f2fs: introduce __is_large_section() for cleanup
PATCH 1/3 f2fs: introduce __is_large_section() for cleanup
Introduce a wrapper __is_large_section() to clean up codes.
--- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 2 +- fs/f2fs/gc.c | 4 ++-- fs/f2fs/segment.c | 16 ++++++++-------- fs/f2fs/segment.h | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-)
fs/f2fs/debug.c +1 -1
@@ -197,7 +197,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=2 *SIT_VBLOCK_MAP_SIZE *MAIN_SEGS (sbi); si->base_mem +=SIT_VBLOCK_MAP_SIZE *MAIN_SEGS (sbi); si->base_mem +=SIT_VBLOCK_MAP_SIZE ; -if (sbi->segs_per_sec >1 ) +if (__is_large_section (sbi)) si->base_mem +=MAIN_SECS (sbi) *sizeof (struct sec_entry ); si->base_mem +=__bitmap_size (sbi,SIT_BITMAP );
fs/f2fs/f2fs.h +2 -0
@@ -2767,6 +2767,8 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,spin_unlock (&sbi->iostat_lock); } +#define __is_large_section (sbi) ((sbi)->segs_per_sec > 1) +#define __is_meta_io (fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \ (!is_read_io(fio->op) || fio->is_meta))
fs/f2fs/file.c +1 -1
@@ -2560,7 +2560,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)return -EFAULT ;if (sbi->s_ndevs <=1 || sbi->s_ndevs -1 <= range.dev_num || - sbi->segs_per_sec !=1 ) { +__is_large_section (sbi)) { f2fs_msg(sbi->sb, KERN_WARNING, "Can't flush %u in %d for segs_per_sec %u != 1\n", range.dev_num, sbi->s_ndevs,
fs/f2fs/gc.c +2 -2
@@ -1099,7 +1099,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,int submitted =0 ;/* readahead multi ssa blocks those have contiguous address */ -if (sbi->segs_per_sec >1 ) +if (__is_large_section (sbi))f2fs_ra_meta_pages (sbi,GET_SUM_BLOCK (sbi, segno), sbi->segs_per_sec,META_SSA , true);
@@ -1307,7 +1307,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) sbi->gc_pin_file_threshold =DEF_GC_FAILED_PINNED_FILES ;/* give warm/cold data area from slower device */ -if (sbi->s_ndevs && sbi->segs_per_sec ==1 ) +if (sbi->s_ndevs && !__is_large_section (sbi))SIT_I (sbi)->last_victim[ALLOC_NEXT ] =GET_SEGNO (sbi,FDEV (0 ).end_blk) +1 ; }
fs/f2fs/segment.c +8 -8
@@ -1884,7 +1884,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,unsigned int start =0 , end =-1 ;unsigned int secno, start_segno;bool force = (cpc->reason &CP_DISCARD ); -bool need_align =test_opt (sbi,LFS ) && sbi->segs_per_sec >1 ; +bool need_align =test_opt (sbi,LFS ) &&__is_large_section (sbi);mutex_lock (&dirty_i->seglist_lock);
@@ -1916,7 +1916,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, (end - 1) <= cpc->trim_end)continue ; -if (!test_opt (sbi,LFS ) || sbi->segs_per_sec ==1 ) { +if (!test_opt (sbi,LFS ) || !__is_large_section (sbi)) {f2fs_issue_discard (sbi,START_BLOCK (sbi, start), (end - start) << sbi->log_blocks_per_seg);continue ;
@@ -2148,7 +2148,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)/* update total number of valid blocks to be written in ckpt area */ SIT_I (sbi)->written_valid_blocks += del; -if (sbi->segs_per_sec >1 ) +if (__is_large_section (sbi))get_sec_entry (sbi, segno)->valid_blocks += del; }
@@ -2414,7 +2414,7 @@ static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)static unsigned int __get_next_segno (struct f2fs_sb_info *sbi,int type) {/* if segs_per_sec is large than 1, we need to keep original policy. */ -if (sbi->segs_per_sec !=1 ) +if (__is_large_section (sbi))return CURSEG_I (sbi, type)->segno;if (unlikely (is_sbi_flag_set (sbi,SBI_CP_DISABLED )))
@@ -2724,7 +2724,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)struct discard_policy dpolicy;unsigned long long trimmed =0 ;int err =0 ; -bool need_align =test_opt (sbi,LFS ) && sbi->segs_per_sec >1 ; +bool need_align =test_opt (sbi,LFS ) &&__is_large_section (sbi);if (start >=MAX_BLKADDR (sbi) || range->len < sbi->blocksize)return -EINVAL ;
@@ -3885,7 +3885,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)if (!sit_i->tmp_map)return -ENOMEM ; -if (sbi->segs_per_sec >1 ) { +if (__is_large_section (sbi)) { sit_i->sec_entries = f2fs_kvzalloc(sbi, array_size(sizeof(struct sec_entry), MAIN_SECS(sbi)),
@@ -4040,7 +4040,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) se->valid_blocks; } -if (sbi->segs_per_sec >1 ) +if (__is_large_section (sbi))get_sec_entry (sbi, start)->valid_blocks += se->valid_blocks; }
@@ -4084,7 +4084,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) sbi->discard_blks -= se->valid_blocks; } -if (sbi->segs_per_sec >1 ) { +if (__is_large_section (sbi)) {get_sec_entry (sbi, start)->valid_blocks += se->valid_blocks; get_sec_entry(sbi, start)->valid_blocks -=
fs/f2fs/segment.h +1 -1
@@ -333,7 +333,7 @@ static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,* In order to get # of valid blocks in a section instantly from many * segments, f2fs manages two counting structures separately. */ -if (use_section && sbi->segs_per_sec >1 ) +if (use_section &&__is_large_section (sbi))return get_sec_entry (sbi, segno)->valid_blocks;else return get_seg_entry (sbi, segno)->valid_blocks;
Signature · 1 line
2.18.0.rc1
PATCH 2/3 f2fs: support subsectional garbage collection
Section is minimal garbage collection unit of f2fs, in zoned block device, or ancient block mapping flash device, in order to improve GC efficiency, we can align GC unit to lower device erase unit, normally, it consists of multiple of segments.
Once background or foreground GC triggers, it brings a large number of IOs, which will impact user IO, and also occupy cpu/memory resource intensively.
So, to reduce impact of GC on large size section, this patch supports subsectional GC, in one cycle of GC, it only migrate partial segment{s} in victim section. Currently, by default, we use sbi->segs_per_sec as migration granularity.
--- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/gc.c | 43 ++++++++++++++++++++++++++++++++++++------- fs/f2fs/super.c | 3 +++ 3 files changed, 42 insertions(+), 7 deletions(-)
fs/f2fs/f2fs.h +3 -0
@@ -1266,6 +1266,7 @@ struct f2fs_sb_info {struct f2fs_gc_kthread *gc_thread;/* GC thread */ unsigned int cur_victim_sec;/* current victim section num */ unsigned int gc_mode;/* current GC state */ +unsigned int next_victim_seg[2 ];/* next segment in victim section */ /* for skip statistic */ unsigned long long skipped_atomic_files[2 ];/* FG_GC and BG_GC */ unsigned long long skipped_gc_rwsem;/* FG_GC only */
@@ -1275,6 +1276,8 @@ struct f2fs_sb_info {/* maximum # of trials to find a victim segment for SSR and GC */ unsigned int max_victim_search; +/* migration granularity of garbage collection, unit: segment */ +unsigned int migration_granularity;/* * for stat information.
fs/f2fs/gc.c +36 -7
95 lines not on this page · raw message
fs/f2fs/super.c +3 -0
@@ -2692,7 +2692,10 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->node_ino_num =le32_to_cpu (raw_super->node_ino); sbi->meta_ino_num =le32_to_cpu (raw_super->meta_ino); sbi->cur_victim_sec =NULL_SECNO ; + 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 = sbi->segs_per_sec; sbi->dir_level =DEF_DIR_LEVEL ; sbi->interval_time[CP_TIME ] =DEF_CP_INTERVAL ;
Signature · 1 line
2.18.0.rc1
PATCH 3/3 f2fs: export migration_granularity sysfs entry
In reply to Chao YuAdd one sysfs entry to control migration granularity of GC in large section f2fs, it can be tuned to mitigate heavy overhead of migrating huge number of blocks in large section.
--- Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++ fs/f2fs/sysfs.c | 7 +++++++ 2 files changed, 16 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +9 -0
@@ -92,6 +92,15 @@ Contact: "Jaegeuk Kim" <[email protected]> Description: Controls the number of trials to find a victim segment. +What: /sys/fs/f2fs/<disk>/migration_granularity +Date: October 2018 +Contact: "Chao Yu" <[email protected]> +Description: + Controls migration granularity of garbage collection on large + section, it can let GC move partial segment{s} of one section + in one GC cycle, so that dispersing heavy overhead GC to + multiple lightweight one. + What: /sys/fs/f2fs/<disk>/dir_level Date: March 2014 Contact: "Jaegeuk Kim" <[email protected]>
fs/f2fs/sysfs.c +7 -0
@@ -246,6 +246,11 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; } +if (!strcmp (a->attr.name,"discard_granularity" )) { +if (t ==0 || t > sbi->segs_per_sec) +return -EINVAL ; + } +if (!strcmp (a->attr.name,"trim_sections" ))return -EINVAL ;
@@ -406,6 +411,7 @@ F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, ra_nid_pages, ra_nid_pages);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, max_victim_search, max_victim_search); +F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, migration_granularity, migration_granularity);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, dir_level, dir_level);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, cp_interval, interval_time[CP_TIME ]);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, idle_interval, interval_time[REQ_TIME ]);
@@ -460,6 +466,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (min_hot_blocks),ATTR_LIST (min_ssr_sections),ATTR_LIST (max_victim_search), +ATTR_LIST (migration_granularity),ATTR_LIST (dir_level),ATTR_LIST (ram_thresh), ATTR_LIST(ra_nid_pages),
Signature · 1 line
2.18.0.rc1
Re: [PATCH 3/3] f2fs: export migration_granularity sysfs entry
Quoted 35 lines · Chao Yu
Add one sysfs entry to control migration granularity of GC in large section f2fs, it can be tuned to mitigate heavy overhead of migrating huge number of blocks in large section.
Signed-off-by Chao Yu <[email protected]>--- Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++ fs/f2fs/sysfs.c | 7 +++++++ 2 files changed, 16 insertions(+)Documentation/ABI/testing/sysfs-fs-f2fs +9
-0@@ -92,6 +92,15 @@ Contact: "Jaegeuk Kim" <[email protected]> Description: Controls the number of trials to find a victim segment. +What: /sys/fs/f2fs/<disk>/migration_granularity +Date: October 2018 +Contact: "Chao Yu" <[email protected]> +Description: + Controls migration granularity of garbage collection on large + section, it can let GC move partial segment{s} of one section + in one GC cycle, so that dispersing heavy overhead GC to + multiple lightweight one. + What: /sys/fs/f2fs/<disk>/dir_level Date: March 2014 Contact: "Jaegeuk Kim" <[email protected]>fs/f2fs/sysfs.c +0
-0
fs/f2fs/sysfs.c static ssize_t __sbi_store(struct f2fs_attr *a, · line 249
Quoted 4 lines
fs/f2fs/sysfs.c +1
-0@@ -246,6 +246,11 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; } +if (!strcmp (a->attr.name,"discard_granularity" )) {
Should be migration_granularity ?
Quoted 23 lines
fs/f2fs/sysfs.c +6
-0+if (t ==0 || t > sbi->segs_per_sec) +return -EINVAL ; + } +if (!strcmp (a->attr.name,"trim_sections" ))return -EINVAL ;@@ -406,6 +411,7 @@ F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, ra_nid_pages, ra_nid_pages);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, max_victim_search, max_victim_search); +F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, migration_granularity, migration_granularity);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, dir_level, dir_level);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, cp_interval, interval_time[CP_TIME ]);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, idle_interval, interval_time[REQ_TIME ]);@@ -460,6 +466,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (min_hot_blocks),ATTR_LIST (min_ssr_sections),ATTR_LIST (max_victim_search), +ATTR_LIST (migration_granularity),ATTR_LIST (dir_level),ATTR_LIST (ram_thresh), ATTR_LIST(ra_nid_pages),
Signature · 2 lines
Thanks, Yunlong Song
Re: [PATCH 3/3] f2fs: export migration_granularity sysfs entry
Quoted 41 lines · Yunlong Song
Quoted 38 lines · Chao Yu
Add one sysfs entry to control migration granularity of GC in large section f2fs, it can be tuned to mitigate heavy overhead of migrating huge number of blocks in large section.
Signed-off-by Chao Yu <[email protected]>--- Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++ fs/f2fs/sysfs.c | 7 +++++++ 2 files changed, 16 insertions(+)Documentation/ABI/testing/sysfs-fs-f2fs +9
-0@@ -92,6 +92,15 @@ Contact: "Jaegeuk Kim" <[email protected]> Description: Controls the number of trials to find a victim segment. +What: /sys/fs/f2fs/<disk>/migration_granularity +Date: October 2018 +Contact: "Chao Yu" <[email protected]> +Description: + Controls migration granularity of garbage collection on large + section, it can let GC move partial segment{s} of one section + in one GC cycle, so that dispersing heavy overhead GC to + multiple lightweight one. + What: /sys/fs/f2fs/<disk>/dir_level Date: March 2014 Contact: "Jaegeuk Kim" <[email protected]>fs/f2fs/sysfs.c +0
-0@@ -246,6 +246,11 @@ static ssize_t __sbi_store(struct f2fs_attr *a,return count; }
Quoted 3 lines
fs/f2fs/sysfs.c static ssize_t __sbi_store(struct f2fs_attr *a, · line 249
Quoted 1 line
fs/f2fs/sysfs.c +1
-0+if (!strcmp (a->attr.name,"discard_granularity" )) {Should be
migration_granularity?
Oh, let me fix this in v2.
Thanks,
Quoted 25 lines
Quoted 24 lines
fs/f2fs/sysfs.c +6
-0+if (t ==0 || t > sbi->segs_per_sec) +return -EINVAL ; + } +if (!strcmp (a->attr.name,"trim_sections" ))return -EINVAL ;@@ -406,6 +411,7 @@ F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, ra_nid_pages, ra_nid_pages);F2FS_RW_ATTR (NM_INFO , f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, max_victim_search, max_victim_search); +F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, migration_granularity, migration_granularity);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, dir_level, dir_level);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, cp_interval, interval_time[CP_TIME ]);F2FS_RW_ATTR (F2FS_SBI , f2fs_sb_info, idle_interval, interval_time[REQ_TIME ]);@@ -460,6 +466,7 @@ static struct attribute *f2fs_attrs[] = {ATTR_LIST (min_hot_blocks),ATTR_LIST (min_ssr_sections),ATTR_LIST (max_victim_search), +ATTR_LIST (migration_granularity),ATTR_LIST (dir_level),ATTR_LIST (ram_thresh), ATTR_LIST(ra_nid_pages),