writeback: don't requeue inode already on b_dirty
Subsystems (2)
PATCH RESEND 1/1 writeback: don't requeue inode already on b_dirty
Since commit 846a3351ddfe ("writeback: Avoid skipping inode writeback"), writeback_single_inode() calls redirty_tail_locked() for any inode left dirty. When that inode is already on b_dirty and older than the newest inode there, redirty_tail_locked() moves it to the head and stamps dirtied_when with jiffies.
Append to an f2fs file so the i_size update puts it on DIRTY_META, and dirty a newer inode before each checkpoint. Every 17s the checkpoint syncs that file and redirty_tail_locked() stamps a new dirtied_when. 17s is shorter than the default 30s dirty_expire_interval, so kupdate never expires it. Dirty pages pile up until writeback or fsync().
An inode that was I_DIRTY on entry is already on b_dirty, so only redirty it if it was not. The b_dirty_time case fixed by commit 846a3351ddfe ("writeback: Avoid skipping inode writeback") enters without I_DIRTY and is still handled.
--- fs/fs-writeback.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/fs-writeback.c +3 -1
@@ -1898,6 +1898,7 @@ static int writeback_single_inode(struct inode *inode, struct writeback_control *wbc) {struct bdi_writeback *wb; +bool was_dirty;int ret =0 ;spin_lock (&inode->i_lock);
@@ -1932,6 +1933,7 @@ static int writeback_single_inode(struct inode *inode, !(inode_state_read(inode) & I_METADATA_WRITEBACK)) goto out; } + was_dirty =inode_state_read (inode) &I_DIRTY ;inode_state_set (inode,I_SYNC );wbc_attach_and_unlock_inode (wbc, inode);
@@ -1954,7 +1956,7 @@ static int writeback_single_inode(struct inode *inode,if (!(inode_state_read (inode) &I_DIRTY_ALL ))inode_cgwb_move_to_attached (inode, wb);else if (!(inode_state_read (inode) &I_SYNC_QUEUED )) { -if ((inode_state_read (inode) &I_DIRTY )) +if ((inode_state_read (inode) &I_DIRTY ) && !was_dirty)redirty_tail_locked (inode, wb);else if (inode_state_read (inode) &I_DIRTY_TIME ) { inode->dirtied_when = jiffies;
Signature · 1 line
2.53.0
Jan Kara
reviewerQuoted 12 lines · Hongyu Jin
Since commit
846a3351ddfe("writeback: Avoid skipping inode writeback"),writeback_single_inode()callsredirty_tail_locked()for any inode left dirty. When that inode is already onb_dirtyand older than the newest inode there,redirty_tail_locked()moves it to the head and stampsdirtied_whenwith jiffies.Append to an f2fs file so the
i_sizeupdate puts it onDIRTY_META, and dirty a newer inode before each checkpoint. Every 17s the checkpoint syncs that file andredirty_tail_locked()stamps a newdirtied_when. 17s is shorter than the default 30sdirty_expire_interval, so kupdate never expires it. Dirty pages pile up until writeback orfsync().
Quoted 8 lines
An inode that was
I_DIRTYon entry is already onb_dirty, so only redirty it if it was not. Theb_dirty_timecase fixed by commit846a3351ddfe("writeback: Avoid skipping inode writeback") enters withoutI_DIRTYand is still handled.Fixes 846a3351ddfe ("writeback: Avoid skipping inode writeback")Signed-off-by Hongyu Jin <[email protected]>
I was mulling over this for quite some time (which is why I didn't reply to your patch earlier - plus the fact that currently there a *lot* of things going on). I agree the current behavior is problematic - in particular that if sync_inode_metadata() is called frequently enough, we never get to kupdate style data writeback.
But I wasn't quite sure your fix is correct. In the end I've convinced myself it is fine but we can actually go even further and remove the redirty_tail() logic altogether. So I'm now testing the attached patch. If my testing passes, I'll send it for inclusion.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
From 4261c07e3cb809f9bfac3b1da529b21bcd9da42d Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 26 Oct 2026 16:16:15 +0100
Subject: [PATCH] writeback: Avoid postponing periodic data writeback
indefinitely
Hongyu Jin has reported that f2fs periodically calls sync_inode_metadata() for some inodes. The logic in writeback_single_inode() thus periodically calls to redirty_tail() and the inode's dirtied_when timestamp never gets old enough for the inode to be eligible for periodic data writeback. Thus dirty data from it is only ever written on explicit request (fsync(2), sync(2), unmount) or on dirty limit pressure.
The redirty_tail() logic in writeback_single_inode() actually should not be necessary. Since this function is used only for once-off writeback, there's no need for any livelock protection among inodes and writeback_single_inode() is only responsible for demoting inode to "less dirty" list based on dirty bits cleared as a result of writeback. So remove the redirty_tail() logic and add a comment explaining the rules.
--- fs/fs-writeback.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
fs/fs-writeback.c +22 -13
@@ -1946,22 +1946,31 @@ static int writeback_single_inode(struct inode *inode,* as it can be finally deleted at this moment. */ if (!(inode_state_read (inode) &I_FREEING )) { +enum inode_state_flags_enum istate =inode_state_read (inode); +/* -* If the inode is now fully clean, then it can be safely -* removed from its writeback list (if any). Otherwise the -* flusher threads are responsible for the writeback lists. +* __mark_inode_dirty() is responsible for promoting inode to +* the proper list (b_attached -> b_dirty_time -> b_dirty). +* Here we are responsible for demoting inode after some dirty +* bits were cleared. +* +* If the inode is now fully clean, then it can be safely moved +* to b_attached list. If the inode is dirty, we don't want to +* touch it - it should be already put to the dirty list by +* __mark_inode_dirty() and we'd just unnecessarily clobber the +* dirtied_when stamp (which is particularly problematic when +* we were called from sync_inode_metadata()). We also cannot +* touch the dirty list association when I_SYNC_QUEUED is set +* and flush worker is responsible for it. Otherwise move the +* inode to b_dirty_time list as that's the only remaining +* possibility. */ -if (!(inode_state_read (inode) &I_DIRTY_ALL )) +if (!(istate &I_DIRTY_ALL ))inode_cgwb_move_to_attached (inode, wb); -else if (!(inode_state_read (inode) &I_SYNC_QUEUED )) { -if ((inode_state_read (inode) &I_DIRTY )) -redirty_tail_locked (inode, wb); -else if (inode_state_read (inode) &I_DIRTY_TIME ) { - inode->dirtied_when = jiffies; -inode_io_list_move_locked (inode, - wb, - &wb->b_dirty_time); - } +else if (!(istate &I_SYNC_QUEUED ) && !(istate &I_DIRTY )) { +WARN_ON_ONCE (!(istate &I_DIRTY_TIME )); + inode->dirtied_when = jiffies; +inode_io_list_move_locked (inode, wb, &wb->b_dirty_time); } }
Signature · 1 line
2.51.0