Commit fa399093 authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman
Browse files

staging: lustre: replace memory_presure funcitons by standard interfaces.



Use memalloc_noreclaim_save() and memalloc_noreclaim_restore(),
and for testing, just directly test the flag in current->flags

Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 525609ed
Loading
Loading
Loading
Loading
+0 −31
Original line number Diff line number Diff line
@@ -48,35 +48,4 @@
#define NUM_CACHEPAGES 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
+6 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
 *
 */

#include <linux/sched/mm.h>
#include "socklnd.h"

struct ksock_tx *
@@ -876,7 +877,7 @@ ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
int
ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
{
	int mpflag = 1;
	unsigned int mpflag = 0;
	int type = lntmsg->msg_type;
	struct lnet_process_id target = lntmsg->msg_target;
	unsigned int payload_niov = lntmsg->msg_niov;
@@ -909,13 +910,13 @@ ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
				     tx_frags.paged.kiov[payload_niov]);

	if (lntmsg->msg_vmflush)
		mpflag = cfs_memory_pressure_get_and_set();
		mpflag = memalloc_noreclaim_save();
	tx = ksocknal_alloc_tx(KSOCK_MSG_LNET, desc_size);
	if (!tx) {
		CERROR("Can't allocate tx desc type %d size %d\n",
		       type, desc_size);
		if (lntmsg->msg_vmflush)
			cfs_memory_pressure_restore(mpflag);
			memalloc_noreclaim_restore(mpflag);
		return -ENOMEM;
	}

@@ -949,8 +950,8 @@ ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)

	/* The first fragment will be set later in pro_pack */
	rc = ksocknal_launch_packet(ni, tx, target);
	if (!mpflag)
		cfs_memory_pressure_restore(mpflag);
	if (mpflag)
		memalloc_noreclaim_restore(mpflag);

	if (!rc)
		return 0;
+3 −2
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ static struct cfs_trace_page *cfs_tage_alloc(gfp_t gfp)
	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;

	/*
@@ -192,7 +192,8 @@ cfs_trace_get_tage_try(struct cfs_trace_cpu_data *tcd, unsigned long len)
		} else {
			tage = cfs_tage_alloc(GFP_ATOMIC);
			if (unlikely(!tage)) {
				if (!memory_pressure_get() || in_interrupt())
				if (!(current->flags & PF_MEMALLOC) ||
				    in_interrupt())
					pr_warn_ratelimited("cannot allocate a tage (%ld)\n",
							    tcd->tcd_cur_pages);
				return NULL;
+1 −1
Original line number Diff line number Diff line
@@ -2014,7 +2014,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
		       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);
	lnet_res_lock(cpt);
+6 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#define DEBUG_SUBSYSTEM S_LDLM

#include <linux/libcfs/libcfs.h>
#include <linux/sched/mm.h>
#include <lustre_dlm.h>
#include <obd_class.h>
#include <linux/list.h>
@@ -387,7 +388,7 @@ static inline void init_blwi(struct ldlm_bl_work_item *blwi,
	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;
@@ -776,12 +777,14 @@ static int ldlm_bl_thread_need_create(struct ldlm_bl_pool *blp,
static int ldlm_bl_thread_blwi(struct ldlm_bl_pool *blp,
			       struct ldlm_bl_work_item *blwi)
{
	unsigned int flags = 0;

	if (!blwi->blwi_ns)
		/* added by ldlm_cleanup() */
		return LDLM_ITER_STOP;

	if (blwi->blwi_mem_pressure)
		memory_pressure_set();
		flags = memalloc_noreclaim_save();

	OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_PAUSE_CANCEL2, 4);

@@ -804,7 +807,7 @@ static int ldlm_bl_thread_blwi(struct ldlm_bl_pool *blp,
					blwi->blwi_lock);
	}
	if (blwi->blwi_mem_pressure)
		memory_pressure_clr();
		memalloc_noreclaim_restore(flags);

	if (blwi->blwi_flags & LCF_ASYNC)
		kfree(blwi);
Loading