Skip to contentSkip to conversation

writeback: Avoid skipping inode writeback

PATCH Superseded Jing Xia 4 participants 5 messages May 5, 2022 – May 9, 2022 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jing Xia

author
#0 lore raw

PATCH 1/1 writeback: Avoid skipping inode writeback

We have run into an issue that a task gets stuck in balance_dirty_pages_ratelimited() when perform I/O stress testing. The reason we observed is that an I_DIRTY_PAGES inode with lots of dirty pages is in b_dirty_time list and standard background writeback cannot writeback the inode.
After studing the relevant code, the following scenario may lead to the issue:

task1 task2
----- -----
fuse_flush
write_inode_now //in b_dirty_time
writeback_single_inode
__writeback_single_inode

                                 fuse_write_end
                                  filemap_dirty_folio
                                   __xa_set_mark:PAGECACHE_TAG_DIRTY
    lock inode->i_lock
    if mapping tagged PAGECACHE_TAG_DIRTY
    inode->i_state |= I_DIRTY_PAGES
    unlock inode->i_lock
                                   __mark_inode_dirty:I_DIRTY_PAGES
                                      lock inode->i_lock
                                      -was dirty,inode stays in
                                      -b_dirty_time
                                      unlock inode->i_lock

if(!(inode->i_state & I_DIRTY_All))
-not true,so nothing done

This patch moves the dirty inode to b_dirty list when the inode currently is not queued in b_io or b_more_io list at the end of writeback_single_inode.

---
 fs/fs-writeback.c | 3 +++
 1 file changed, 3 insertions(+)
fs/fs-writeback.c +3 -0
index 591fe9cf1659..d7763feaf14a 100644
@@ -1712,6 +1712,9 @@ static int writeback_single_inode(struct inode *inode,
 	 */
 	if (!(inode->i_state & I_DIRTY_ALL))
 		inode_cgwb_move_to_attached(inode, wb);
+	else if (!(inode->i_state & I_SYNC_QUEUED) && (inode->i_state & I_DIRTY))
+		redirty_tail_locked(inode, wb);
+
 	spin_unlock(&wb->list_lock);
 	inode_sync_complete(inode);
 out:
Signature · 1 line
2.17.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Jing Xia

We have run into an issue that a task gets stuck in balance_dirty_pages_ratelimited() when perform I/O stress testing. The reason we observed is that an I_DIRTY_PAGES inode with lots of dirty pages is in b_dirty_time list and standard background writeback cannot writeback the inode.
After studing the relevant code, the following scenario may lead to the issue:

task1 task2
----- -----
fuse_flush
write_inode_now //in b_dirty_time
writeback_single_inode
__writeback_single_inode

                                 fuse_write_end
                                  filemap_dirty_folio
                                   __xa_set_mark:PAGECACHE_TAG_DIRTY
    lock inode->i_lock
    if mapping tagged PAGECACHE_TAG_DIRTY
    inode->i_state |= I_DIRTY_PAGES
    unlock inode->i_lock
                                   __mark_inode_dirty:I_DIRTY_PAGES
                                      lock inode->i_lock
                                      -was dirty,inode stays in
                                      -b_dirty_time
                                      unlock inode->i_lock
Quoted 8 lines

if(!(inode->i_state & I_DIRTY_All))
-not true,so nothing done

This patch moves the dirty inode to b_dirty list when the inode currently is not queued in b_io or b_more_io list at the end of writeback_single_inode.

Thanks for report and the fix! The patch looks good so feel free to add:

Also please add tags:

Fixes 0ae45f63d4ef ("vfs: add support for a lazytime mount option")

Thanks.
Honza

Quoted 17 lines
fs/fs-writeback.c +3 -0
index 591fe9cf1659..d7763feaf14a 100644
@@ -1712,6 +1712,9 @@ static int writeback_single_inode(struct inode *inode,
 	 */
 	if (!(inode->i_state & I_DIRTY_ALL))
 		inode_cgwb_move_to_attached(inode, wb);
+	else if (!(inode->i_state & I_SYNC_QUEUED) && (inode->i_state & I_DIRTY))
+		redirty_tail_locked(inode, wb);
+
 	spin_unlock(&wb->list_lock);
 	inode_sync_complete(inode);
 out:
Signature · 1 line
2.17.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw

Thanks, I'll update the patch.

Quoted 70 lines · Jan Kara
Quoted 27 lines · Jing Xia

We have run into an issue that a task gets stuck in balance_dirty_pages_ratelimited() when perform I/O stress testing. The reason we observed is that an I_DIRTY_PAGES inode with lots of dirty pages is in b_dirty_time list and standard background writeback cannot writeback the inode.
After studing the relevant code, the following scenario may lead to the issue:

task1 task2
----- -----
fuse_flush
write_inode_now //in b_dirty_time
writeback_single_inode
__writeback_single_inode

                                 fuse_write_end
                                  filemap_dirty_folio
                                   __xa_set_mark:PAGECACHE_TAG_DIRTY
    lock inode->i_lock
    if mapping tagged PAGECACHE_TAG_DIRTY
    inode->i_state |= I_DIRTY_PAGES
    unlock inode->i_lock
                                   __mark_inode_dirty:I_DIRTY_PAGES
                                      lock inode->i_lock
                                      -was dirty,inode stays in
                                      -b_dirty_time
                                      unlock inode->i_lock
Quoted 8 lines

if(!(inode->i_state & I_DIRTY_All))
-not true,so nothing done

This patch moves the dirty inode to b_dirty list when the inode currently is not queued in b_io or b_more_io list at the end of writeback_single_inode.

Thanks for report and the fix! The patch looks good so feel free to add:

Also please add tags:

Fixes 0ae45f63d4ef ("vfs: add support for a lazytime mount option")

Thanks.
Honza

Quoted 15 lines
fs/fs-writeback.c +3 -1
index 591fe9cf1659..d7763feaf14a 100644
@@ -1712,6 +1712,9 @@ static int writeback_single_inode(struct inode *inode,
       */
      if (!(inode->i_state & I_DIRTY_ALL))
              inode_cgwb_move_to_attached(inode, wb);
+     else if (!(inode->i_state & I_SYNC_QUEUED) && (inode->i_state & I_DIRTY))
+             redirty_tail_locked(inode, wb);
+
      spin_unlock(&wb->list_lock);
      inode_sync_complete(inode);
 out:
--
Quoted 2 lines

2.17.1

--
Jan Kara <[email protected]>
SUSE Labs, CR

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jing Xia

fs/fs-writeback.c static int writeback_single_inode(struct inode *inode, · line 1715

Quoted 3 lines · Jing Xia
fs/fs-writeback.c +1 -0
 	if (!(inode->i_state & I_DIRTY_ALL))
 		inode_cgwb_move_to_attached(inode, wb);
+	else if (!(inode->i_state & I_SYNC_QUEUED) && (inode->i_state & I_DIRTY))

Please turn this into

	else if ((inode->i_state & I_DIRTY) &&
	         !(inode->i_state & I_SYNC_QUEUED))

to keep it a little more readable.

Otherwise looks good:

#4 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Jing Xia
      if (!(inode->i_state & I_DIRTY_ALL))
              inode_cgwb_move_to_attached(inode, wb);

+ else if (!(inode->i_state & I_SYNC_QUEUED) && (inode->i_state & I_DIRTY))

Please turn this into

Quoted 8 lines
        else if ((inode->i_state & I_DIRTY) &&
                 !(inode->i_state & I_SYNC_QUEUED))

to keep it a little more readable.

Otherwise looks good:

Ok. And thanks for the review.