Sometimes it can happen that reclaim of some slab object drops the last reference of an inode that is already unlinked. The frequently reported case of this is a reclaim of overlayfs inode dropping the last reference of an inode on upper filesystem. Because the inode is unlinked, evict() will delete it which generally requires writing to the filesystem and memory allocations - not good from kswapd or even direct reclaim. Defer inode reclaim of unlinked inodes to a workqueue when the last inode reference is dropped from a reclaim path. Signed-off-by: Jan Kara --- fs/inode.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 5713e18229e0..e6af38faa964 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2240,6 +2240,23 @@ static void iput_final(struct inode *inode) inode_lru_list_del(inode); spin_unlock(&inode->i_lock); + /* + * Are we going to delete this inode while in reclaim path? Likely + * reclaim of some object (e.g. overlayfs inode) ended up dropping the + * last reference to an already deleted inode. Offload the eviction as + * it's likely to require memory allocations and block on IO. Since + * this eviction was triggered by a reclaim of unrelated object, the + * inode is already outliving the operation that originally deleted it + * (unlink, file close...). A slightly longer delay thus should not be + * observable by userspace. + */ + if (current->flags & PF_MEMALLOC && !inode->i_nlink) { + LIST_HEAD(defer); + + list_add(&inode->i_lru, &defer); + queue_deferred_reclaim(sb, 1, &defer); + return; + } evict(inode); } -- 2.53.0