f2fs-tools: give less overprovisioning space
PATCH 1/3 f2fs-tools: give less overprovisioning space
As f2fs becomes more resilient for GCs, let's give the marginal overprovision space back to user.
--- fsck/resize.c | 8 ++++---- include/f2fs_fs.h | 6 ++++-- mkfs/f2fs_format.c | 9 ++++++--- 3 files changed, 14 insertions(+), 9 deletions(-)
fsck/resize.c +4 -4
@@ -150,7 +150,7 @@ safe_resize: c.new_overprovision =get_best_overprovision (sb); c.new_reserved_segments = - (2 * (100 / c.new_overprovision +1 ) +6 ) * + (100 / c.new_overprovision +1 +NR_CURSEG_TYPE ) *get_sb (segs_per_sec); if ((get_sb(segment_count_main) - 2) < c.new_reserved_segments ||
@@ -475,8 +475,9 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,set_cp (overprov_segment_count, (get_newsb (segment_count_main) -get_cp (rsvd_segment_count)) * c.new_overprovision /100 ); -set_cp (overprov_segment_count,get_cp (overprov_segment_count) + -get_cp (rsvd_segment_count)); + +if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) +ASSERT_MSG ("Cannot support wrong overprovision ratio\n" );DBG (0 ,"Info: Overprovision ratio = %.3lf%%\n" , c.new_overprovision); DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
@@ -607,7 +608,6 @@ static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block * overprov_segment_count = (get_newsb (segment_count_main) - c.new_reserved_segments) * c.new_overprovision /100 ; - overprov_segment_count += c.new_reserved_segments; user_block_count = (get_newsb (segment_count_main) - overprov_segment_count) * c.blks_per_seg;
include/f2fs_fs.h +4 -2
@@ -1631,10 +1631,12 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb) }for (; candidate <= end; candidate += diff) { - reserved = (2 * (100 / candidate +1 ) +6 ) * + reserved = (100 / candidate +1 +NR_CURSEG_TYPE ) *round_up (usable_main_segs,get_sb (section_count)); ovp = (usable_main_segs - reserved) * candidate /100 ; - space = usable_main_segs - reserved - ovp; +if (reserved >= ovp) +continue ; + space = usable_main_segs - ovp;if (max_space < space) { max_space = space; max_ovp = candidate;
mkfs/f2fs_format.c +6 -3
@@ -484,7 +484,7 @@ static int f2fs_prepare_super_block(void) c.overprovision =get_best_overprovision (sb); c.reserved_segments = - (2 * (100 / c.overprovision +1 ) +NR_CURSEG_TYPE ) * + (100 / c.overprovision +1 +NR_CURSEG_TYPE ) *round_up (f2fs_get_usable_segments (sb),get_sb (section_count));if (c.feature &cpu_to_le32 (F2FS_FEATURE_RO )) {
@@ -764,8 +764,11 @@ static int f2fs_write_check_point_pack(void)set_cp (overprov_segment_count, (f2fs_get_usable_segments (sb) -get_cp (rsvd_segment_count)) * c.overprovision /100 ); -set_cp (overprov_segment_count,get_cp (overprov_segment_count) + -get_cp (rsvd_segment_count)); + +if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) { +MSG (0 ,"\tError: Wrong overprovision ratio\n" ); + goto free_cp_payload; + }if (f2fs_get_usable_segments (sb) <=get_cp (overprov_segment_count)) {MSG (0 ,"\tError: Not enough segments to create F2FS Volume\n" );
Signature · 8 lines
2.38.0.rc1.362.ged0d419d3c-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 2/3 fsck.f2fs: fix missing to assign c.zoned_model
We need to set the c.zoned_model appropriately for further usages.
--- fsck/mount.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fsck/mount.c +8 -0
@@ -1095,6 +1095,14 @@ int init_sb_info(struct f2fs_sb_info *sbi)if (i ==0 ) c.devices[i].end_blkaddr +=get_sb (segment0_blkaddr); +if (c.zoned_model ==F2FS_ZONED_NONE ) { +if (c.devices[i].zoned_model ==F2FS_ZONED_HM ) + c.zoned_model =F2FS_ZONED_HM ; +else if (c.devices[i].zoned_model ==F2FS_ZONED_HA && + c.zoned_model !=F2FS_ZONED_HM ) + c.zoned_model =F2FS_ZONED_HA ; + } + c.ndevs = i +1 ; MSG(0, "Info: Device[%d] : %s blkaddr = %"PRIx64"--%"PRIx64"\n", i, c.devices[i].path,
Signature · 8 lines
2.38.0.rc1.362.ged0d419d3c-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/3 f2fs-tools: set host-aware zoned device similar to host-managed one
In reply to Jaegeuk KimIt'd be good to generate zone-aware sequential writes to both of HA and HM zoned devices.
--- fsck/mount.c | 2 +- mkfs/f2fs_format.c | 2 +- mkfs/f2fs_format_main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fsck/mount.c +1 -1
@@ -987,7 +987,7 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr) }/* Check zoned block device feature */ -if (c.devices[0 ].zoned_model ==F2FS_ZONED_HM && +if (c.devices[0 ].zoned_model !=F2FS_ZONED_NONE && !(sb->feature &cpu_to_le32 (F2FS_FEATURE_BLKZONED ))) {MSG (0 ,"\tMissing zoned block device feature\n" );return -1 ;
mkfs/f2fs_format.c +1 -1
@@ -454,7 +454,7 @@ static int f2fs_prepare_super_block(void)* not overlap to metadata area. */ for (i =1 ; i < c.ndevs; i++) { -if (c.devices[i].zoned_model ==F2FS_ZONED_HM && +if (c.devices[i].zoned_model !=F2FS_ZONED_NONE && c.devices[i].start_blkaddr <get_sb (main_blkaddr)) { MSG(0, "\tError: Conventional device %s is too small," " (%"PRIu64" MiB needed).\n", c.devices[0].path,
mkfs/f2fs_format_main.c +1 -1
@@ -480,7 +480,7 @@ int main(int argc, char *argv[])* Some options are mandatory for host-managed * zoned block devices. */ -if (c.zoned_model ==F2FS_ZONED_HM && !c.zoned_mode) { +if (c.zoned_model !=F2FS_ZONED_NONE && !c.zoned_mode) {MSG (0 ,"\tError: zoned block device feature is required\n" ); goto err_format; }
Signature · 8 lines
2.38.0.rc1.362.ged0d419d3c-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 4 lines · Jaegeuk Kim
As f2fs becomes more resilient for GCs, let's give the marginal overprovision space back to user.
Signed-off-by Jaegeuk Kim <[email protected]>
Hello Jaegeuk,
Using the dev branch of f2fs-tools repo, I observed mkfs.f2fs failure with zoned block devices:
Error: Device size is not sufficient for F2FS volume
I found this patch in the branch triggers it. I also observed the same failure is observed with non- zoned regular block devices when I specify -s options to mkfs.f2fs command. With these conditions, number of segments in each section is not zero, and it increases the number of reserved segments. My understanding is that it makes reserved segments larger than overprovisioning segments all the time in the loop of get_best_overprovision(). Then get_best_overprovision() returns 0% overprovisioning ratio. Hence the error.
Could you take a look for fix?
FYI, I tried to fix and created a patch which allows reserved segments larger than overprovisioning segments [1]. It compares those two, and take larger one to subtract from usable segments to get the segments for users. I confirmed it keeps small number of overprovisioning segments for no -s option case, and avoids the mkfs.f2fs failure for the -s option and zoned block device cases. However, it increases runtime of my test script which fills f2fs and do file overwrites to test f2fs GC on zoned block devices. It takes +60% longer runtime. Then GC performance looks worse than before, and this fix does not look good for me.
[1]
include/f2fs_fs.h +3 -2
@@ -1634,9 +1634,10 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb) reserved = (100 / candidate +1 +NR_CURSEG_TYPE ) *round_up (usable_main_segs,get_sb (section_count)); ovp = (usable_main_segs - reserved) * candidate /100 ; -if (reserved >= ovp) +if (ovp <0 )continue ; - space = usable_main_segs - ovp; + + space = usable_main_segs -max (reserved, ovp);if (max_space < space) { max_space = space; max_ovp = candidate;
mkfs/f2fs_format.c +2 -5
@@ -764,11 +764,8 @@ static int f2fs_write_check_point_pack(void)set_cp (overprov_segment_count, (f2fs_get_usable_segments (sb) -get_cp (rsvd_segment_count)) * c.overprovision /100 ); - -if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) { -MSG (0 ,"\tError: Wrong overprovision ratio\n" ); - goto free_cp_payload; - } +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count));if (f2fs_get_usable_segments (sb) <=get_cp (overprov_segment_count)) {MSG (0 ,"\tError: Not enough segments to create F2FS Volume\n" );
Signature · 6 lines
Shin'ichiro Kawasaki _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 21 lines · Shinichiro Kawasaki
Quoted 4 lines · Jaegeuk Kim
As f2fs becomes more resilient for GCs, let's give the marginal overprovision space back to user.
Signed-off-by Jaegeuk Kim <[email protected]>Hello Jaegeuk,
Using the dev branch of f2fs-tools repo, I observed mkfs.f2fs failure with zoned block devices:
Error: Device size is not sufficient for F2FS volume
I found this patch in the branch triggers it. I also observed the same failure is observed with non- zoned regular block devices when I specify -s options to mkfs.f2fs command. With these conditions, number of segments in each section is not zero, and it increases the number of reserved segments. My understanding is that it makes reserved segments larger than overprovisioning segments all the time in the loop of
get_best_overprovision(). Thenget_best_overprovision()returns 0% overprovisioning ratio. Hence the error.
Quoted 1 line
Could you take a look for fix?
Thanks, I think that fix looks good to me. I applied into the original patch.
https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev&id=281d3e72370f6c39c0d57acaf37a7f0e003ddd28
Quoted 10 lines
FYI, I tried to fix and created a patch which allows reserved segments larger than overprovisioning segments [1]. It compares those two, and take larger one to subtract from usable segments to get the segments for users. I confirmed it keeps small number of overprovisioning segments for no -s option case, and avoids the mkfs.f2fs failure for the -s option and zoned block device cases. However, it increases runtime of my test script which fills f2fs and do file overwrites to test f2fs GC on zoned block devices. It takes +60% longer runtime. Then GC performance looks worse than before, and this fix does not look good for me.
I think you can try to avoid that by tuning /sys/fs/f2fs/xx/reserved_blocks?
Quoted 41 lines
[1]
include/f2fs_fs.h +3
-2@@ -1634,9 +1634,10 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb) reserved = (100 / candidate +1 +NR_CURSEG_TYPE ) *round_up (usable_main_segs,get_sb (section_count)); ovp = (usable_main_segs - reserved) * candidate /100 ; -if (reserved >= ovp) +if (ovp <0 )continue ; - space = usable_main_segs - ovp; + + space = usable_main_segs -max (reserved, ovp);if (max_space < space) { max_space = space; max_ovp = candidate;mkfs/f2fs_format.c +2
-5@@ -764,11 +764,8 @@ static int f2fs_write_check_point_pack(void)set_cp (overprov_segment_count, (f2fs_get_usable_segments (sb) -get_cp (rsvd_segment_count)) * c.overprovision /100 ); - -if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) { -MSG (0 ,"\tError: Wrong overprovision ratio\n" ); - goto free_cp_payload; - } +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count));if (f2fs_get_usable_segments (sb) <=get_cp (overprov_segment_count)) {MSG (0 ,"\tError: Not enough segments to create F2FS Volume\n" );Signature · 2 lines
-- Shin'ichiro Kawasaki
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
On Oct 20, 2022 / 16:18, Jaegeuk Kim wrote:
...
Quoted 2 lines
Thanks, I think that fix looks good to me. I applied into the original patch.
https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev&id=281d3e72370f6c39c0d57acaf37a7f0e003ddd28
Oh, happy to know that the fix is good. And thank you for adding my SoB tag.
One more thing, my fix missed care for fsck/resize.c. I suggest to apply one more hunk below to the commit in same manner as mkfs/f2fs_format.c.
fsck/resize.c +2 -2
@@ -476,8 +476,8 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, get_cp(rsvd_segment_count)) * c.new_overprovision / 100); -if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) -ASSERT_MSG ("Cannot support wrong overprovision ratio\n" ); +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count));DBG (0 ,"Info: Overprovision ratio = %.3lf%%\n" , c.new_overprovision); DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
Without this change, the assert message "Cannot support wrong overprovision ratio" was printed when I ran resize.f2fs -t X command to the f2fs formatted with mkfs.f2fs -s Y. With the change above, the assert message is not printed.
Quoted 12 lines
Quoted 11 lines
FYI, I tried to fix and created a patch which allows reserved segments larger than overprovisioning segments [1]. It compares those two, and take larger one to subtract from usable segments to get the segments for users. I confirmed it keeps small number of overprovisioning segments for no -s option case, and avoids the mkfs.f2fs failure for the -s option and zoned block device cases. However, it increases runtime of my test script which fills f2fs and do file overwrites to test f2fs GC on zoned block devices. It takes +60% longer runtime. Then GC performance looks worse than before, and this fix does not look good for me.
Quoted 1 line
I think you can try to avoid that by tuning
/sys/fs/f2fs/xx/reserved_blocks?
Thanks, I was able to shorten the runtime using the sysfs attribute. So the longer GC time was just caused by the smaller reserved segments size. Good.
Signature · 6 lines
Shin'ichiro Kawasaki _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
AppliedQuoted 28 lines · Shinichiro Kawasaki
On Oct 20, 2022 / 16:18, Jaegeuk Kim wrote:
...
Quoted 2 lines
Thanks, I think that fix looks good to me. I applied into the original patch.
https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev&id=281d3e72370f6c39c0d57acaf37a7f0e003ddd28Oh, happy to know that the fix is good. And thank you for adding my SoB tag.
One more thing, my fix missed care for
fsck/resize.c. I suggest to apply one more hunk below to the commit in same manner asmkfs/f2fs_format.c.fsck/resize.c +2
-2@@ -476,8 +476,8 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, get_cp(rsvd_segment_count)) * c.new_overprovision / 100); -if (get_cp (rsvd_segment_count) >get_cp (overprov_segment_count)) -ASSERT_MSG ("Cannot support wrong overprovision ratio\n" ); +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count));DBG (0 ,"Info: Overprovision ratio = %.3lf%%\n" , c.new_overprovision); DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
Quoted 3 lines
Without this change, the assert message "Cannot support wrong overprovision ratio" was printed when I ran resize.f2fs -t X command to the f2fs formatted with mkfs.f2fs -s Y. With the change above, the assert message is not printed.
Thanks, applied.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
FYI, I tried to fix and created a patch which allows reserved segments larger than overprovisioning segments [1]. It compares those two, and take larger one to subtract from usable segments to get the segments for users. I confirmed it keeps small number of overprovisioning segments for no -s option case, and avoids the mkfs.f2fs failure for the -s option and zoned block device cases. However, it increases runtime of my test script which fills f2fs and do file overwrites to test f2fs GC on zoned block devices. It takes +60% longer runtime. Then GC performance looks worse than before, and this fix does not look good for me.
Quoted 7 lines
Quoted 1 line
I think you can try to avoid that by tuning
/sys/fs/f2fs/xx/reserved_blocks?Thanks, I was able to shorten the runtime using the sysfs attribute. So the longer GC time was just caused by the smaller reserved segments size. Good.
Signature · 1 line
Shin'ichiro Kawasaki
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
As f2fs becomes more resilient for GCs, let's give the marginal overprovision space back to user.
Fix an issue where reserved_space > ovp_space, reported by Shinichiro.
---
Change log from v1:
- adjust ovp should be larger than reserved to kick f2fs runtime GCs
fsck/resize.c | 12 +++++++++--- include/f2fs_fs.h | 7 +++++-- mkfs/f2fs_format.c | 8 ++++++-- 3 files changed, 20 insertions(+), 7 deletions(-)
fsck/resize.c +9 -3
@@ -150,7 +150,7 @@ safe_resize: c.new_overprovision =get_best_overprovision (sb); c.new_reserved_segments = - (2 * (100 / c.new_overprovision +1 ) +6 ) * + (100 / c.new_overprovision +1 +NR_CURSEG_TYPE ) *get_sb (segs_per_sec); if ((get_sb(segment_count_main) - 2) < c.new_reserved_segments ||
@@ -475,8 +475,13 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,set_cp (overprov_segment_count, (get_newsb (segment_count_main) -get_cp (rsvd_segment_count)) * c.new_overprovision /100 ); + +/* give 2 sections (DATA and NODE) to trigger GC in advance */ +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count)); +set_cp (overprov_segment_count,get_cp (overprov_segment_count) + -get_cp (rsvd_segment_count)); +2 *get_sb (segs_per_sec));DBG (0 ,"Info: Overprovision ratio = %.3lf%%\n" , c.new_overprovision); DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
@@ -607,7 +612,8 @@ static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block * overprov_segment_count = (get_newsb (segment_count_main) - c.new_reserved_segments) * c.new_overprovision /100 ; - overprov_segment_count += c.new_reserved_segments; + + overprov_segment_count +=2 *get_newsb (segs_per_sec); user_block_count = (get_newsb (segment_count_main) - overprov_segment_count) * c.blks_per_seg;
include/f2fs_fs.h +5 -2
@@ -1631,10 +1631,13 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb) }for (; candidate <= end; candidate += diff) { - reserved = (2 * (100 / candidate +1 ) +6 ) * + reserved = (100 / candidate +1 +NR_CURSEG_TYPE ) *round_up (usable_main_segs,get_sb (section_count)); ovp = (usable_main_segs - reserved) * candidate /100 ; - space = usable_main_segs - reserved - ovp; +if (ovp <0 ) +continue ; + space = usable_main_segs -max (reserved, ovp) - +2 *get_sb (segs_per_sec);if (max_space < space) { max_space = space; max_ovp = candidate;
mkfs/f2fs_format.c +6 -2
@@ -484,7 +484,7 @@ static int f2fs_prepare_super_block(void) c.overprovision =get_best_overprovision (sb); c.reserved_segments = - (2 * (100 / c.overprovision +1 ) +NR_CURSEG_TYPE ) * + (100 / c.overprovision +1 +NR_CURSEG_TYPE ) *round_up (f2fs_get_usable_segments (sb),get_sb (section_count));if (c.feature &cpu_to_le32 (F2FS_FEATURE_RO )) {
@@ -764,8 +764,12 @@ static int f2fs_write_check_point_pack(void)set_cp (overprov_segment_count, (f2fs_get_usable_segments (sb) -get_cp (rsvd_segment_count)) * c.overprovision /100 ); + +if (get_cp (overprov_segment_count) <get_cp (rsvd_segment_count)) +set_cp (overprov_segment_count,get_cp (rsvd_segment_count)); +set_cp (overprov_segment_count,get_cp (overprov_segment_count) + -get_cp (rsvd_segment_count)); +2 *get_sb (segs_per_sec));if (f2fs_get_usable_segments (sb) <=get_cp (overprov_segment_count)) {MSG (0 ,"\tError: Not enough segments to create F2FS Volume\n" );
Signature · 8 lines
2.38.0.135.g90850a2211-goog _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel