The f2fs-tools support manual configuration of rsvd and ovp rate. In cases where only a small rsvd is set, the automatically calculated ovp rate can be very large, resulting in the reserved space of the entire file system being almost the same as before, failing to achieve the goal of reducing space usage. Therefore, for cases where only rsvd is set and ovp rate is not, we will provide the same ovp rate as in normal situations, which exceeds overprovision_segment_buffer, and does not occupy additional space.
Signed-off-by: Liao Yuanhong <liaoyuanh...@vivo.com> --- fsck/resize.c | 2 +- include/f2fs_fs.h | 8 ++++---- mkfs/f2fs_format.c | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fsck/resize.c b/fsck/resize.c index 049ddd3..eca6555 100644 --- a/fsck/resize.c +++ b/fsck/resize.c @@ -147,7 +147,7 @@ safe_resize: /* Let's determine the best reserved and overprovisioned space */ if (c.new_overprovision == 0) - c.new_overprovision = get_best_overprovision(sb); + c.new_overprovision = get_best_overprovision(sb, true); c.new_reserved_segments = (100 / c.new_overprovision + 1 + NR_CURSEG_TYPE) * diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 870a6e4..038002a 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1760,13 +1760,13 @@ extern uint32_t f2fs_get_usable_segments(struct f2fs_super_block *sb); #define ZONE_ALIGN(blks) SIZE_ALIGN(blks, c.blks_per_seg * \ c.segs_per_zone) -static inline uint32_t get_reserved(struct f2fs_super_block *sb, double ovp) +static inline uint32_t get_reserved(struct f2fs_super_block *sb, double ovp, bool conf_reserved) { uint32_t usable_main_segs = f2fs_get_usable_segments(sb); uint32_t segs_per_sec = round_up(usable_main_segs, get_sb(section_count)); uint32_t reserved; - if (c.conf_reserved_sections) + if (c.conf_reserved_sections && conf_reserved) reserved = c.conf_reserved_sections * segs_per_sec; else reserved = (100 / ovp + 1 + NR_CURSEG_TYPE) * segs_per_sec; @@ -1781,7 +1781,7 @@ static inline uint32_t overprovision_segment_buffer(struct f2fs_super_block *sb) return 6 * get_sb(segs_per_sec); } -static inline double get_best_overprovision(struct f2fs_super_block *sb) +static inline double get_best_overprovision(struct f2fs_super_block *sb, bool conf_reserved) { double ovp, candidate, end, diff, space; double max_ovp = 0, max_space = 0; @@ -1799,7 +1799,7 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb) } for (; candidate <= end; candidate += diff) { - reserved = get_reserved(sb, candidate); + reserved = get_reserved(sb, candidate, conf_reserved); ovp = (usable_main_segs - reserved) * candidate / 100; if (ovp < 0) continue; diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index e26a513..9c917c9 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -480,10 +480,19 @@ static int f2fs_prepare_super_block(void) * overprovision ratio and reserved seg count based on avg usable * segs_per_sec. */ - if (c.overprovision == 0) - c.overprovision = get_best_overprovision(sb); + if (c.overprovision == 0) { - c.reserved_segments = get_reserved(sb, c.overprovision); + /* + * If rsvd is manually set but ovp rate is not, + * provide the same ovp rate as in normal allocation. + */ + if (c.conf_reserved_sections) + c.overprovision = get_best_overprovision(sb, false); + else + c.overprovision = get_best_overprovision(sb, true); + } + + c.reserved_segments = get_reserved(sb, c.overprovision, true); if (c.feature & F2FS_FEATURE_RO) { c.overprovision = 0; -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel