f2fs: enforce single zone capacity
Jaegeuk Kim
maintainerPATCH 1/3 f2fs: enforce single zone capacity
In order to simplify the complicated per-zone capacity, let's support only one capacity for entire zoned device.
--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/segment.c | 19 ++++++------------- fs/f2fs/segment.h | 3 +++ fs/f2fs/super.c | 33 ++++++++++++--------------------- 4 files changed, 22 insertions(+), 35 deletions(-)
fs/f2fs/f2fs.h +1 -1
@@ -1235,7 +1235,6 @@ struct f2fs_dev_info {#ifdef CONFIG_BLK_DEV_ZONED unsigned int nr_blkz;/* Total number of zones */ unsigned long *blkz_seq;/* Bitmap indicating sequential zones */ -block_t *zone_capacity_blocks;/* Array of zone capacity in blks */ #endif };
@@ -1673,6 +1672,7 @@ struct f2fs_sb_info {unsigned int meta_ino_num;/* meta inode number*/ unsigned int log_blocks_per_seg;/* log2 blocks per segment */ unsigned int blocks_per_seg;/* blocks per segment */ +unsigned int unusable_blocks_per_sec;/* unusable blocks per section */ unsigned int segs_per_sec;/* segments per section */ unsigned int secs_per_zone;/* sections per zone */ unsigned int total_sections;/* total section count */
fs/f2fs/segment.c +6 -13
@@ -4895,7 +4895,7 @@ static unsigned int get_zone_idx(struct f2fs_sb_info *sbi, unsigned int secno,static inline unsigned int f2fs_usable_zone_segs_in_sec (struct f2fs_sb_info *sbi,unsigned int segno) { -unsigned int dev_idx, zone_idx, unusable_segs_in_sec; +unsigned int dev_idx, zone_idx; dev_idx =f2fs_target_device_index (sbi,START_BLOCK (sbi, segno)); zone_idx =get_zone_idx (sbi,GET_SEC_FROM_SEG (sbi, segno), dev_idx);
@@ -4904,18 +4904,12 @@ static inline unsigned int f2fs_usable_zone_segs_in_sec(if (is_conv_zone (sbi, zone_idx, dev_idx))return sbi->segs_per_sec; -/* -* If the zone_capacity_blocks array is NULL, then zone capacity -* is equal to the zone size for all zones -*/ -if (!FDEV (dev_idx).zone_capacity_blocks) +if (!sbi->unusable_blocks_per_sec)return sbi->segs_per_sec;/* Get the segment count beyond zone capacity block */ - unusable_segs_in_sec = (sbi->blocks_per_blkz - -FDEV (dev_idx).zone_capacity_blocks[zone_idx]) >> - sbi->log_blocks_per_seg; -return sbi->segs_per_sec - unusable_segs_in_sec; +return sbi->segs_per_sec - (sbi->unusable_blocks_per_sec >> + sbi->log_blocks_per_seg); }/*
@@ -4944,12 +4938,11 @@ static inline unsigned int f2fs_usable_zone_blks_in_seg(if (is_conv_zone (sbi, zone_idx, dev_idx))return sbi->blocks_per_seg; -if (!FDEV (dev_idx).zone_capacity_blocks) +if (!sbi->unusable_blocks_per_sec)return sbi->blocks_per_seg; sec_start_blkaddr =START_BLOCK (sbi,GET_SEG_FROM_SEC (sbi, secno)); - sec_cap_blkaddr = sec_start_blkaddr + -FDEV (dev_idx).zone_capacity_blocks[zone_idx]; + sec_cap_blkaddr = sec_start_blkaddr +CAP_BLKS_PER_SEC (sbi);/* * If segment starts before zone capacity and spans beyond
fs/f2fs/segment.h +3 -0
@@ -101,6 +101,9 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi, GET_SEGNO_FROM_SEG0(sbi, blk_addr)))#define BLKS_PER_SEC (sbi) \ ((sbi)->segs_per_sec * (sbi)->blocks_per_seg) +#define CAP_BLKS_PER_SEC (sbi) \ + ((sbi)->segs_per_sec * (sbi)->blocks_per_seg - \ + (sbi)->unusable_blocks_per_sec)#define GET_SEC_FROM_SEG (sbi, segno) \ (((segno) == -1) ? -1: (segno) / (sbi)->segs_per_sec)#define GET_SEG_FROM_SEC (sbi, secno) \
fs/f2fs/super.c +12 -21
@@ -1522,7 +1522,6 @@ static void destroy_device_list(struct f2fs_sb_info *sbi)blkdev_put (FDEV (i).bdev,FMODE_EXCL );#ifdef CONFIG_BLK_DEV_ZONED kvfree (FDEV (i).blkz_seq); -kfree (FDEV (i).zone_capacity_blocks);#endif }kvfree (sbi->devs);
@@ -3673,24 +3672,29 @@ static int init_percpu_info(struct f2fs_sb_info *sbi)#ifdef CONFIG_BLK_DEV_ZONED struct f2fs_report_zones_args { +struct f2fs_sb_info *sbi;struct f2fs_dev_info *dev; -bool zone_cap_mismatch; };static int f2fs_report_zone_cb (struct blk_zone *zone,unsigned int idx,void *data) {struct f2fs_report_zones_args *rz_args = data; +block_t unusable_blocks = (zone->len - zone->capacity) >> +F2FS_LOG_SECTORS_PER_BLOCK ;if (zone->type ==BLK_ZONE_TYPE_CONVENTIONAL )return 0 ;set_bit (idx, rz_args->dev->blkz_seq); - rz_args->dev->zone_capacity_blocks[idx] = zone->capacity >> -F2FS_LOG_SECTORS_PER_BLOCK ; -if (zone->len != zone->capacity && !rz_args->zone_cap_mismatch) - rz_args->zone_cap_mismatch = true; - +if (!rz_args->sbi->unusable_blocks_per_sec) { + rz_args->sbi->unusable_blocks_per_sec = unusable_blocks; +return 0 ; + } +if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) { +f2fs_err (rz_args->sbi,"F2FS supports single zone capacity\n" ); +return -EINVAL ; + }return 0 ; }
@@ -3731,26 +3735,13 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)if (!FDEV (devi).blkz_seq)return -ENOMEM ; -/* Get block zones type and zone-capacity */ -FDEV (devi).zone_capacity_blocks =f2fs_kzalloc (sbi, -FDEV (devi).nr_blkz *sizeof (block_t), -GFP_KERNEL ); -if (!FDEV (devi).zone_capacity_blocks) -return -ENOMEM ; - + rep_zone_arg.sbi = sbi; rep_zone_arg.dev = &FDEV (devi); - rep_zone_arg.zone_cap_mismatch = false; ret =blkdev_report_zones (bdev,0 ,BLK_ALL_ZONES , f2fs_report_zone_cb, &rep_zone_arg);if (ret <0 )return ret; - -if (!rep_zone_arg.zone_cap_mismatch) { -kfree (FDEV (devi).zone_capacity_blocks); -FDEV (devi).zone_capacity_blocks =NULL ; - } - return 0; }#endif
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Jaegeuk Kim
maintainerPATCH 2/3 f2fs: adjust zone capacity when considering valid block count
This patch fixes counting unusable blocks set by zone capacity when checking the valid block count in a section.
--- fs/f2fs/debug.c | 2 +- fs/f2fs/file.c | 6 +++--- fs/f2fs/gc.c | 4 ++-- fs/f2fs/segment.c | 7 +++---- fs/f2fs/segment.h | 8 ++++---- 5 files changed, 13 insertions(+), 14 deletions(-)
fs/f2fs/debug.c +1 -1
@@ -39,7 +39,7 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi) bimodal =0 ; total_vblocks =0 ; - blks_per_sec =BLKS_PER_SEC (sbi); + blks_per_sec =CAP_BLKS_PER_SEC (sbi); hblks_per_sec = blks_per_sec /2 ;for (segno =0 ; segno <MAIN_SEGS (sbi); segno += sbi->segs_per_sec) { vblocks =get_valid_blocks (sbi, segno, true);
fs/f2fs/file.c +3 -3
@@ -1681,7 +1681,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,return 0 ;if (f2fs_is_pinned_file (inode)) { -block_t sec_blks =BLKS_PER_SEC (sbi); +block_t sec_blks =CAP_BLKS_PER_SEC (sbi);block_t sec_len =roundup (map.m_len, sec_blks); map.m_len = sec_blks;
@@ -2432,7 +2432,7 @@ static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range) ret = -EAGAIN ; goto out; } - range->start +=BLKS_PER_SEC (sbi); + range->start +=CAP_BLKS_PER_SEC (sbi);if (range->start <= end) goto do_more; out:
@@ -2557,7 +2557,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, goto out; } - sec_num =DIV_ROUND_UP (total,BLKS_PER_SEC (sbi)); + sec_num =DIV_ROUND_UP (total,CAP_BLKS_PER_SEC (sbi));/* * make sure there are enough free section for LFS allocation, this can
fs/f2fs/gc.c +2 -2
@@ -487,7 +487,7 @@ static void atgc_lookup_victim(struct f2fs_sb_info *sbi,unsigned long long age, u, accu;unsigned long long max_mtime = sit_i->dirty_max_mtime;unsigned long long min_mtime = sit_i->dirty_min_mtime; -unsigned int sec_blocks =BLKS_PER_SEC (sbi); +unsigned int sec_blocks =CAP_BLKS_PER_SEC (sbi);unsigned int vblocks; unsigned int dirty_threshold = max(am->max_candidate_count, am->candidate_ratio *
@@ -1487,7 +1487,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,*/ if ((gc_type ==BG_GC &&has_not_enough_free_secs (sbi,0 ,0 )) || (!force_migrate &&get_valid_blocks (sbi, segno, true) == -BLKS_PER_SEC (sbi))) +CAP_BLKS_PER_SEC (sbi)))return submitted;if (check_valid_map (sbi, segno, off) ==0 )
fs/f2fs/segment.c +3 -4
@@ -728,7 +728,7 @@ static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,get_valid_blocks (sbi, segno, true);f2fs_bug_on (sbi,unlikely (!valid_blocks || - valid_blocks ==BLKS_PER_SEC (sbi))); + valid_blocks ==CAP_BLKS_PER_SEC (sbi)));if (!IS_CURSEC (sbi, secno))set_bit (secno, dirty_i->dirty_secmap);
@@ -764,7 +764,7 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,unsigned int secno =GET_SEC_FROM_SEG (sbi, segno);if (!valid_blocks || - valid_blocks ==BLKS_PER_SEC (sbi)) { + valid_blocks ==CAP_BLKS_PER_SEC (sbi)) {clear_bit (secno, dirty_i->dirty_secmap);return ; }
@@ -4483,7 +4483,6 @@ static void init_dirty_segmap(struct f2fs_sb_info *sbi)struct free_segmap_info *free_i =FREE_I (sbi);unsigned int segno =0 , offset =0 , secno;block_t valid_blocks, usable_blks_in_seg; -block_t blks_per_sec =BLKS_PER_SEC (sbi);while (1 ) {/* find dirty segment based on free segmap */
@@ -4512,7 +4511,7 @@ static void init_dirty_segmap(struct f2fs_sb_info *sbi) valid_blocks =get_valid_blocks (sbi, segno, true); secno =GET_SEC_FROM_SEG (sbi, segno); -if (!valid_blocks || valid_blocks == blks_per_sec) +if (!valid_blocks || valid_blocks ==CAP_BLKS_PER_SEC (sbi))continue ;if (IS_CURSEC (sbi, secno))continue ;
fs/f2fs/segment.h +4 -4
@@ -612,10 +612,10 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,get_pages (sbi,F2FS_DIRTY_DENTS ) +get_pages (sbi,F2FS_DIRTY_IMETA );unsigned int total_dent_blocks =get_pages (sbi,F2FS_DIRTY_DENTS ); -unsigned int node_secs = total_node_blocks /BLKS_PER_SEC (sbi); -unsigned int dent_secs = total_dent_blocks /BLKS_PER_SEC (sbi); -unsigned int node_blocks = total_node_blocks %BLKS_PER_SEC (sbi); -unsigned int dent_blocks = total_dent_blocks %BLKS_PER_SEC (sbi); +unsigned int node_secs = total_node_blocks /CAP_BLKS_PER_SEC (sbi); +unsigned int dent_secs = total_dent_blocks /CAP_BLKS_PER_SEC (sbi); +unsigned int node_blocks = total_node_blocks %CAP_BLKS_PER_SEC (sbi); +unsigned int dent_blocks = total_dent_blocks %CAP_BLKS_PER_SEC (sbi);unsigned int free, need_lower, need_upper;if (unlikely (is_sbi_flag_set (sbi,SBI_POR_DOING )))
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Re: [f2fs-dev] [PATCH 2/3] f2fs: adjust zone capacity when considering valid block count
Quoted 2 lines · Jaegeuk Kim
This patch fixes counting unusable blocks set by zone capacity when checking the valid block count in a section.
Good catch!
Quoted 2 lines
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Jaegeuk Kim
maintainerPATCH 3/3 f2fs: add a sysfs entry to show zone capacity
In reply to Jaegeuk KimThis patch adds a sysfs entry showing the unusable space in a section made by zone capacity.
--- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++ fs/f2fs/sysfs.c | 10 ++++++++++ 2 files changed, 16 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
@@ -580,3 +580,9 @@ Date: January 2022 Contact: "Jaegeuk Kim" <[email protected]> Description: Controls max # of node block writes to be used for roll forward recovery. This can limit the roll forward recovery time. + +What: /sys/fs/f2fs/<disk>/unusable_blocks_per_sec +Date: June 2022 +Contact: "Jaegeuk Kim" <[email protected]> +Description: Shows the number of unusable blocks in a section which was defined by + the zone capacity reported by underlying zoned device.
fs/f2fs/sysfs.c +10 -0
@@ -713,6 +713,11 @@ static struct f2fs_attr f2fs_attr_##_name = { \ .offset = _offset \ } +#define F2FS_RO_ATTR (struct_type, struct_name, name, elname) \ + F2FS_ATTR_OFFSET(struct_type, name, 0444, \ + f2fs_sbi_show, NULL, \ + offsetof(struct struct_name, elname)) +#define F2FS_RW_ATTR (struct_type, struct_name, name, elname) \ F2FS_ATTR_OFFSET(struct_type, name, 0644, \ f2fs_sbi_show, f2fs_sbi_store, \
@@ -811,6 +816,8 @@ F2FS_FEATURE_RO_ATTR(encrypted_casefold);#endif /* CONFIG_FS_ENCRYPTION */ #ifdef CONFIG_BLK_DEV_ZONED F2FS_FEATURE_RO_ATTR (block_zoned); +F2FS_RO_ATTR (F2FS_SBI , f2fs_sb_info, unusable_blocks_per_sec, + unusable_blocks_per_sec);#endif F2FS_FEATURE_RO_ATTR (atomic_write);F2FS_FEATURE_RO_ATTR (extra_attr);
@@ -919,6 +926,9 @@ static struct attribute *f2fs_attrs[] = { ATTR_LIST(moved_blocks_background), ATTR_LIST(avg_vblocks),#endif +#ifdef CONFIG_BLK_DEV_ZONED + ATTR_LIST(unusable_blocks_per_sec), +#endif #ifdef CONFIG_F2FS_FS_COMPRESSION ATTR_LIST (compr_written_block), ATTR_LIST(compr_saved_block),
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Re: [f2fs-dev] [PATCH 3/3] f2fs: add a sysfs entry to show zone capacity
Quoted 4 lines · Jaegeuk Kim
This patch adds a sysfs entry showing the unusable space in a section made by zone capacity.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,
Quoted 4 lines · Jaegeuk Kim
In order to simplify the complicated per-zone capacity, let's support only one capacity for entire zoned device.
Signed-off-by Jaegeuk Kim <[email protected]>
Thanks,