[PATCH v3 2/2] f2fs: Integration of migration window granularity with migration Granularity

From: yohan.joung
Date: Thu Apr 17 2025 - 00:15:11 EST


Modify the large section so that only segments
with valid blocks are moved.
Remove Migration Window Granularity by searching
based on segment numbers instead of window search

Signed-off-by: yohan.joung <yohan.joung@xxxxxx>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 8 --------
fs/f2fs/gc.c | 15 +++++++++------
fs/f2fs/gc.h | 2 +-
fs/f2fs/super.c | 5 ++---
fs/f2fs/sysfs.c | 7 -------
5 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 59adb7dc6f9e..b65033730a2c 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -788,14 +788,6 @@ Description: The zone UFS we are currently using consists of two parts:
blkzone_alloc_policy = 2 Prioritize writing to conventional zones
======================== =========================================

-What: /sys/fs/f2fs/<disk>/migration_window_granularity
-Date: September 2024
-Contact: "Daeho Jeong" <daehojeong@xxxxxxxxxx>
-Description: Controls migration window granularity of garbage collection on large
- section. it can control the scanning window granularity for GC migration
- in a unit of segment, while migration_granularity controls the number
- of segments which can be migrated at the same turn.
-
What: /sys/fs/f2fs/<disk>/reserved_segments
Date: September 2024
Contact: "Daeho Jeong" <daehojeong@xxxxxxxxxx>
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index fcd2cf68612d..3496c1523be7 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1750,7 +1750,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
unsigned int segno = start_segno;
unsigned int end_segno = start_segno + SEGS_PER_SEC(sbi);
unsigned int sec_end_segno;
- unsigned int window_granularity = 1;
+ unsigned int migration_granularity = sbi->migration_granularity;
int seg_freed = 0, migrated = 0;
unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
SUM_TYPE_DATA : SUM_TYPE_NODE;
@@ -1773,29 +1773,32 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
f2fs_usable_segs_in_sec(sbi);

if (gc_type == BG_GC || one_time) {
- window_granularity =
- sbi->migration_window_granularity;

if (f2fs_sb_has_blkzoned(sbi) &&
!has_enough_free_blocks(sbi,
sbi->gc_thread->boost_zoned_gc_percent))
- window_granularity *=
+ migration_granularity *=
BOOST_GC_MULTIPLE;
}

+ if (gc_type == FG_GC) {
+ migration_granularity = sec_end_segno - start_segno;
+ }
+
if (end_segno > sec_end_segno)
end_segno = sec_end_segno;
}

sanity_check_seg_type(sbi, get_seg_entry(sbi, segno)->type);

+
for (segno = start_segno; segno < end_segno; segno++) {
if (!get_valid_blocks(sbi, segno, false))
continue;

/* readahead multi ssa blocks those have contiguous address */
f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno),
- window_granularity, META_SSA, true);
+ migration_granularity, META_SSA, true);

/* reference all summary page */
sum_page = f2fs_get_sum_page(sbi, segno);
@@ -1806,7 +1809,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
}
add_gc_page_entry(&gc_page_list, sum_page, segno);
unlock_page(sum_page);
- if (++gc_list_count >= window_granularity)
+ if (++gc_list_count >= migration_granularity)
break;
}

diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h
index 9c8695efe394..5e933c2110d2 100644
--- a/fs/f2fs/gc.h
+++ b/fs/f2fs/gc.h
@@ -33,7 +33,7 @@

#define LIMIT_NO_ZONED_GC 60 /* percentage over total user space of no gc for zoned devices */
#define LIMIT_BOOST_ZONED_GC 25 /* percentage over total user space of boosted gc for zoned devices */
-#define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED 3
+#define DEF_MIGRATION_GRANULARITY_ZONED 3
#define BOOST_GC_MULTIPLE 5
#define ZONED_PIN_SEC_REQUIRED_COUNT 1

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index a3241730fe4f..775a6e3cc6a6 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -3890,9 +3890,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
- sbi->migration_granularity = SEGS_PER_SEC(sbi);
- sbi->migration_window_granularity = f2fs_sb_has_blkzoned(sbi) ?
- DEF_MIGRATION_WINDOW_GRANULARITY_ZONED : SEGS_PER_SEC(sbi);
+ sbi->migration_granularity = f2fs_sb_has_blkzoned(sbi) ?
+ DEF_MIGRATION_GRANULARITY_ZONED : SEGS_PER_SEC(sbi);
sbi->seq_file_ra_mul = MIN_RA_MUL;
sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index c69161366467..6a47b9c9c267 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -568,11 +568,6 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return -EINVAL;
}

- if (!strcmp(a->attr.name, "migration_window_granularity")) {
- if (t == 0 || t > SEGS_PER_SEC(sbi))
- return -EINVAL;
- }
-
if (!strcmp(a->attr.name, "gc_urgent")) {
if (t == 0) {
sbi->gc_mode = GC_NORMAL;
@@ -1085,7 +1080,6 @@ F2FS_SBI_RW_ATTR(gc_pin_file_thresh, gc_pin_file_threshold);
F2FS_SBI_RW_ATTR(gc_reclaimed_segments, gc_reclaimed_segs);
F2FS_SBI_GENERAL_RW_ATTR(max_victim_search);
F2FS_SBI_GENERAL_RW_ATTR(migration_granularity);
-F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity);
F2FS_SBI_GENERAL_RW_ATTR(dir_level);
#ifdef CONFIG_F2FS_IOSTAT
F2FS_SBI_GENERAL_RW_ATTR(iostat_enable);
@@ -1234,7 +1228,6 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(reserved_segments),
ATTR_LIST(max_victim_search),
ATTR_LIST(migration_granularity),
- ATTR_LIST(migration_window_granularity),
ATTR_LIST(dir_level),
ATTR_LIST(ram_thresh),
ATTR_LIST(ra_nid_pages),
--
2.33.0