Skip to contentSkip to conversation

mtd: nand: nandsim: convert to memalloc_noreclaim_*()

PATCH New [email protected] 1 participant 1 message May 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 106/114 mtd: nand: nandsim: convert to memalloc_noreclaim_*()

From: Vlastimil Babka <[email protected]>
Subject: mtd: nand: nandsim: convert to memalloc_noreclaim_*()

Nandsim has own functions set_memalloc() and clear_memalloc() for robust setting and clearing of PF_MEMALLOC. Replace them by the new generic helpers. No functional change.

Cc Boris Brezillon <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Chris Leech <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Josef Bacik <[email protected]>
Cc Lee Duncan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Adrian Hunter <[email protected]>

---

 drivers/mtd/nand/nandsim.c |   29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)
drivers/mtd/nand/nandsim.c renamed from drivers/mtd/nand/nandsim.c~mtd-nand-nandsim-convert-to-memalloc_noreclaim_ +9 -20
diff -puN drivers/mtd/nand/nandsim.c~mtd-nand-nandsim-convert-to-memalloc_noreclaim_ drivers/mtd/nand/nandsim.c
@@ -40,6 +40,7 @@
 #include <linux/list.h>
 #include <linux/random.h>
 #include <linux/sched.h>
+#include <linux/sched/mm.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
 #include <linux/seq_file.h>
@@ -1368,31 +1369,18 @@ static int get_pages(struct nandsim *ns,
 	return 0;
 }
 
-static int set_memalloc(void)
-{
-	if (current->flags & PF_MEMALLOC)
-		return 0;
-	current->flags |= PF_MEMALLOC;
-	return 1;
-}
-
-static void clear_memalloc(int memalloc)
-{
-	if (memalloc)
-		current->flags &= ~PF_MEMALLOC;
-}
-
 static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
 {
 	ssize_t tx;
-	int err, memalloc;
+	int err;
+	unsigned int noreclaim_flag;
 
 	err = get_pages(ns, file, count, pos);
 	if (err)
 		return err;
-	memalloc = set_memalloc();
+	noreclaim_flag = memalloc_noreclaim_save();
 	tx = kernel_read(file, pos, buf, count);
-	clear_memalloc(memalloc);
+	memalloc_noreclaim_restore(noreclaim_flag);
 	put_pages(ns);
 	return tx;
 }
@@ -1400,14 +1388,15 @@ static ssize_t read_file(struct nandsim
 static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos)
 {
 	ssize_t tx;
-	int err, memalloc;
+	int err;
+	unsigned int noreclaim_flag;
 
 	err = get_pages(ns, file, count, pos);
 	if (err)
 		return err;
-	memalloc = set_memalloc();
+	noreclaim_flag = memalloc_noreclaim_save();
 	tx = kernel_write(file, buf, count, pos);
-	clear_memalloc(memalloc);
+	memalloc_noreclaim_restore(noreclaim_flag);
 	put_pages(ns);
 	return tx;
 }

_