Patch "fs-writeback: do not requeue a clean inode having skipped pages" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    fs-writeback: do not requeue a clean inode having skipped pages

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     fs-writeback-do-not-requeue-a-clean-inode-having-ski.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 91fd6d0b1a881061fa737b9afd5f1a4714d326c1
Author: Chunhai Guo <guochunhai@xxxxxxxx>
Date:   Fri Sep 15 22:51:31 2023 -0600

    fs-writeback: do not requeue a clean inode having skipped pages
    
    [ Upstream commit be049c3a088d512187407b7fd036cecfab46d565 ]
    
    When writing back an inode and performing an fsync on it concurrently, a
    deadlock issue may arise as shown below. In each writeback iteration, a
    clean inode is requeued to the wb->b_dirty queue due to non-zero
    pages_skipped, without anything actually being written. This causes an
    infinite loop and prevents the plug from being flushed, resulting in a
    deadlock. We now avoid requeuing the clean inode to prevent this issue.
    
        wb_writeback        fsync (inode-Y)
    blk_start_plug(&plug)
    for (;;) {
      iter i-1: some reqs with page-X added into plug->mq_list // f2fs node page-X with PG_writeback
                            filemap_fdatawrite
                              __filemap_fdatawrite_range // write inode-Y with sync_mode WB_SYNC_ALL
                               do_writepages
                                f2fs_write_data_pages
                                 __f2fs_write_data_pages // wb_sync_req[DATA]++ for WB_SYNC_ALL
                                  f2fs_write_cache_pages
                                   f2fs_write_single_data_page
                                    f2fs_do_write_data_page
                                     f2fs_outplace_write_data
                                      f2fs_update_data_blkaddr
                                       f2fs_wait_on_page_writeback
                                         wait_on_page_writeback // wait for f2fs node page-X
      iter i:
        progress = __writeback_inodes_wb(wb, work)
        . writeback_sb_inodes
        .   __writeback_single_inode // write inode-Y with sync_mode WB_SYNC_NONE
        .   . do_writepages
        .   .   f2fs_write_data_pages
        .   .   .  __f2fs_write_data_pages // skip writepages due to (wb_sync_req[DATA]>0)
        .   .   .   wbc->pages_skipped += get_dirty_pages(inode) // wbc->pages_skipped = 1
        .   if (!(inode->i_state & I_DIRTY_ALL)) // i_state = I_SYNC | I_SYNC_QUEUED
        .    total_wrote++;  // total_wrote = 1
        .   requeue_inode // requeue inode-Y to wb->b_dirty queue due to non-zero pages_skipped
        if (progress) // progress = 1
          continue;
      iter i+1:
          queue_io
          // similar process with iter i, infinite for-loop !
    }
    blk_finish_plug(&plug)   // flush plug won't be called
    
    Signed-off-by: Chunhai Guo <guochunhai@xxxxxxxx>
    Reviewed-by: Jan Kara <jack@xxxxxxx>
    Message-Id: <20230916045131.957929-1-guochunhai@xxxxxxxx>
    Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index c76537a6826a7..5f0abea107e46 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -1557,10 +1557,15 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
 
 	if (wbc->pages_skipped) {
 		/*
-		 * writeback is not making progress due to locked
-		 * buffers. Skip this inode for now.
+		 * Writeback is not making progress due to locked buffers.
+		 * Skip this inode for now. Although having skipped pages
+		 * is odd for clean inodes, it can happen for some
+		 * filesystems so handle that gracefully.
 		 */
-		redirty_tail_locked(inode, wb);
+		if (inode->i_state & I_DIRTY_ALL)
+			redirty_tail_locked(inode, wb);
+		else
+			inode_cgwb_move_to_attached(inode, wb);
 		return;
 	}
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux