f2fs: Convert f2fs_grab_cache_page() to use scoped memory APIs
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 22 Feb 2022 14:45:38 +0000 (09:45 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Sun, 8 May 2022 18:28:19 +0000 (14:28 -0400)
Prevent GFP_FS allocations by using memalloc_nofs_save() instead
of AOP_FLAG_NOFS.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/f2fs/f2fs.h

index 8c570de21ed5aaa0b98212cb44b9f584c68ee052..74929ade4b5e5b86692be1318f0d3441b87e2349 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/kobject.h>
 #include <linux/sched.h>
 #include <linux/cred.h>
+#include <linux/sched/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/bio.h>
 #include <linux/blkdev.h>
@@ -2654,6 +2655,7 @@ static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
                                                pgoff_t index, bool for_write)
 {
        struct page *page;
+       unsigned int flags;
 
        if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
                if (!for_write)
@@ -2673,7 +2675,12 @@ static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
 
        if (!for_write)
                return grab_cache_page(mapping, index);
-       return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
+
+       flags = memalloc_nofs_save();
+       page = grab_cache_page_write_begin(mapping, index, 0);
+       memalloc_nofs_restore(flags);
+
+       return page;
 }
 
 static inline struct page *f2fs_pagecache_get_page(