f2fs: make BG GC more aggressive for zoned devices
PATCH v2 1/7 f2fs: make BG GC more aggressive for zoned devices
From: Daeho Jeong <[email protected]>
Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that.
--- fs/f2fs/f2fs.h | 20 ++++++++++++++++++-- fs/f2fs/gc.c | 25 +++++++++++++++++++++---- fs/f2fs/gc.h | 21 +++++++++++++++++++++ fs/f2fs/super.c | 5 +++++ 4 files changed, 65 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +18 -2
@@ -2854,13 +2854,26 @@ static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type)return false; } +static inline bool is_inflight_read_io (struct f2fs_sb_info *sbi) +{ +return get_pages (sbi,F2FS_RD_DATA ) ||get_pages (sbi,F2FS_DIO_READ ); +} +static inline bool is_idle (struct f2fs_sb_info *sbi,int type) { +bool zoned_gc = (type ==GC_TIME && +F2FS_HAS_FEATURE (sbi,F2FS_FEATURE_BLKZONED )); +if (sbi->gc_mode ==GC_URGENT_HIGH )return true; -if (is_inflight_io (sbi, type)) -return false; +if (zoned_gc) { +if (is_inflight_read_io (sbi)) +return false; + }else { +if (is_inflight_io (sbi, type)) +return false; + }if (sbi->gc_mode ==GC_URGENT_MID )return true;
@@ -2869,6 +2882,9 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type) (type == DISCARD_TIME || type == GC_TIME))return true; +if (zoned_gc) +return true; +return f2fs_time_over (sbi, type); }
fs/f2fs/gc.c +21 -4
@@ -116,7 +116,17 @@ static int gc_thread_func(void *data) goto next; } -if (has_enough_invalid_blocks (sbi)) +if (f2fs_sb_has_blkzoned (sbi)) { +if (has_enough_free_blocks (sbi,LIMIT_NO_ZONED_GC )) { + wait_ms = gc_th->no_gc_sleep_time; +f2fs_up_write (&sbi->gc_lock); + goto next; + } +if (wait_ms == gc_th->no_gc_sleep_time) + wait_ms = gc_th->max_sleep_time; + } + +if (need_to_boost_gc (sbi))decrease_sleep_time (gc_th, &wait_ms);else increase_sleep_time (gc_th, &wait_ms);
@@ -179,9 +189,16 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi)return -ENOMEM ; gc_th->urgent_sleep_time =DEF_GC_THREAD_URGENT_SLEEP_TIME ; - gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME ; - gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME ; - gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME ; + +if (f2fs_sb_has_blkzoned (sbi)) { + gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED ; + gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED ; + gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED ; + }else { + gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME ; + gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME ; + gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME ; + } gc_th->gc_wake = false;
fs/f2fs/gc.h +21 -0
@@ -15,6 +15,11 @@#define DEF_GC_THREAD_MAX_SLEEP_TIME 60000#define DEF_GC_THREAD_NOGC_SLEEP_TIME 300000/* wait 5 min */ +/* GC sleep parameters for zoned deivces */ +#define DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED 10 +#define DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED 20 +#define DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED 60000 +/* choose candidates from sections which has age of more than 7 days */ #define DEF_GC_THREAD_AGE_THRESHOLD (60 * 60 * 24 * 7)#define DEF_GC_THREAD_CANDIDATE_RATIO 20/* select 20% oldest sections as candidates */
@@ -25,6 +30,9 @@#define LIMIT_INVALID_BLOCK 40/* percentage over total user space */ #define LIMIT_FREE_BLOCK 40/* percentage over invalid + free space */ +#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_GC_FAILED_PINNED_FILES 2048#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX
@@ -152,6 +160,12 @@ static inline void decrease_sleep_time(struct f2fs_gc_kthread *gc_th, *wait -= min_time; } +static inline bool has_enough_free_blocks (struct f2fs_sb_info *sbi, +unsigned int limit_perc) +{ +return free_sections (sbi) > ((sbi->total_sections * limit_perc) /100 ); +} +static inline bool has_enough_invalid_blocks (struct f2fs_sb_info *sbi) {block_t user_block_count = sbi->user_block_count;
@@ -167,3 +181,10 @@ static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)free_user_blocks (sbi) < limit_free_user_blocks(invalid_user_blocks)); } + +static inline bool need_to_boost_gc (struct f2fs_sb_info *sbi) +{ +if (f2fs_sb_has_blkzoned (sbi)) +return !has_enough_free_blocks (sbi,LIMIT_BOOST_ZONED_GC ); +return has_enough_invalid_blocks (sbi); +}
fs/f2fs/super.c +5 -0
@@ -707,6 +707,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)if (!strcmp (name,"on" )) {F2FS_OPTION (sbi).bggc_mode =BGGC_MODE_ON ; }else if (!strcmp (name,"off" )) { +if (f2fs_sb_has_blkzoned (sbi)) { +f2fs_warn (sbi,"zoned devices need bggc" ); +kfree (name); +return -EINVAL ; + }F2FS_OPTION (sbi).bggc_mode =BGGC_MODE_OFF ; }else if (!strcmp (name,"sync" )) {F2FS_OPTION (sbi).bggc_mode =BGGC_MODE_SYNC ;
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
PATCH v2 2/7 f2fs: introduce migration_window_granularity
From: Daeho Jeong <[email protected]>
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.
---
v2: introduced a new migration_window_granularity instead of changing
the meaning of the current migration_granularity
--- Documentation/ABI/testing/sysfs-fs-f2fs | 8 +++++++ fs/f2fs/f2fs.h | 2 ++ fs/f2fs/gc.c | 31 +++++++++++++++++-------- fs/f2fs/gc.h | 1 + fs/f2fs/super.c | 2 ++ fs/f2fs/sysfs.c | 7 ++++++ 6 files changed, 41 insertions(+), 10 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +8 -0
@@ -763,3 +763,11 @@ Date: November 2023 Contact: "Chao Yu" <[email protected]> Description: It controls to enable/disable IO aware feature for background discard. By default, the value is 1 which indicates IO aware is on. + +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.
fs/f2fs/f2fs.h +2 -0
@@ -1685,6 +1685,8 @@ struct f2fs_sb_info {unsigned int max_victim_search;/* migration granularity of garbage collection, unit: segment */ unsigned int migration_granularity; +/* migration window granularity of garbage collection, unit: segment */ +unsigned int migration_window_granularity;/* * for stat information.
fs/f2fs/gc.c +21 -10
@@ -1708,24 +1708,34 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,struct blk_plug plug;unsigned int segno = start_segno;unsigned int end_segno = start_segno +SEGS_PER_SEC (sbi); +unsigned int sec_end_segno;int seg_freed =0 , migrated =0 ;unsigned char type =IS_DATASEG (get_seg_entry (sbi, segno)->type) ?SUM_TYPE_DATA :SUM_TYPE_NODE ;unsigned char data_type = (type ==SUM_TYPE_DATA ) ?DATA :NODE ;int submitted =0 ; -if (__is_large_section (sbi)) - end_segno =rounddown (end_segno,SEGS_PER_SEC (sbi)); +if (__is_large_section (sbi)) { + sec_end_segno =rounddown (end_segno,SEGS_PER_SEC (sbi)); -/* -* zone-capacity can be less than zone-size in zoned devices, -* resulting in less than expected usable segments in the zone, -* calculate the end segno in the zone which can be garbage collected -*/ -if (f2fs_sb_has_blkzoned (sbi)) - end_segno -=SEGS_PER_SEC (sbi) - +/* +* zone-capacity can be less than zone-size in zoned devices, +* resulting in less than expected usable segments in the zone, +* calculate the end segno in the zone which can be garbage +* collected +*/ +if (f2fs_sb_has_blkzoned (sbi)) + sec_end_segno -=SEGS_PER_SEC (sbi) -f2fs_usable_segs_in_sec (sbi, segno); +if (gc_type ==BG_GC ) + end_segno = start_segno + + sbi->migration_window_granularity; + +if (end_segno > sec_end_segno) + end_segno = sec_end_segno; + } +sanity_check_seg_type (sbi,get_seg_entry (sbi, segno)->type);/* readahead multi ssa blocks those have contiguous address */
@@ -1803,7 +1813,8 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,if (__is_large_section (sbi)) sbi->next_victim_seg[gc_type] = - (segno +1 < end_segno) ? segno +1 :NULL_SEGNO ; + (segno +1 < sec_end_segno) ? + segno +1 :NULL_SEGNO ; skip:f2fs_put_page (sum_page,0 ); }
fs/f2fs/gc.h +1 -0
@@ -32,6 +32,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_GC_FAILED_PINNED_FILES 2048#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX
fs/f2fs/super.c +2 -0
@@ -3791,6 +3791,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) 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->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 +7 -0
@@ -561,6 +561,11 @@ 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 ;
@@ -1001,6 +1006,7 @@ 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);
@@ -1140,6 +1146,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (min_ssr_sections),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.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 2/7] f2fs: introduce migration_window_granularity
Quoted 7 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
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]>
Thanks,
PATCH v2 3/7 f2fs: add reserved_segments sysfs node
In reply to Daeho JeongFrom: Daeho Jeong <[email protected]>
For the fine tuning of GC behavior, add reserved_segments sysfs node.
--- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++ fs/f2fs/sysfs.c | 2 ++ 2 files changed, 8 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
@@ -771,3 +771,9 @@ Description: Controls migration window granularity of garbage collection on larg 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]> +Description: In order to fine tune GC behavior, we can control the number of + reserved segments.
fs/f2fs/sysfs.c +2 -0
@@ -974,6 +974,7 @@ SM_INFO_GENERAL_RW_ATTR(min_fsync_blocks);SM_INFO_GENERAL_RW_ATTR (min_seq_blocks);SM_INFO_GENERAL_RW_ATTR (min_hot_blocks);SM_INFO_GENERAL_RW_ATTR (min_ssr_sections); +SM_INFO_GENERAL_RW_ATTR (reserved_segments);/* DCC_INFO ATTR */ DCC_INFO_RW_ATTR (max_small_discards, max_discards);
@@ -1144,6 +1145,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (min_seq_blocks),ATTR_LIST (min_hot_blocks),ATTR_LIST (min_ssr_sections), +ATTR_LIST (reserved_segments),ATTR_LIST (max_victim_search),ATTR_LIST (migration_granularity), ATTR_LIST(migration_window_granularity),
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 3/7] f2fs: add reserved_segments sysfs node
Quoted 5 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
For the fine tuning of GC behavior, add
reserved_segmentssysfs node.Signed-off-by Daeho Jeong <[email protected]>
Thanks,
PATCH v2 4/7 f2fs: increase BG GC migration window granularity when boosted for zoned devices
In reply to Daeho JeongFrom: Daeho Jeong <[email protected]>
Need bigger BG GC migration window granularity when free section is running low.
--- fs/f2fs/gc.c | 12 ++++++++++-- fs/f2fs/gc.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +10 -2
@@ -1728,10 +1728,18 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, sec_end_segno -=SEGS_PER_SEC (sbi) -f2fs_usable_segs_in_sec (sbi, segno); -if (gc_type ==BG_GC ) - end_segno = start_segno + +if (gc_type ==BG_GC ) { +unsigned int window_granularity = sbi->migration_window_granularity; +if (f2fs_sb_has_blkzoned (sbi) && + !has_enough_free_blocks (sbi, +LIMIT_BOOST_ZONED_GC )) + window_granularity *=BOOST_GC_MULTIPLE ; + + end_segno = start_segno + window_granularity; + } +if (end_segno > sec_end_segno) end_segno = sec_end_segno; }
fs/f2fs/gc.h +1 -0
@@ -33,6 +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 BOOST_GC_MULTIPLE 5#define DEF_GC_FAILED_PINNED_FILES 2048#define MAX_GC_FAILED_PINNED_FILES USHRT_MAX
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 4/7] f2fs: increase BG GC migration window granularity when boosted for zoned devices
Quoted 6 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Need bigger BG GC migration window granularity when free section is running low.
Signed-off-by Daeho Jeong <[email protected]>
Thanks,
PATCH v2 5/7 f2fs: do FG_GC when GC boosting is required for zoned devices
In reply to Daeho JeongFrom: Daeho Jeong <[email protected]>
Under low free section count, we need to use FG_GC instead of BG_GC to recover free sections.
---
v2: moved up the one_time field for better padding.
--- fs/f2fs/f2fs.h | 1 + fs/f2fs/gc.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-)
fs/f2fs/f2fs.h +1 -0
@@ -1293,6 +1293,7 @@ struct f2fs_gc_control {bool no_bg_gc;/* check the space and stop bg_gc */ bool should_migrate_blocks;/* should migrate blocks */ bool err_gc_skipped;/* return EAGAIN if GC skipped */ +bool one_time;/* require one time GC in one migration unit */ unsigned int nr_free_secs;/* # of free sections to do GC */ };
fs/f2fs/gc.c +17 -7
@@ -81,6 +81,8 @@ static int gc_thread_func(void *data)continue ; } + gc_control.one_time = false; +/* * [GC triggering condition] * 0. GC is not conducted currently.
@@ -126,15 +128,19 @@ static int gc_thread_func(void *data) wait_ms = gc_th->max_sleep_time; } -if (need_to_boost_gc (sbi)) +if (need_to_boost_gc (sbi)) {decrease_sleep_time (gc_th, &wait_ms); -else +if (f2fs_sb_has_blkzoned (sbi)) + gc_control.one_time = true; + }else {increase_sleep_time (gc_th, &wait_ms); + } do_gc:stat_inc_gc_call_count (sbi, foreground ?FOREGROUND :BACKGROUND ); - sync_mode =F2FS_OPTION (sbi).bggc_mode ==BGGC_MODE_SYNC ; + sync_mode = (F2FS_OPTION (sbi).bggc_mode ==BGGC_MODE_SYNC ) || + gc_control.one_time;/* foreground GC was been triggered via f2fs_balance_fs() */ if (foreground)
@@ -1701,7 +1707,7 @@ static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim,static int do_garbage_collect (struct f2fs_sb_info *sbi,unsigned int start_segno,struct gc_inode_list *gc_list,int gc_type, -bool force_migrate) +bool force_migrate,bool one_time) {struct page *sum_page;struct f2fs_summary_block *sum;
@@ -1728,7 +1734,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, sec_end_segno -=SEGS_PER_SEC (sbi) -f2fs_usable_segs_in_sec (sbi, segno); -if (gc_type ==BG_GC ) { +if (gc_type ==BG_GC || one_time) {unsigned int window_granularity = sbi->migration_window_granularity;
@@ -1911,7 +1917,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) } seg_freed =do_garbage_collect (sbi, segno, &gc_list, gc_type, - gc_control->should_migrate_blocks); + gc_control->should_migrate_blocks, + gc_control->one_time);if (seg_freed <0 ) goto stop;
@@ -1922,6 +1929,9 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) total_sec_freed++; } +if (gc_control->one_time) + goto stop; +if (gc_type ==FG_GC ) { sbi->cur_victim_sec =NULL_SEGNO ;
@@ -2047,7 +2057,7 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi, };do_garbage_collect (sbi, segno, &gc_list,FG_GC , - dry_run_sections ==0 ); + dry_run_sections ==0 , false);put_gc_inode (&gc_list);if (!dry_run &&get_valid_blocks (sbi, segno, true))
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 5/7] f2fs: do FG_GC when GC boosting is required for zoned devices
Quoted 6 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Under low free section count, we need to use
FG_GCinstead ofBG_GCto recover free sections.Signed-off-by Daeho Jeong <[email protected]>
Thanks,
PATCH v2 6/7 f2fs: create gc_no_zoned_gc_percent and gc_boost_zoned_gc_percent
In reply to Daeho JeongFrom: Daeho Jeong <[email protected]>
Added control knobs for gc_no_zoned_gc_percent and gc_boost_zoned_gc_percent.
--- Documentation/ABI/testing/sysfs-fs-f2fs | 14 ++++++++++++++ fs/f2fs/gc.c | 12 +++++++++--- fs/f2fs/gc.h | 4 ++++ fs/f2fs/sysfs.c | 4 ++++ 4 files changed, 31 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +14 -0
@@ -777,3 +777,17 @@ Date: September 2024 Contact: "Daeho Jeong" <[email protected]> Description: In order to fine tune GC behavior, we can control the number of reserved segments. + +What: /sys/fs/f2fs/<disk>/gc_no_zoned_gc_percent +Date: September 2024 +Contact: "Daeho Jeong" <[email protected]> +Description: If the percentage of free sections over total sections is above this + number, F2FS do not garbage collection for zoned devices through the + background GC thread. the default number is "60". + +What: /sys/fs/f2fs/<disk>/gc_boost_zoned_gc_percent +Date: September 2024 +Contact: "Daeho Jeong" <[email protected]> +Description: If the percentage of free sections over total sections is under this + number, F2FS boosts garbage collection for zoned devices through the + background GC thread. the default number is "25".
fs/f2fs/gc.c +9 -3
@@ -119,7 +119,8 @@ static int gc_thread_func(void *data) }if (f2fs_sb_has_blkzoned (sbi)) { -if (has_enough_free_blocks (sbi,LIMIT_NO_ZONED_GC )) { +if (has_enough_free_blocks (sbi, + gc_th->no_zoned_gc_percent)) { wait_ms = gc_th->no_gc_sleep_time;f2fs_up_write (&sbi->gc_lock); goto next;
@@ -200,10 +201,14 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED ; gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME_ZONED ; gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME_ZONED ; + gc_th->no_zoned_gc_percent =LIMIT_NO_ZONED_GC ; + gc_th->boost_zoned_gc_percent =LIMIT_BOOST_ZONED_GC ; }else { gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME ; gc_th->max_sleep_time =DEF_GC_THREAD_MAX_SLEEP_TIME ; gc_th->no_gc_sleep_time =DEF_GC_THREAD_NOGC_SLEEP_TIME ; + gc_th->no_zoned_gc_percent =0 ; + gc_th->boost_zoned_gc_percent =0 ; } gc_th->gc_wake = false;
@@ -1740,8 +1745,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,if (f2fs_sb_has_blkzoned (sbi) && !has_enough_free_blocks (sbi, -LIMIT_BOOST_ZONED_GC )) - window_granularity *=BOOST_GC_MULTIPLE ; + sbi->gc_thread->boost_zoned_gc_percent)) + window_granularity *= +BOOST_GC_MULTIPLE ; end_segno = start_segno + window_granularity; }
fs/f2fs/gc.h +4 -0
@@ -61,6 +61,10 @@ struct f2fs_gc_kthread {* caller of f2fs_balance_fs() * will wait on this wait queue. */ + +/* for gc control for zoned devices */ +unsigned int no_zoned_gc_percent; +unsigned int boost_zoned_gc_percent; };struct gc_inode_list {
fs/f2fs/sysfs.c +4 -0
@@ -965,6 +965,8 @@ GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time);GC_THREAD_RW_ATTR (gc_min_sleep_time, min_sleep_time);GC_THREAD_RW_ATTR (gc_max_sleep_time, max_sleep_time);GC_THREAD_RW_ATTR (gc_no_gc_sleep_time, no_gc_sleep_time); +GC_THREAD_RW_ATTR (gc_no_zoned_gc_percent, no_zoned_gc_percent); +GC_THREAD_RW_ATTR (gc_boost_zoned_gc_percent, boost_zoned_gc_percent);/* SM_INFO ATTR */ SM_INFO_RW_ATTR (reclaim_segments, rec_prefree_segments);
@@ -1123,6 +1125,8 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (gc_min_sleep_time),ATTR_LIST (gc_max_sleep_time),ATTR_LIST (gc_no_gc_sleep_time), +ATTR_LIST (gc_no_zoned_gc_percent), +ATTR_LIST (gc_boost_zoned_gc_percent),ATTR_LIST (gc_idle),ATTR_LIST (gc_urgent), ATTR_LIST(reclaim_segments),
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 6/7] f2fs: create gc_no_zoned_gc_percent and gc_boost_zoned_gc_percent
Quoted 6 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Added control knobs for
gc_no_zoned_gc_percentandgc_boost_zoned_gc_percent.Signed-off-by Daeho Jeong <[email protected]>
Thanks,
PATCH v2 7/7 f2fs: add valid block ratio not to do excessive GC for one time GC
In reply to Daeho JeongFrom: Daeho Jeong <[email protected]>
We need to introduce a valid block ratio threshold not to trigger excessive GC for zoned deivces. The initial value of it is 95%. So, F2FS will stop the thread from intiating GC for sections having valid blocks exceeding the ratio.
---
v2: use CAP_BLKS_PER_SEC instead of BLKS_PER_SEC
--- Documentation/ABI/testing/sysfs-fs-f2fs | 8 ++++++++ fs/f2fs/f2fs.h | 2 +- fs/f2fs/gc.c | 16 ++++++++++++---- fs/f2fs/gc.h | 2 ++ fs/f2fs/segment.c | 6 ++++-- fs/f2fs/segment.h | 1 + fs/f2fs/sysfs.c | 2 ++ 7 files changed, 30 insertions(+), 7 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +8 -0
@@ -791,3 +791,11 @@ Contact: "Daeho Jeong" <[email protected]> Description: If the percentage of free sections over total sections is under this number, F2FS boosts garbage collection for zoned devices through the background GC thread. the default number is "25". + +What: /sys/fs/f2fs/<disk>/gc_valid_thresh_ratio +Date: September 2024 +Contact: "Daeho Jeong" <[email protected]> +Description: It controls the valid block ratio threshold not to trigger excessive GC + for zoned deivces. The initial value of it is 95(%). F2FS will stop the + background GC thread from intiating GC for sections having valid blocks + exceeding the ratio.
fs/f2fs/f2fs.h +1 -1
@@ -3920,7 +3920,7 @@ void f2fs_destroy_garbage_collection_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, -unsigned long long age); +unsigned long long age,bool one_time);/* * recovery.c
fs/f2fs/gc.c +12 -4
@@ -196,6 +196,7 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi)return -ENOMEM ; gc_th->urgent_sleep_time =DEF_GC_THREAD_URGENT_SLEEP_TIME ; + gc_th->valid_thresh_ratio =DEF_GC_THREAD_VALID_THRESH_RATIO ;if (f2fs_sb_has_blkzoned (sbi)) { gc_th->min_sleep_time =DEF_GC_THREAD_MIN_SLEEP_TIME_ZONED ;
@@ -396,6 +397,11 @@ static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi,if (p->alloc_mode ==SSR )return get_seg_entry (sbi, segno)->ckpt_valid_blocks; +if (p->one_time_gc && (get_valid_blocks (sbi, segno, true) >= +CAP_BLKS_PER_SEC (sbi) * sbi->gc_thread->valid_thresh_ratio / +100 )) +return UINT_MAX ; +/* alloc_mode == LFS */ if (p->gc_mode ==GC_GREEDY )return get_valid_blocks (sbi, segno, true);
@@ -770,7 +776,7 @@ static int f2fs_gc_pinned_control(struct inode *inode, int gc_type,*/ int f2fs_get_victim (struct f2fs_sb_info *sbi,unsigned int *result,int gc_type,int type,char alloc_mode, -unsigned long long age) +unsigned long long age,bool one_time) {struct dirty_seglist_info *dirty_i =DIRTY_I (sbi);struct sit_info *sm =SIT_I (sbi);
@@ -787,6 +793,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, p.alloc_mode = alloc_mode; p.age = age; p.age_threshold = sbi->am.age_threshold; + p.one_time_gc = one_time; retry:select_policy (sbi, gc_type, type, &p);
@@ -1698,13 +1705,14 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, }static int __get_victim (struct f2fs_sb_info *sbi,unsigned int *victim, -int gc_type) +int gc_type,bool one_time) {struct sit_info *sit_i =SIT_I (sbi);int ret;down_write (&sit_i->sentry_lock); - ret =f2fs_get_victim (sbi, victim, gc_type,NO_CHECK_TYPE ,LFS ,0 ); + ret =f2fs_get_victim (sbi, victim, gc_type,NO_CHECK_TYPE , +LFS ,0 , one_time);up_write (&sit_i->sentry_lock);return ret; }
@@ -1911,7 +1919,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) goto stop; } retry: - ret =__get_victim (sbi, &segno, gc_type); + ret =__get_victim (sbi, &segno, gc_type, gc_control->one_time);if (ret) {/* allow to search victim from sections has pinned data */ if (ret == -ENODATA && gc_type == FG_GC &&
fs/f2fs/gc.h +2 -0
@@ -25,6 +25,7 @@#define DEF_GC_THREAD_CANDIDATE_RATIO 20/* select 20% oldest sections as candidates */ #define DEF_GC_THREAD_MAX_CANDIDATE_COUNT 10/* select at most 10 sections as candidates */ #define DEF_GC_THREAD_AGE_WEIGHT 60/* age weight */ +#define DEF_GC_THREAD_VALID_THRESH_RATIO 95/* do not GC over 95% valid block ratio for one time GC */ #define DEFAULT_ACCURACY_CLASS 10000/* accuracy class */ #define LIMIT_INVALID_BLOCK 40/* percentage over total user space */
@@ -65,6 +66,7 @@ struct f2fs_gc_kthread {/* for gc control for zoned devices */ unsigned int no_zoned_gc_percent;unsigned int boost_zoned_gc_percent; +unsigned int valid_thresh_ratio; };struct gc_inode_list {
fs/f2fs/segment.c +4 -2
@@ -3052,7 +3052,8 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,sanity_check_seg_type (sbi, seg_type);/* f2fs_need_SSR() already forces to do this */ -if (!f2fs_get_victim (sbi, &segno,BG_GC , seg_type, alloc_mode, age)) { +if (!f2fs_get_victim (sbi, &segno,BG_GC , seg_type, + alloc_mode, age, false)) { curseg->next_segno = segno;return 1 ; }
@@ -3079,7 +3080,8 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,for (; cnt-- >0 ; reversed ? i-- : i++) {if (i == seg_type)continue ; -if (!f2fs_get_victim (sbi, &segno,BG_GC , i, alloc_mode, age)) { +if (!f2fs_get_victim (sbi, &segno,BG_GC , i, + alloc_mode, age, false)) { curseg->next_segno = segno;return 1 ; }
fs/f2fs/segment.h +1 -0
@@ -188,6 +188,7 @@ struct victim_sel_policy {unsigned int min_segno;/* segment # having min. cost */ unsigned long long age;/* mtime of GCed section*/ unsigned long long age_threshold;/* age threshold */ +bool one_time_gc;/* one time GC */ };struct seg_entry {
fs/f2fs/sysfs.c +2 -0
@@ -967,6 +967,7 @@ GC_THREAD_RW_ATTR(gc_max_sleep_time, max_sleep_time);GC_THREAD_RW_ATTR (gc_no_gc_sleep_time, no_gc_sleep_time);GC_THREAD_RW_ATTR (gc_no_zoned_gc_percent, no_zoned_gc_percent);GC_THREAD_RW_ATTR (gc_boost_zoned_gc_percent, boost_zoned_gc_percent); +GC_THREAD_RW_ATTR (gc_valid_thresh_ratio, valid_thresh_ratio);/* SM_INFO ATTR */ SM_INFO_RW_ATTR (reclaim_segments, rec_prefree_segments);
@@ -1127,6 +1128,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (gc_no_gc_sleep_time),ATTR_LIST (gc_no_zoned_gc_percent),ATTR_LIST (gc_boost_zoned_gc_percent), +ATTR_LIST (gc_valid_thresh_ratio),ATTR_LIST (gc_idle),ATTR_LIST (gc_urgent), ATTR_LIST(reclaim_segments),
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Re: [f2fs-dev] [PATCH v2 7/7] f2fs: add valid block ratio not to do excessive GC for one time GC
Quoted 8 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
We need to introduce a valid block ratio threshold not to trigger excessive GC for zoned deivces. The initial value of it is 95%. So, F2FS will stop the thread from intiating GC for sections having valid blocks exceeding the ratio.
Signed-off-by Daeho Jeong <[email protected]>
Thanks,
Quoted 6 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that.
Signed-off-by Daeho Jeong <[email protected]>
Daeho,
What about collecting all last reviewed-by tags for each patch of this patchset? if there is no change when version updates.
Thanks,
Quoted 7 lines · Chao Yu
Quoted 5 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that.
Quoted 6 lines
Quoted 1 line
Signed-off-by Daeho Jeong <[email protected]>Daeho,
What about collecting all last reviewed-by tags for each patch of this patchset? if there is no change when version updates.
Oh, got it. Thanks~!
Quoted 4 lines
Reviewed-by Chao Yu <[email protected]>Thanks,
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 8 lines · On Mon, 9 Sep 2024 15:19:40 -0700 you wrote:
From: Daeho Jeong <[email protected]>
Since we don't have any GC on device side for zoned devices, need more aggressive BG GC. So, tune the parameters for that.
Signed-off-by Daeho Jeong <[email protected]>[...]
Here is the summary with links:
- [f2fs-dev,v2,1/7] f2fs: make BG GC more aggressive for zoned devices
https://git.kernel.org/jaegeuk/f2fs/c/5062b5bed432 - [f2fs-dev,v2,2/7] f2fs: introduce migration_window_granularity (no matching commit) - [f2fs-dev,v2,3/7] f2fs: add reserved_segments sysfs node https://git.kernel.org/jaegeuk/f2fs/c/4cdca5a904b1 - [f2fs-dev,v2,4/7] f2fs: increase BG GC migration window granularity when boosted for zoned devices https://git.kernel.org/jaegeuk/f2fs/c/2223fe652f75 - [f2fs-dev,v2,5/7] f2fs: do FG_GC when GC boosting is required for zoned devices https://git.kernel.org/jaegeuk/f2fs/c/9748c2ddea4a - [f2fs-dev,v2,6/7] f2fs: create gc_no_zoned_gc_percent and gc_boost_zoned_gc_percent https://git.kernel.org/jaegeuk/f2fs/c/9a481a1c16f4 - [f2fs-dev,v2,7/7] f2fs: add valid block ratio not to do excessive GC for one time GC https://git.kernel.org/jaegeuk/f2fs/c/e791d00bd06c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html