mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs-tools:provide a more reasonable ovp rate for manually setting rsvd
@ 2024-09-24  9:56 Liao Yuanhong
  2024-10-09  7:39 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Liao Yuanhong @ 2024-09-24  9:56 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Liao Yuanhong

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 <liaoyuanhong@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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-09  7:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-24  9:56 [PATCH] f2fs-tools:provide a more reasonable ovp rate for manually setting rsvd Liao Yuanhong
2024-10-09  7:39 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®