From: Jan Kara <jack@suse.cz>
To: Christian Brauner <brauner@kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>,
Christoph Hellwig <hch@infradead.org>, <linux-mm@kvack.org>,
Mikhail Rudenko <xyzzy@yandex-team.ru>,
Andreas Gruenbacher <agruenba@redhat.com>,
Jan Kara <jack@suse.cz>
Subject: [PATCH v2 4/8] fs: Defer reclaim of unlinked inodes
Date: Tue, 24 Nov 2026 12:58:48 +0100 [thread overview]
Message-ID: <20261124115850.3512-12-jack@suse.cz> (raw)
In-Reply-To: <20261124113450.3451-1-jack@suse.cz>
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 <jack@suse.cz>
---
fs/inode.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/fs/inode.c b/fs/inode.c
index e08c6f0b0336..4ffafb101718 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2239,6 +2239,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
next prev parent reply other threads:[~2026-11-24 11:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 11:58 [PATCH 0/8 v4] fs: Deferred inode reclaim Jan Kara
2026-11-24 11:58 ` [PATCH v2 1/8] writeback: Fix missed lazytime flush Jan Kara
2026-11-24 11:58 ` [PATCH v2 2/8] fs: Avoid inode dirtying on last iput Jan Kara
2026-11-24 11:58 ` [PATCH v2 3/8] fs: Basic infrastructure for offloading inode reclaim Jan Kara
2026-11-24 11:58 ` Jan Kara [this message]
2026-11-24 11:58 ` [PATCH v2 5/8] fs: Defer reclaim of inodes requiring metadata writeback Jan Kara
2026-11-24 11:58 ` [PATCH v2 6/8] fs: Add throttling to deferred inode reclaim Jan Kara
2026-11-24 11:58 ` [PATCH v2 7/8] fs: Protect deferred inode reclaim from freezing Jan Kara
2026-11-24 11:58 ` [PATCH v2 8/8] ext4: Defer inode reclaim if it has preallocations Jan Kara
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=20261124115850.3512-12-jack@suse.cz \
--to=jack@suse.cz \
--cc=agruenba@redhat.com \
--cc=brauner@kernel.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=xyzzy@yandex-team.ru \
/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