diff options
author | Vlastimil Babka <vbabka@suse.cz> | 2017-05-08 18:59:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-08 20:15:15 -0400 |
commit | dcbe82149cc9d03dcdf7cd1a75d5541de7c14be1 (patch) | |
tree | 542c9cb63edc70cfe402c9cdce4fc0a8f1c19bd2 | |
parent | f108304872b8d987ceab195174ba41153fb70bf6 (diff) |
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.
Link: http://lkml.kernel.org/r/20170405074700.29871-5-vbabka@suse.cz
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Chris Leech <cleech@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Josef Bacik <jbacik@fb.com>
Cc: Lee Duncan <lduncan@suse.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/mtd/nand/nandsim.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index c84742671a5f..092c9bd225be 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/list.h> | 40 | #include <linux/list.h> |
41 | #include <linux/random.h> | 41 | #include <linux/random.h> |
42 | #include <linux/sched.h> | 42 | #include <linux/sched.h> |
43 | #include <linux/sched/mm.h> | ||
43 | #include <linux/fs.h> | 44 | #include <linux/fs.h> |
44 | #include <linux/pagemap.h> | 45 | #include <linux/pagemap.h> |
45 | #include <linux/seq_file.h> | 46 | #include <linux/seq_file.h> |
@@ -1368,31 +1369,18 @@ static int get_pages(struct nandsim *ns, struct file *file, size_t count, loff_t | |||
1368 | return 0; | 1369 | return 0; |
1369 | } | 1370 | } |
1370 | 1371 | ||
1371 | static int set_memalloc(void) | ||
1372 | { | ||
1373 | if (current->flags & PF_MEMALLOC) | ||
1374 | return 0; | ||
1375 | current->flags |= PF_MEMALLOC; | ||
1376 | return 1; | ||
1377 | } | ||
1378 | |||
1379 | static void clear_memalloc(int memalloc) | ||
1380 | { | ||
1381 | if (memalloc) | ||
1382 | current->flags &= ~PF_MEMALLOC; | ||
1383 | } | ||
1384 | |||
1385 | static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) | 1372 | static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) |
1386 | { | 1373 | { |
1387 | ssize_t tx; | 1374 | ssize_t tx; |
1388 | int err, memalloc; | 1375 | int err; |
1376 | unsigned int noreclaim_flag; | ||
1389 | 1377 | ||
1390 | err = get_pages(ns, file, count, pos); | 1378 | err = get_pages(ns, file, count, pos); |
1391 | if (err) | 1379 | if (err) |
1392 | return err; | 1380 | return err; |
1393 | memalloc = set_memalloc(); | 1381 | noreclaim_flag = memalloc_noreclaim_save(); |
1394 | tx = kernel_read(file, pos, buf, count); | 1382 | tx = kernel_read(file, pos, buf, count); |
1395 | clear_memalloc(memalloc); | 1383 | memalloc_noreclaim_restore(noreclaim_flag); |
1396 | put_pages(ns); | 1384 | put_pages(ns); |
1397 | return tx; | 1385 | return tx; |
1398 | } | 1386 | } |
@@ -1400,14 +1388,15 @@ static ssize_t read_file(struct nandsim *ns, struct file *file, void *buf, size_ | |||
1400 | static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) | 1388 | static ssize_t write_file(struct nandsim *ns, struct file *file, void *buf, size_t count, loff_t pos) |
1401 | { | 1389 | { |
1402 | ssize_t tx; | 1390 | ssize_t tx; |
1403 | int err, memalloc; | 1391 | int err; |
1392 | unsigned int noreclaim_flag; | ||
1404 | 1393 | ||
1405 | err = get_pages(ns, file, count, pos); | 1394 | err = get_pages(ns, file, count, pos); |
1406 | if (err) | 1395 | if (err) |
1407 | return err; | 1396 | return err; |
1408 | memalloc = set_memalloc(); | 1397 | noreclaim_flag = memalloc_noreclaim_save(); |
1409 | tx = kernel_write(file, buf, count, pos); | 1398 | tx = kernel_write(file, buf, count, pos); |
1410 | clear_memalloc(memalloc); | 1399 | memalloc_noreclaim_restore(noreclaim_flag); |
1411 | put_pages(ns); | 1400 | put_pages(ns); |
1412 | return tx; | 1401 | return tx; |
1413 | } | 1402 | } |