Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>
Cc: Josef Bacik <josef@toxicpanda.com>,
	Chris Mason <mason@kernel.org>,
	 linux-ext4@vger.kernel.org,
	OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	 Andreas Dilger <adilger.kernel@dilger.ca>,
	 Baokun Li <libaokun@linux.alibaba.com>,
	 Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	 "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	 Namjae Jeon <namjae.jeon@samsung.com>,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH RFC v2 13/13] fs: don't strand I_METADATA_WRITEBACK inodes outside the LRU
Date: Thu, 05 Nov 2026 13:41:42 +0100	[thread overview]
Message-ID: <20261105-work-inode-metadata_writeback-v2-13-48628c60c336@kernel.org> (raw)
In-Reply-To: <20261105-work-inode-metadata_writeback-v2-0-48628c60c336@kernel.org>

Since commit c474bc56b6d1 ("fs: Provide way for filesystem to wait for
metadata writeback") ext2, ext4 without a journal, fat, udf and minix
set I_METADATA_WRITEBACK on an inode whose metadata was copied into a
buffer that might not have reached the disk yet. Only data integrity
writeback, i.e. fsync() and friends, clears it again. The flusher and
sync(2) leave it alone.

inode_lru_isolate() treats every state bit other than I_REFERENCED as a
reason not to reclaim the inode right now. It takes the inode off the
LRU and relies on iput(), writeback completion or the removal of the
last page from the page cache to put it back once the reason is gone.

But I_METADATA_WRITEBACK doesn't go away on its own. iput() puts the
inode back on the LRU with the bit still set and the next scan takes it
off again. So neither memory pressure nor drop_caches can free these
inodes. Only fsync() and friends or unmounting the filesystem get rid
of them.

On ext4 without a journal ext4_mark_iloc_dirty() sets the bit on every
ext4_mark_inode_dirty(), so even an atime update is enough. An
unprivileged user creating or touching lots of files grows the inode
cache without bound until the OOM killer comes along.

The inode can't just be thrown away though. An fsync() after the inode
was read back in wouldn't know that its metadata still has to be
written out. But that's no different from the metadata buffers these
filesystems track in their mapping_metadata_bhs. Their ->evict_inode()
calls mmb_sync() and that is what allowed commit 972b9dd4e418 ("fs:
Ignore inode metadata buffers in inode_lru_isolate()") to take those
buffers out of inode_lru_isolate(). With the previous patches
->evict_inode() writes out what I_METADATA_WRITEBACK tracks the same
way, without reading anything from disk.

So let the shrinker reclaim inodes with I_METADATA_WRITEBACK like any
other clean inode.

Handing these inodes to a work item that syncs them and puts them back
on the LRU would work too. But that's a second inode reclaim offload
mechanism next to the deferred inode reclaim that is being worked on,
and it needs a reference on the inode which leaks into remount, freeze
and umount.

For stable this needs the previous patches as well. Without the
->evict_inode() changes an fsync() after the inode was read back in
misses the inode block. Without the lookup changes ->evict_inode() reads
inode blocks from disk with __GFP_NOFAIL allocations from reclaim. v7.3
also still has bfs which sets I_METADATA_WRITEBACK too, so the backport
needs the same two changes for bfs.

Fixes: c474bc56b6d1 ("fs: Provide way for filesystem to wait for metadata writeback")
Cc: stable@vger.kernel.org # v7.3; see patch description
Reported-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/inode.c b/fs/inode.c
index 1cb6293b237a..16ebd686d681 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -947,9 +947,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
 	 * they're already on the LRU, and this can make them
 	 * unreclaimable for a while. Remove them lazily here; iput,
 	 * sync, or the last page cache deletion will requeue them.
+	 * Nothing requeues them for I_METADATA_WRITEBACK, ->evict_inode()
+	 * writes that out instead.
 	 */
 	if (icount_read(inode) ||
-	    (inode_state_read(inode) & ~I_REFERENCED) ||
+	    (inode_state_read(inode) &
+	     ~(I_REFERENCED | I_METADATA_WRITEBACK)) ||
 	    !mapping_shrinkable(&inode->i_data)) {
 		list_lru_isolate(lru, &inode->i_lru);
 		spin_unlock(&inode->i_lock);

-- 
2.53.0


  parent reply	other threads:[~2026-11-05 12:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 12:41 [PATCH RFC v2 00/13] fs: reclaim inodes with I_METADATA_WRITEBACK Christian Brauner
2026-11-05 12:41 ` [PATCH RFC v2 01/13] ext2: add ext2_inode_block() helper Christian Brauner
2026-11-05 12:52   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 02/13] ext2: don't read the inode block in ext2_sync_inode_metadata() Christian Brauner
2026-11-05 12:47   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 03/13] ext2: sync inode metadata in ext2_evict_inode() Christian Brauner
2026-11-05 12:49   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 04/13] ext4: use sb_find_get_block_nonatomic() in ext4_get_inode_loc_noio() Christian Brauner
2026-11-05 12:46   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 05/13] ext4: don't read the inode block in ext4_sync_inode_metadata() Christian Brauner
2026-11-05 12:48   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 06/13] ext4: sync inode metadata in ext4_evict_inode() Christian Brauner
2026-11-05 12:54   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 07/13] minix: add minix_inode_block() helper Christian Brauner
2026-11-05 12:45   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 08/13] minix: don't read the inode block in minix_sync_inode_metadata() Christian Brauner
2026-11-05 12:46   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 09/13] minix: sync inode metadata in minix_evict_inode() Christian Brauner
2026-11-05 12:46   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 10/13] udf: don't allocate the inode block in udf_sync_inode_metadata() Christian Brauner
2026-11-05 12:49   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 11/13] udf: sync inode metadata in udf_evict_inode() Christian Brauner
2026-11-05 12:54   ` sashiko-bot
2026-11-05 12:41 ` [PATCH RFC v2 12/13] fat: sync inode metadata in fat_evict_inode() Christian Brauner
2026-11-05 13:06   ` sashiko-bot
2026-11-05 12:41 ` Christian Brauner [this message]
2026-11-05 12:55   ` [PATCH RFC v2 13/13] fs: don't strand I_METADATA_WRITEBACK inodes outside the LRU sashiko-bot

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=20261105-work-inode-metadata_writeback-v2-13-48628c60c336@kernel.org \
    --to=brauner@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=namjae.jeon@samsung.com \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=stable@vger.kernel.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