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

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



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* [PATCH] f2fs-tools:provide a more reasonable ovp rate for manually setting rsvd
@ 2024-09-24  9:56 ` Liao Yuanhong
  0 siblings, 0 replies; 4+ 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 related	[flat|nested] 4+ messages in thread

* Re: [f2fs-dev] [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
  -1 siblings, 0 replies; 4+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2024-10-09  7:39 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

On 2024/9/24 17:56, Liao Yuanhong wrote:
> 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);

get_best_overprovision() can provide a pair value [ovp, reserved], which can
maximize available space for user. If we just pick one of them, and use configured
one instead of another of them, it's weird.

For your case, maybe we can introduce a default ovp value, and use it w/ configured
reserved value? or you can assign ovp/reserved secs directly by using -o and -Z?

Thanks,

> +	}
> +
> +	c.reserved_segments = get_reserved(sb, c.overprovision, true);
>   
>   	if (c.feature & F2FS_FEATURE_RO) {
>   		c.overprovision = 0;



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [PATCH] f2fs-tools:provide a more reasonable ovp rate for manually setting rsvd
@ 2024-10-09  7:39   ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2024-10-09  7:39 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim; +Cc: Chao Yu, linux-f2fs-devel, linux-kernel

On 2024/9/24 17:56, Liao Yuanhong wrote:
> 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);

get_best_overprovision() can provide a pair value [ovp, reserved], which can
maximize available space for user. If we just pick one of them, and use configured
one instead of another of them, it's weird.

For your case, maybe we can introduce a default ovp value, and use it w/ configured
reserved value? or you can assign ovp/reserved secs directly by using -o and -Z?

Thanks,

> +	}
> +
> +	c.reserved_segments = get_reserved(sb, c.overprovision, true);
>   
>   	if (c.feature & F2FS_FEATURE_RO) {
>   		c.overprovision = 0;


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

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

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.