]) # LIBCFS_REFCOUNT_T
#
+# Kernel version 4.12 commit 499118e966f1d2150bd66647c8932343c4e9a0b8
+# introduce memalloc_noreclaim_{save,restore}
+#
+AC_DEFUN([LIBCFS_MEMALLOC_NORECLAIM], [
+LB_CHECK_COMPILE([if memalloc_noreclaim_{save,restore} exist],
+memalloc_noreclaim, [
+ #include <linux/sched/mm.h>
+],[
+ int flag = memalloc_noreclaim_save();
+ memalloc_noreclaim_restore(flag);
+],[
+ AC_DEFINE(HAVE_MEMALLOC_RECLAIM, 1,
+ [memalloc_noreclaim_{save,restore}() is supported])
+])
+]) # LIBCFS_MEMALLOC_NORECLAIM
+
+#
# LIBCFS_SCHED_HEADERS
#
# 4.11 has broken up sched.h into more headers.
# 4.12
LIBCFS_HAVE_PROCESSOR_HEADER
LIBCFS_HAVE_WAIT_BIT_HEADER
+LIBCFS_MEMALLOC_NORECLAIM
LIBCFS_WAIT_QUEUE_TASK_LIST_RENAME
LIBCFS_CPUS_READ_LOCK
LIBCFS_UUID_T
# define NUM_CACHEPAGES cfs_totalram_pages()
#endif
-static inline unsigned int memory_pressure_get(void)
-{
- return current->flags & PF_MEMALLOC;
-}
-
-static inline void memory_pressure_set(void)
-{
- current->flags |= PF_MEMALLOC;
-}
-
-static inline void memory_pressure_clr(void)
-{
- current->flags &= ~PF_MEMALLOC;
-}
-
-static inline int cfs_memory_pressure_get_and_set(void)
-{
- int old = memory_pressure_get();
-
- if (!old)
- memory_pressure_set();
- return old;
-}
-
-static inline void cfs_memory_pressure_restore(int old)
-{
- if (old)
- memory_pressure_set();
- else
- memory_pressure_clr();
-}
#endif
#ifdef HAVE_MM_INLINE
# include <linux/mm_inline.h>
#endif
+#include <linux/sched.h>
+#ifdef HAVE_SCHED_HEADERS
+#include <linux/sched/mm.h>
+#endif
+
+#ifndef HAVE_MEMALLOC_RECLAIM
+static inline unsigned int memalloc_noreclaim_save(void)
+{
+ unsigned int flags = current->flags & PF_MEMALLOC;
+
+ current->flags |= PF_MEMALLOC;
+ return flags;
+}
+
+static inline void memalloc_noreclaim_restore(unsigned int flags)
+{
+ current->flags = (current->flags & ~PF_MEMALLOC) | flags;
+}
+#endif /* !HAVE_MEMALLOC_RECLAIM */
/*
* Shrinker
struct cfs_trace_page *tage;
/* My caller is trying to free memory */
- if (!in_interrupt() && memory_pressure_get())
+ if (!in_interrupt() && (current->flags & PF_MEMALLOC))
return NULL;
/*
} else {
tage = cfs_tage_alloc(GFP_ATOMIC);
if (unlikely(tage == NULL)) {
- if ((!memory_pressure_get() ||
+ if ((!(current->flags & PF_MEMALLOC) ||
in_interrupt()) && printk_ratelimit())
pr_warn("Lustre: cannot allocate a tage (%ld)\n",
tcd->tcd_cur_pages);
#include <asm/page.h>
#include <linux/nmi.h>
#include <linux/pagemap.h>
+
+#include <libcfs/linux/linux-mem.h>
+
#include "gnilnd.h"
/* this is useful when needed to debug wire corruption. */
kgn_net_t *net = ni->ni_data;
kgn_tx_t *tx;
int rc = 0;
- int mpflag = 0;
+ /* '1' for consistency with code that checks !mpflag to restore */
+ unsigned int mpflag = 1;
int reverse_rdma_flag = *kgnilnd_tunables.kgn_reverse_rdma;
/* NB 'private' is different depending on what we're sending.... */
"lntmsg %p niov %d\n", lntmsg, niov);
if (msg_vmflush)
- mpflag = cfs_memory_pressure_get_and_set();
+ mpflag = memalloc_noreclaim_save();
switch (type) {
default:
out:
/* use stored value as we could have already finalized lntmsg here from a failed launch */
if (msg_vmflush)
- cfs_memory_pressure_restore(mpflag);
+ memalloc_noreclaim_restore(mpflag);
return rc;
}
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <libcfs/linux/linux-mem.h>
#include "socklnd.h"
struct ksock_tx *
int
ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
{
- int mpflag = 1;
+ /* '1' for consistency with code that checks !mpflag to restore */
+ unsigned int mpflag = 1;
int type = lntmsg->msg_type;
struct lnet_process_id target = lntmsg->msg_target;
unsigned int payload_niov = lntmsg->msg_niov;
tx_frags.paged.kiov[payload_niov]);
if (lntmsg->msg_vmflush)
- mpflag = cfs_memory_pressure_get_and_set();
- tx = ksocknal_alloc_tx(KSOCK_MSG_LNET, desc_size);
- if (tx == NULL) {
- CERROR("Can't allocate tx desc type %d size %d\n",
- type, desc_size);
- if (lntmsg->msg_vmflush)
- cfs_memory_pressure_restore(mpflag);
- return (-ENOMEM);
- }
+ mpflag = memalloc_noreclaim_save();
+
+ tx = ksocknal_alloc_tx(KSOCK_MSG_LNET, desc_size);
+ if (tx == NULL) {
+ CERROR("Can't allocate tx desc type %d size %d\n",
+ type, desc_size);
+ if (lntmsg->msg_vmflush)
+ memalloc_noreclaim_restore(mpflag);
+ return -ENOMEM;
+ }
tx->tx_conn = NULL; /* set when assigned a conn */
tx->tx_lnetmsg = lntmsg;
tx->tx_msg.ksm_zc_cookies[0] = 0;
tx->tx_msg.ksm_zc_cookies[1] = 0;
- /* The first fragment will be set later in pro_pack */
- rc = ksocknal_launch_packet(ni, tx, target);
- if (!mpflag)
- cfs_memory_pressure_restore(mpflag);
+ /* The first fragment will be set later in pro_pack */
+ rc = ksocknal_launch_packet(ni, tx, target);
+ /*
+ * We can't test lntsmg->msg_vmflush again as lntmsg may
+ * have been freed.
+ */
+ if (!mpflag)
+ memalloc_noreclaim_restore(mpflag);
if (rc == 0)
return (0);
libcfs_id2str(target));
return -ENOMEM;
}
- msg->msg_vmflush = !!memory_pressure_get();
+ msg->msg_vmflush = !!(current->flags & PF_MEMALLOC);
cpt = lnet_cpt_of_cookie(mdh.cookie);
#include <linux/kthread.h>
#include <linux/list.h>
#include <libcfs/libcfs.h>
+#include <libcfs/linux/linux-mem.h>
#include <lustre_errno.h>
#include <lustre_dlm.h>
#include <obd_class.h>
init_completion(&blwi->blwi_comp);
INIT_LIST_HEAD(&blwi->blwi_head);
- if (memory_pressure_get())
+ if (current->flags & PF_MEMALLOC)
blwi->blwi_mem_pressure = 1;
blwi->blwi_ns = ns;
static int ldlm_bl_thread_blwi(struct ldlm_bl_pool *blp,
struct ldlm_bl_work_item *blwi)
{
+ /* '1' for consistency with code that checks !mpflag to restore */
+ unsigned int mpflags = 1;
+
ENTRY;
if (blwi->blwi_ns == NULL)
RETURN(LDLM_ITER_STOP);
if (blwi->blwi_mem_pressure)
- memory_pressure_set();
+ mpflags = memalloc_noreclaim_save();
OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_PAUSE_CANCEL2, 4);
blwi->blwi_lock);
}
if (blwi->blwi_mem_pressure)
- memory_pressure_clr();
+ memalloc_noreclaim_restore(mpflags);
if (blwi->blwi_flags & LCF_ASYNC)
OBD_FREE(blwi, sizeof(*blwi));
oap->oap_async_flags |= ASYNC_READY|ASYNC_URGENT;
spin_unlock(&oap->oap_lock);
- if (memory_pressure_get())
+ if (current->flags & PF_MEMALLOC)
ext->oe_memalloc = 1;
ext->oe_urgent = 1;
struct cl_req_attr *crattr = NULL;
loff_t starting_offset = OBD_OBJECT_EOF;
loff_t ending_offset = 0;
- int mpflag = 0;
+ /* '1' for consistency with code that checks !mpflag to restore */
+ int mpflag = 1;
int mem_tight = 0;
int page_count = 0;
bool soft_sync = false;
soft_sync = osc_over_unstable_soft_limit(cli);
if (mem_tight)
- mpflag = cfs_memory_pressure_get_and_set();
+ mpflag = memalloc_noreclaim_save();
OBD_ALLOC_PTR_ARRAY(pga, page_count);
if (pga == NULL)
EXIT;
out:
- if (mem_tight != 0)
- cfs_memory_pressure_restore(mpflag);
+ if (mem_tight)
+ memalloc_noreclaim_restore(mpflag);
if (rc != 0) {
LASSERT(req == NULL);
*/
#define DEBUG_SUBSYSTEM S_RPC
+#include <libcfs/linux/linux-mem.h>
#include <obd_support.h>
#include <lustre_net.h>
#include <lustre_lib.h>
request->rq_resend_cb(request, &request->rq_async_args);
}
if (request->rq_memalloc)
- mpflag = cfs_memory_pressure_get_and_set();
+ mpflag = memalloc_noreclaim_save();
rc = sptlrpc_cli_wrap_request(request);
if (rc)
}
if (request->rq_memalloc)
- cfs_memory_pressure_restore(mpflag);
+ memalloc_noreclaim_restore(mpflag);
return rc;
}
#include <linux/delay.h>
#include <linux/uidgid.h>
+#include <libcfs/linux/linux-mem.h>
#include <obd.h>
#include <obd_class.h>
#include <obd_cksum.h>
struct tgt_thread_big_cache *tbc = req->rq_svc_thread->t_data;
bool wait_sync = false;
const char *obd_name = exp->exp_obd->obd_name;
+ /* '1' for consistency with code that checks !mpflag to restore */
+ unsigned int mpflags = 1;
ENTRY;
if ((remote_nb[0].rnb_flags & OBD_BRW_MEMALLOC) &&
ptlrpc_connection_is_local(exp->exp_connection))
- memory_pressure_set();
+ mpflags = memalloc_noreclaim_save();
req_capsule_set_size(&req->rq_pill, &RMF_RCS, RCL_SERVER,
niocount * sizeof(*rcs));
obd_uuid2str(&exp->exp_client_uuid),
obd_export_nid2str(exp), rc);
}
- memory_pressure_clr();
+
+ if (mpflags)
+ memalloc_noreclaim_restore(mpflags);
+
RETURN(rc);
}
EXPORT_SYMBOL(tgt_brw_write);