From 76a88baa904759ff3b5004b64f396020526d9db2 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Mon, 10 Oct 2022 14:02:22 -0700 Subject: [PATCH] f2fs-tools: give less overprovisioning space 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. Signed-off-by: Shinichiro Kawasaki Signed-off-by: Jaegeuk Kim --- fsck/resize.c | 12 +++++++++--- include/f2fs_fs.h | 7 +++++-- mkfs/f2fs_format.c | 8 ++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/fsck/resize.c b/fsck/resize.c index 3d8ea46..c545dd9 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -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; diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 5fa9931..333ae07 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -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; diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 10ed74e..9fc091f 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -486,7 +486,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)) { @@ -766,8 +766,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");