Skip to content

Commit 8c890c4

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: introduce migration_window_granularity
We can control the scanning window granularity for GC migration. For more frequent scanning and GC on zoned devices, we need a fine grained control knob for it. Signed-off-by: Daeho Jeong <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 5062b5b commit 8c890c4

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,11 @@ Description: The zone UFS we are currently using consists of two parts:
783783
blkzone_alloc_policy = 1 Only allow writing to sequential zones
784784
blkzone_alloc_policy = 2 Prioritize writing to conventional zones
785785
======================== =========================================
786+
787+
What: /sys/fs/f2fs/<disk>/migration_window_granularity
788+
Date: September 2024
789+
Contact: "Daeho Jeong" <[email protected]>
790+
Description: Controls migration window granularity of garbage collection on large
791+
section. it can control the scanning window granularity for GC migration
792+
in a unit of segment, while migration_granularity controls the number
793+
of segments which can be migrated at the same turn.

fs/f2fs/f2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,8 @@ struct f2fs_sb_info {
16961696
unsigned int max_victim_search;
16971697
/* migration granularity of garbage collection, unit: segment */
16981698
unsigned int migration_granularity;
1699+
/* migration window granularity of garbage collection, unit: segment */
1700+
unsigned int migration_window_granularity;
16991701

17001702
/*
17011703
* for stat information.

fs/f2fs/gc.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,24 +1708,34 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
17081708
struct blk_plug plug;
17091709
unsigned int segno = start_segno;
17101710
unsigned int end_segno = start_segno + SEGS_PER_SEC(sbi);
1711+
unsigned int sec_end_segno;
17111712
int seg_freed = 0, migrated = 0;
17121713
unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
17131714
SUM_TYPE_DATA : SUM_TYPE_NODE;
17141715
unsigned char data_type = (type == SUM_TYPE_DATA) ? DATA : NODE;
17151716
int submitted = 0;
17161717

1717-
if (__is_large_section(sbi))
1718-
end_segno = rounddown(end_segno, SEGS_PER_SEC(sbi));
1718+
if (__is_large_section(sbi)) {
1719+
sec_end_segno = rounddown(end_segno, SEGS_PER_SEC(sbi));
17191720

1720-
/*
1721-
* zone-capacity can be less than zone-size in zoned devices,
1722-
* resulting in less than expected usable segments in the zone,
1723-
* calculate the end segno in the zone which can be garbage collected
1724-
*/
1725-
if (f2fs_sb_has_blkzoned(sbi))
1726-
end_segno -= SEGS_PER_SEC(sbi) -
1721+
/*
1722+
* zone-capacity can be less than zone-size in zoned devices,
1723+
* resulting in less than expected usable segments in the zone,
1724+
* calculate the end segno in the zone which can be garbage
1725+
* collected
1726+
*/
1727+
if (f2fs_sb_has_blkzoned(sbi))
1728+
sec_end_segno -= SEGS_PER_SEC(sbi) -
17271729
f2fs_usable_segs_in_sec(sbi, segno);
17281730

1731+
if (gc_type == BG_GC)
1732+
end_segno = start_segno +
1733+
sbi->migration_window_granularity;
1734+
1735+
if (end_segno > sec_end_segno)
1736+
end_segno = sec_end_segno;
1737+
}
1738+
17291739
sanity_check_seg_type(sbi, get_seg_entry(sbi, segno)->type);
17301740

17311741
/* readahead multi ssa blocks those have contiguous address */
@@ -1803,7 +1813,8 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
18031813

18041814
if (__is_large_section(sbi))
18051815
sbi->next_victim_seg[gc_type] =
1806-
(segno + 1 < end_segno) ? segno + 1 : NULL_SEGNO;
1816+
(segno + 1 < sec_end_segno) ?
1817+
segno + 1 : NULL_SEGNO;
18071818
skip:
18081819
f2fs_put_page(sum_page, 0);
18091820
}

fs/f2fs/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#define LIMIT_NO_ZONED_GC 60 /* percentage over total user space of no gc for zoned devices */
3434
#define LIMIT_BOOST_ZONED_GC 25 /* percentage over total user space of boosted gc for zoned devices */
35+
#define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED 3
3536

3637
#define DEF_GC_FAILED_PINNED_FILES 2048
3738
#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX

fs/f2fs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
38073807
sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
38083808
sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
38093809
sbi->migration_granularity = SEGS_PER_SEC(sbi);
3810+
sbi->migration_window_granularity = f2fs_sb_has_blkzoned(sbi) ?
3811+
DEF_MIGRATION_WINDOW_GRANULARITY_ZONED : SEGS_PER_SEC(sbi);
38103812
sbi->seq_file_ra_mul = MIN_RA_MUL;
38113813
sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
38123814
sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;

fs/f2fs/sysfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
564564
return -EINVAL;
565565
}
566566

567+
if (!strcmp(a->attr.name, "migration_window_granularity")) {
568+
if (t == 0 || t > SEGS_PER_SEC(sbi))
569+
return -EINVAL;
570+
}
571+
567572
if (!strcmp(a->attr.name, "gc_urgent")) {
568573
if (t == 0) {
569574
sbi->gc_mode = GC_NORMAL;
@@ -1013,6 +1018,7 @@ F2FS_SBI_RW_ATTR(gc_pin_file_thresh, gc_pin_file_threshold);
10131018
F2FS_SBI_RW_ATTR(gc_reclaimed_segments, gc_reclaimed_segs);
10141019
F2FS_SBI_GENERAL_RW_ATTR(max_victim_search);
10151020
F2FS_SBI_GENERAL_RW_ATTR(migration_granularity);
1021+
F2FS_SBI_GENERAL_RW_ATTR(migration_window_granularity);
10161022
F2FS_SBI_GENERAL_RW_ATTR(dir_level);
10171023
#ifdef CONFIG_F2FS_IOSTAT
10181024
F2FS_SBI_GENERAL_RW_ATTR(iostat_enable);
@@ -1154,6 +1160,7 @@ static struct attribute *f2fs_attrs[] = {
11541160
ATTR_LIST(min_ssr_sections),
11551161
ATTR_LIST(max_victim_search),
11561162
ATTR_LIST(migration_granularity),
1163+
ATTR_LIST(migration_window_granularity),
11571164
ATTR_LIST(dir_level),
11581165
ATTR_LIST(ram_thresh),
11591166
ATTR_LIST(ra_nid_pages),

0 commit comments

Comments
 (0)