]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: flush plug periodically during GC to maximize readahead effect
authorDaeho Jeong <daehojeong@google.com>
Tue, 30 Dec 2025 17:38:45 +0000 (09:38 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 7 Jan 2026 03:17:06 +0000 (03:17 +0000)
During the garbage collection process, F2FS submits readahead I/Os for
valid blocks. However, since the GC loop runs within a single plug scope
without intermediate flushing, these readahead I/Os often accumulate in
the block layer's plug list instead of being dispatched to the device
immediately.

Consequently, when the GC thread attempts to lock the page later, the
I/O might not have completed (or even started), leading to a "read try
and wait" scenario. This negates the benefit of readahead and causes
unnecessary delays in GC latency.

This patch addresses this issue by introducing an intermediate
blk_finish_plug() and blk_start_plug() pair within the GC loop. This
forces the dispatch of pending I/Os, ensuring that readahead pages are
fetched in time, thereby reducing GC latency.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c

index d889f7d9a70f1c7c7f5fc5f704dd9ad206fdd429..ba66d8bc9b5f298ec6d34422d20dbfb89e16718d 100644 (file)
@@ -1031,7 +1031,8 @@ static int check_valid_map(struct f2fs_sb_info *sbi,
  * ignore that.
  */
 static int gc_node_segment(struct f2fs_sb_info *sbi,
-               struct f2fs_summary *sum, unsigned int segno, int gc_type)
+               struct f2fs_summary *sum, unsigned int segno, int gc_type,
+               struct blk_plug *plug)
 {
        struct f2fs_summary *entry;
        block_t start_addr;
@@ -1100,8 +1101,11 @@ next_step:
                stat_inc_node_blk_count(sbi, 1, gc_type);
        }
 
-       if (++phase < 3)
+       if (++phase < 3) {
+               blk_finish_plug(plug);
+               blk_start_plug(plug);
                goto next_step;
+       }
 
        if (fggc)
                atomic_dec(&sbi->wb_sync_req[NODE]);
@@ -1539,7 +1543,7 @@ out:
  */
 static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                struct gc_inode_list *gc_list, unsigned int segno, int gc_type,
-               bool force_migrate)
+               bool force_migrate, struct blk_plug *plug)
 {
        struct super_block *sb = sbi->sb;
        struct f2fs_summary *entry;
@@ -1707,8 +1711,11 @@ next_step:
                }
        }
 
-       if (++phase < 5)
+       if (++phase < 5) {
+               blk_finish_plug(plug);
+               blk_start_plug(plug);
                goto next_step;
+       }
 
        return submitted;
 }
@@ -1857,11 +1864,11 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
                         */
                        if (type == SUM_TYPE_NODE)
                                submitted += gc_node_segment(sbi, sum->entries,
-                                               cur_segno, gc_type);
+                                               cur_segno, gc_type, &plug);
                        else
                                submitted += gc_data_segment(sbi, sum->entries,
                                                gc_list, cur_segno,
-                                               gc_type, force_migrate);
+                                               gc_type, force_migrate, &plug);
 
                        stat_inc_gc_seg_count(sbi, data_type, gc_type);
                        sbi->gc_reclaimed_segs[sbi->gc_mode]++;