From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org, willy@infradead.org, david@fromorbit.com,
Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: [PATCH 2/3] fs: use memalloc_nofs API while shrinking superblock
Date: Wed, 21 Mar 2018 17:44:28 -0500 [thread overview]
Message-ID: <20180321224429.15860-3-rgoldwyn@suse.de> (raw)
In-Reply-To: <20180321224429.15860-1-rgoldwyn@suse.de>
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
The superblock shrinkers are responsible for pruning dcache and icache.
which evicts the inode by calling into local filesystem code. Protect
allocations under memalloc_nofs_save/restore().
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
fs/super.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/super.c b/fs/super.c
index 672538ca9831..26fc2679118d 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -35,6 +35,7 @@
#include <linux/fsnotify.h>
#include <linux/lockdep.h>
#include <linux/user_namespace.h>
+#include <linux/sched/mm.h>
#include "internal.h"
@@ -63,6 +64,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
long freed = 0;
long dentries;
long inodes;
+ unsigned flags;
sb = container_of(shrink, struct super_block, s_shrink);
@@ -70,9 +72,11 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
* Deadlock avoidance. We may hold various FS locks, and we don't want
* to recurse into the FS that called us in clear_inode() and friends..
*/
- if (!(sc->gfp_mask & __GFP_FS))
+ if (!(sc->gfp_mask & __GFP_FS) || (current->flags & PF_MEMALLOC_NOFS))
return SHRINK_STOP;
+ flags = memalloc_nofs_save();
+
if (!trylock_super(sb))
return SHRINK_STOP;
@@ -107,6 +111,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
freed += sb->s_op->free_cached_objects(sb, sc);
}
+ memalloc_nofs_restore(flags);
up_read(&sb->s_umount);
return freed;
}
--
2.16.2
next prev parent reply other threads:[~2018-03-21 22:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-21 22:44 [PATCH 0/3] fs: Use memalloc_nofs_save/restore scope API Goldwyn Rodrigues
2018-03-21 22:44 ` [PATCH 1/3] fs: Perform writebacks under memalloc_nofs Goldwyn Rodrigues
2018-03-22 7:08 ` Michal Hocko
2018-03-27 12:52 ` Goldwyn Rodrigues
2018-03-27 14:21 ` Matthew Wilcox
2018-03-27 15:13 ` Goldwyn Rodrigues
2018-03-27 16:45 ` Matthew Wilcox
2018-03-28 7:01 ` Michal Hocko
2018-03-28 23:57 ` Dave Chinner
2018-03-29 7:01 ` Michal Hocko
2018-03-31 21:21 ` Dave Chinner
2018-03-21 22:44 ` Goldwyn Rodrigues [this message]
2018-03-22 7:09 ` [PATCH 2/3] fs: use memalloc_nofs API while shrinking superblock Michal Hocko
2018-03-21 22:44 ` [PATCH 3/3] fs: Use memalloc_nofs_save in generic_perform_write Goldwyn Rodrigues
2018-03-22 7:10 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180321224429.15860-3-rgoldwyn@suse.de \
--to=rgoldwyn@suse.de \
--cc=david@fromorbit.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rgoldwyn@suse.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox