Skip to contentSkip to conversation

f2fs: Improve large section GC by locating valid block segments

PATCH New yohan.joung 1 participant 2 messages Apr 17, 2025 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 f2fs: Improve large section GC by locating valid block segments

Change the large section GC to locate valid block segments instead of performing a sequential search. This modification enhances performance by reducing unnecessary block scanning in large storage sections.

example :
[invalid seg 0] [invalid seg 1] [invalid seg 2]
[ valid seg 3] [ valid seg 4] [ valid seg 5]

Current: In the first GC, nothing is moved,
but in the second GC, segments 3, 4, and 5 are moved.
Change: In the first GC, segments 3, 4, and 5 are moved.

---
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/gc.c    | 89 +++++++++++++++++++++++++++++++++++++------------
 fs/f2fs/gc.h    |  6 ++++
 fs/f2fs/super.c |  8 ++++-
 4 files changed, 82 insertions(+), 23 deletions(-)
fs/f2fs/f2fs.h +2 -0
index f1576dc6ec67..348417edac25 100644
@@ -4008,6 +4008,8 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi,
 int f2fs_resize_fs(struct file *filp, __u64 block_count);
 int __init f2fs_create_garbage_collection_cache(void);
 void f2fs_destroy_garbage_collection_cache(void);
+int __init f2fs_init_garbage_collection_summary_cache(void);
+void f2fs_destroy_garbage_collection_summary_cache(void);
 /* victim selection function for cleaning and SSR */
 int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
 			int gc_type, int type, char alloc_mode,
fs/f2fs/gc.c +67 -22

166 lines not on this page · raw message

fs/f2fs/gc.h +6 -0
index 5c1eaf55e127..9c8695efe394 100644
@@ -82,6 +82,12 @@ struct victim_entry {
 	struct list_head list;
 };
 
+struct gc_page_entry {
+	unsigned int segno;
+	struct page *sum_page;
+	struct list_head list;
+};
+
 /*
  * inline functions
  */
fs/f2fs/super.c +7 -1
index f087b2b71c89..a3241730fe4f 100644
@@ -5090,9 +5090,12 @@ static int __init init_f2fs_fs(void)
 	err = f2fs_create_garbage_collection_cache();
 	if (err)
 		goto free_extent_cache;
-	err = f2fs_init_sysfs();
+	err = f2fs_init_garbage_collection_summary_cache();
 	if (err)
 		goto free_garbage_collection_cache;
+	err = f2fs_init_sysfs();
+	if (err)
+		goto free_garbage_collection_summary_cache;
 	err = f2fs_init_shrinker();
 	if (err)
 		goto free_sysfs;
@@ -5141,6 +5144,8 @@ static int __init init_f2fs_fs(void)
 	f2fs_exit_shrinker();
 free_sysfs:
 	f2fs_exit_sysfs();
+free_garbage_collection_summary_cache:
+	f2fs_destroy_garbage_collection_summary_cache();
 free_garbage_collection_cache:
 	f2fs_destroy_garbage_collection_cache();
 free_extent_cache:
@@ -5172,6 +5177,7 @@ static void __exit exit_f2fs_fs(void)
 	f2fs_destroy_root_stats();
 	f2fs_exit_shrinker();
 	f2fs_exit_sysfs();
+	f2fs_destroy_garbage_collection_summary_cache();
 	f2fs_destroy_garbage_collection_cache();
 	f2fs_destroy_extent_cache();
 	f2fs_destroy_recovery_cache();
Signature · 1 line
2.33.0
#1 lore raw

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

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

---
 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(-)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -8
index 59adb7dc6f9e..b65033730a2c 100644
@@ -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" <[email protected]>
-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" <[email protected]>
fs/f2fs/gc.c +9 -6
index fcd2cf68612d..3496c1523be7 100644
@@ -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;
 	}
 
fs/f2fs/gc.h +1 -1
index 9c8695efe394..5e933c2110d2 100644
@@ -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
 
fs/f2fs/super.c +2 -3
index a3241730fe4f..775a6e3cc6a6 100644
@@ -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;
fs/f2fs/sysfs.c +0 -7
index c69161366467..6a47b9c9c267 100644
@@ -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),
Signature · 1 line
2.33.0