linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 0/2] f2fs: Some optimizations for background GC in Zoned UFS.
@ 2025-09-09 13:44 Liao Yuanhong via Linux-f2fs-devel
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection " Liao Yuanhong via Linux-f2fs-devel
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC Liao Yuanhong via Linux-f2fs-devel
  0 siblings, 2 replies; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-09 13:44 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, open list:F2FS FILE SYSTEM, open list; +Cc: Liao Yuanhong

While testing Zoned UFS, I discovered that the background GC results in
excessive write operations. I wrote a script to capture the data, as shown
below:

Timestamp        Free_Sections        BG_GC_Calls        Dirty_Segment
2025/9/8 19:04   433                  0                  935  <-- begin
...
2025/9/8 20:17   224                  14533              27734  <-- stop
...
2025/9/8 22:07   244                  78722              728
2025/9/8 22:07   243                  78968              755
2025/9/8 22:08   243                  79201              706
...
2025/9/9 9:46    244                  273763             797
2025/9/9 9:47    244                  273930             791
2025/9/9 9:47    244                  274097             796
2025/9/9 9:48    243                  274265             791

Currently, in Zoned UFS, when free space is between 25% and 60%, background
GC is triggered without boosting. If the free space does not recover to
more than 60%, the background GC does not stop. This leads to excessive
redundant GC writes, as there are not enough dirty segments to release. I
suggest adding a has_enough_dirty_blocks() function to determine if there
are enough dirty segments that can be freed. If there aren't enough dirty
segments available, the background GC should be halted. After applying this
patch, the captured data is as follows:

Timestamp        Free_Sections        BG_GC_Calls        Dirty_Segment
2025/9/9 12:04   444                  0                  529  <-- begin
...
2025/9/9 16:54   227                  14339              29854  <-- stop
...
2025/9/9 20:31   242                  55842              1583
2025/9/9 20:32   242                  55842              1583
2025/9/9 20:32   242                  55842              1584
2025/9/9 20:33   242                  55842              1585
2025/9/9 20:34   242                  55843              1583
2025/9/9 20:34   242                  55843              1583
2025/9/9 20:35   242                  55843              1583
2025/9/9 20:35   242                  55843              1583
2025/9/9 20:36   242                  55843              1584

This patch currently only optimizes background GC. Similar issues seem to
be present for foreground GC, requiring further investigation.

Additionally, I implemented a modification to the valid_thresh_ratio to
prevent the execution of background GC when the proportion of dirty
segments in all sections within the range exceeds the valid_thresh_ratio.
This also helps to avoid unnecessary excessive write operations.

Liao Yuanhong (2):
  f2fs: Optimize excessive write operations caused by continuous
    background garbage collection in Zoned UFS
  f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent
    unnecessary background GC

 fs/f2fs/gc.c | 13 +++++++++++--
 fs/f2fs/gc.h |  9 ++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

-- 
2.34.1



_______________________________________________
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] 13+ messages in thread

* [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection in Zoned UFS
  2025-09-09 13:44 [f2fs-dev] [PATCH 0/2] f2fs: Some optimizations for background GC in Zoned UFS Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-09 13:44 ` Liao Yuanhong via Linux-f2fs-devel
  2025-09-15  8:25   ` Chao Yu via Linux-f2fs-devel
  2025-09-16  2:28   ` Jaegeuk Kim via Linux-f2fs-devel
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC Liao Yuanhong via Linux-f2fs-devel
  1 sibling, 2 replies; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-09 13:44 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, open list:F2FS FILE SYSTEM, open list; +Cc: Liao Yuanhong

Incorporate a check using has_enough_dirty_blocks() to prevent redundant
background GC in Zoned UFS. When there are insufficient dirty segments,
continuous execution of background GC should be avoided, as it results in
unnecessary write operations and impacts device lifespan. The initial
threshold is set to 3 * section size (since f2fs data uses three write
pointers).

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 fs/f2fs/gc.c |  8 ++++++--
 fs/f2fs/gc.h | 10 +++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index ed3acbfc83ca..4a8c08f970e3 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -120,7 +120,9 @@ static int gc_thread_func(void *data)
 
 		if (f2fs_sb_has_blkzoned(sbi)) {
 			if (has_enough_free_blocks(sbi,
-				gc_th->no_zoned_gc_percent)) {
+				gc_th->no_zoned_gc_percent) ||
+				!has_enough_dirty_blocks(sbi,
+				LIMIT_GC_DIRTY_SECTION_NUM)) {
 				wait_ms = gc_th->no_gc_sleep_time;
 				f2fs_up_write(&sbi->gc_lock);
 				goto next;
@@ -1750,7 +1752,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 
 			if (f2fs_sb_has_blkzoned(sbi) &&
 					!has_enough_free_blocks(sbi,
-					sbi->gc_thread->boost_zoned_gc_percent))
+					sbi->gc_thread->boost_zoned_gc_percent) &&
+					has_enough_dirty_blocks(sbi,
+					LIMIT_GC_DIRTY_SECTION_NUM))
 				window_granularity *=
 					sbi->gc_thread->boost_gc_multiple;
 
diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h
index 24e8b1c27acc..1ef234c2702b 100644
--- a/fs/f2fs/gc.h
+++ b/fs/f2fs/gc.h
@@ -36,6 +36,7 @@
 #define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED	3
 #define BOOST_GC_MULTIPLE	5
 #define ZONED_PIN_SEC_REQUIRED_COUNT	1
+#define LIMIT_GC_DIRTY_SECTION_NUM	3
 
 #define DEF_GC_FAILED_PINNED_FILES	2048
 #define MAX_GC_FAILED_PINNED_FILES	USHRT_MAX
@@ -177,6 +178,12 @@ static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi,
 	return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100);
 }
 
+static inline bool has_enough_dirty_blocks(struct f2fs_sb_info *sbi,
+						unsigned int limit_num)
+{
+	return dirty_segments(sbi) > limit_num * SEGS_PER_SEC(sbi);
+}
+
 static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
 {
 	block_t user_block_count = sbi->user_block_count;
@@ -197,6 +204,7 @@ static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi)
 {
 	if (f2fs_sb_has_blkzoned(sbi))
 		return !has_enough_free_blocks(sbi,
-				sbi->gc_thread->boost_zoned_gc_percent);
+				sbi->gc_thread->boost_zoned_gc_percent) &&
+				has_enough_dirty_blocks(sbi, LIMIT_GC_DIRTY_SECTION_NUM);
 	return has_enough_invalid_blocks(sbi);
 }
-- 
2.34.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] 13+ messages in thread

* [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-09 13:44 [f2fs-dev] [PATCH 0/2] f2fs: Some optimizations for background GC in Zoned UFS Liao Yuanhong via Linux-f2fs-devel
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection " Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-09 13:44 ` Liao Yuanhong via Linux-f2fs-devel
  2025-09-15  8:36   ` Chao Yu via Linux-f2fs-devel
  1 sibling, 1 reply; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-09 13:44 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, open list:F2FS FILE SYSTEM, open list; +Cc: Liao Yuanhong

When the proportion of dirty segments within a section exceeds the
valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
indicating that these sections should not be released. However, if all
section costs within the scanning range of get_victim() are UINT_MAX,
background GC will still occur. Add a condition to prevent this situation.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
 fs/f2fs/gc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 4a8c08f970e3..ffc3188416f4 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
 		}
 	}
 
+	if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
+		ret = -ENODATA;
+		goto out;
+	}
+
 	/* get victim for GC_AT/AT_SSR */
 	if (is_atgc) {
 		lookup_victim_by_age(sbi, &p);
-- 
2.34.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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection in Zoned UFS
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection " Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-15  8:25   ` Chao Yu via Linux-f2fs-devel
  2025-09-16  2:28   ` Jaegeuk Kim via Linux-f2fs-devel
  1 sibling, 0 replies; 13+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-15  8:25 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list

On 9/9/25 21:44, Liao Yuanhong wrote:
> Incorporate a check using has_enough_dirty_blocks() to prevent redundant
> background GC in Zoned UFS. When there are insufficient dirty segments,
> continuous execution of background GC should be avoided, as it results in
> unnecessary write operations and impacts device lifespan. The initial
> threshold is set to 3 * section size (since f2fs data uses three write
> pointers).
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-15  8:36   ` Chao Yu via Linux-f2fs-devel
  2025-09-17  7:08     ` Liao Yuanhong via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-15  8:36 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list

On 9/9/25 21:44, Liao Yuanhong wrote:
> When the proportion of dirty segments within a section exceeds the
> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
> indicating that these sections should not be released. However, if all
> section costs within the scanning range of get_victim() are UINT_MAX,
> background GC will still occur. Add a condition to prevent this situation.

For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
segno for GC?

Thanks,

> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
>  fs/f2fs/gc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index 4a8c08f970e3..ffc3188416f4 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>  		}
>  	}
>  
> +	if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
> +		ret = -ENODATA;
> +		goto out;
> +	}
> +
>  	/* get victim for GC_AT/AT_SSR */
>  	if (is_atgc) {
>  		lookup_victim_by_age(sbi, &p);



_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection in Zoned UFS
  2025-09-09 13:44 ` [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection " Liao Yuanhong via Linux-f2fs-devel
  2025-09-15  8:25   ` Chao Yu via Linux-f2fs-devel
@ 2025-09-16  2:28   ` Jaegeuk Kim via Linux-f2fs-devel
  2025-09-17  7:15     ` Liao Yuanhong via Linux-f2fs-devel
  1 sibling, 1 reply; 13+ messages in thread
From: Jaegeuk Kim via Linux-f2fs-devel @ 2025-09-16  2:28 UTC (permalink / raw)
  To: Liao Yuanhong; +Cc: open list, open list:F2FS FILE SYSTEM

Could you please share some trends of relation between has_enough_free_blocks()
vs. has_enough_dirty_blocks()? I'm wondering whethere there's a missing case
where has_enough_free_blocks() is not enough.

On 09/09, Liao Yuanhong wrote:
> Incorporate a check using has_enough_dirty_blocks() to prevent redundant
> background GC in Zoned UFS. When there are insufficient dirty segments,
> continuous execution of background GC should be avoided, as it results in
> unnecessary write operations and impacts device lifespan. The initial
> threshold is set to 3 * section size (since f2fs data uses three write
> pointers).
> 
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
>  fs/f2fs/gc.c |  8 ++++++--
>  fs/f2fs/gc.h | 10 +++++++++-
>  2 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index ed3acbfc83ca..4a8c08f970e3 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -120,7 +120,9 @@ static int gc_thread_func(void *data)
>  
>  		if (f2fs_sb_has_blkzoned(sbi)) {
>  			if (has_enough_free_blocks(sbi,
> -				gc_th->no_zoned_gc_percent)) {
> +				gc_th->no_zoned_gc_percent) ||
> +				!has_enough_dirty_blocks(sbi,
> +				LIMIT_GC_DIRTY_SECTION_NUM)) {
>  				wait_ms = gc_th->no_gc_sleep_time;
>  				f2fs_up_write(&sbi->gc_lock);
>  				goto next;
> @@ -1750,7 +1752,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
>  
>  			if (f2fs_sb_has_blkzoned(sbi) &&
>  					!has_enough_free_blocks(sbi,
> -					sbi->gc_thread->boost_zoned_gc_percent))
> +					sbi->gc_thread->boost_zoned_gc_percent) &&
> +					has_enough_dirty_blocks(sbi,
> +					LIMIT_GC_DIRTY_SECTION_NUM))
>  				window_granularity *=
>  					sbi->gc_thread->boost_gc_multiple;
>  
> diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h
> index 24e8b1c27acc..1ef234c2702b 100644
> --- a/fs/f2fs/gc.h
> +++ b/fs/f2fs/gc.h
> @@ -36,6 +36,7 @@
>  #define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED	3
>  #define BOOST_GC_MULTIPLE	5
>  #define ZONED_PIN_SEC_REQUIRED_COUNT	1
> +#define LIMIT_GC_DIRTY_SECTION_NUM	3
>  
>  #define DEF_GC_FAILED_PINNED_FILES	2048
>  #define MAX_GC_FAILED_PINNED_FILES	USHRT_MAX
> @@ -177,6 +178,12 @@ static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi,
>  	return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100);
>  }
>  
> +static inline bool has_enough_dirty_blocks(struct f2fs_sb_info *sbi,
> +						unsigned int limit_num)
> +{
> +	return dirty_segments(sbi) > limit_num * SEGS_PER_SEC(sbi);
> +}
> +
>  static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
>  {
>  	block_t user_block_count = sbi->user_block_count;
> @@ -197,6 +204,7 @@ static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi)
>  {
>  	if (f2fs_sb_has_blkzoned(sbi))
>  		return !has_enough_free_blocks(sbi,
> -				sbi->gc_thread->boost_zoned_gc_percent);
> +				sbi->gc_thread->boost_zoned_gc_percent) &&
> +				has_enough_dirty_blocks(sbi, LIMIT_GC_DIRTY_SECTION_NUM);
>  	return has_enough_invalid_blocks(sbi);
>  }
> -- 
> 2.34.1


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-15  8:36   ` Chao Yu via Linux-f2fs-devel
@ 2025-09-17  7:08     ` Liao Yuanhong via Linux-f2fs-devel
  2025-09-17  7:57       ` Chao Yu via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-17  7:08 UTC (permalink / raw)
  To: Chao Yu, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list


On 9/15/2025 4:36 PM, Chao Yu wrote:
> On 9/9/25 21:44, Liao Yuanhong wrote:
>> When the proportion of dirty segments within a section exceeds the
>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>> indicating that these sections should not be released. However, if all
>> section costs within the scanning range of get_victim() are UINT_MAX,
>> background GC will still occur. Add a condition to prevent this situation.
> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
> segno for GC?
>
> Thanks,

You're right, segno won't update in this scenario, and this patch 
feature is redundant.


Thanks,

Liao

>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>> ---
>>   fs/f2fs/gc.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>> index 4a8c08f970e3..ffc3188416f4 100644
>> --- a/fs/f2fs/gc.c
>> +++ b/fs/f2fs/gc.c
>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>   		}
>>   	}
>>   
>> +	if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>> +		ret = -ENODATA;
>> +		goto out;
>> +	}
>> +
>>   	/* get victim for GC_AT/AT_SSR */
>>   	if (is_atgc) {
>>   		lookup_victim_by_age(sbi, &p);


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection in Zoned UFS
  2025-09-16  2:28   ` Jaegeuk Kim via Linux-f2fs-devel
@ 2025-09-17  7:15     ` Liao Yuanhong via Linux-f2fs-devel
  0 siblings, 0 replies; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-17  7:15 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: open list, open list:F2FS FILE SYSTEM


On 9/16/2025 10:28 AM, Jaegeuk Kim wrote:
> Could you please share some trends of relation between has_enough_free_blocks()
> vs. has_enough_dirty_blocks()? I'm wondering whethere there's a missing case
> where has_enough_free_blocks() is not enough.

Sure. I will find some time to test the data and create a table to see 
if there are any omissions.


Thanks,

Liao

> On 09/09, Liao Yuanhong wrote:
>> Incorporate a check using has_enough_dirty_blocks() to prevent redundant
>> background GC in Zoned UFS. When there are insufficient dirty segments,
>> continuous execution of background GC should be avoided, as it results in
>> unnecessary write operations and impacts device lifespan. The initial
>> threshold is set to 3 * section size (since f2fs data uses three write
>> pointers).
>>
>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>> ---
>>   fs/f2fs/gc.c |  8 ++++++--
>>   fs/f2fs/gc.h | 10 +++++++++-
>>   2 files changed, 15 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>> index ed3acbfc83ca..4a8c08f970e3 100644
>> --- a/fs/f2fs/gc.c
>> +++ b/fs/f2fs/gc.c
>> @@ -120,7 +120,9 @@ static int gc_thread_func(void *data)
>>   
>>   		if (f2fs_sb_has_blkzoned(sbi)) {
>>   			if (has_enough_free_blocks(sbi,
>> -				gc_th->no_zoned_gc_percent)) {
>> +				gc_th->no_zoned_gc_percent) ||
>> +				!has_enough_dirty_blocks(sbi,
>> +				LIMIT_GC_DIRTY_SECTION_NUM)) {
>>   				wait_ms = gc_th->no_gc_sleep_time;
>>   				f2fs_up_write(&sbi->gc_lock);
>>   				goto next;
>> @@ -1750,7 +1752,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
>>   
>>   			if (f2fs_sb_has_blkzoned(sbi) &&
>>   					!has_enough_free_blocks(sbi,
>> -					sbi->gc_thread->boost_zoned_gc_percent))
>> +					sbi->gc_thread->boost_zoned_gc_percent) &&
>> +					has_enough_dirty_blocks(sbi,
>> +					LIMIT_GC_DIRTY_SECTION_NUM))
>>   				window_granularity *=
>>   					sbi->gc_thread->boost_gc_multiple;
>>   
>> diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h
>> index 24e8b1c27acc..1ef234c2702b 100644
>> --- a/fs/f2fs/gc.h
>> +++ b/fs/f2fs/gc.h
>> @@ -36,6 +36,7 @@
>>   #define DEF_MIGRATION_WINDOW_GRANULARITY_ZONED	3
>>   #define BOOST_GC_MULTIPLE	5
>>   #define ZONED_PIN_SEC_REQUIRED_COUNT	1
>> +#define LIMIT_GC_DIRTY_SECTION_NUM	3
>>   
>>   #define DEF_GC_FAILED_PINNED_FILES	2048
>>   #define MAX_GC_FAILED_PINNED_FILES	USHRT_MAX
>> @@ -177,6 +178,12 @@ static inline bool has_enough_free_blocks(struct f2fs_sb_info *sbi,
>>   	return free_sections(sbi) > ((sbi->total_sections * limit_perc) / 100);
>>   }
>>   
>> +static inline bool has_enough_dirty_blocks(struct f2fs_sb_info *sbi,
>> +						unsigned int limit_num)
>> +{
>> +	return dirty_segments(sbi) > limit_num * SEGS_PER_SEC(sbi);
>> +}
>> +
>>   static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi)
>>   {
>>   	block_t user_block_count = sbi->user_block_count;
>> @@ -197,6 +204,7 @@ static inline bool need_to_boost_gc(struct f2fs_sb_info *sbi)
>>   {
>>   	if (f2fs_sb_has_blkzoned(sbi))
>>   		return !has_enough_free_blocks(sbi,
>> -				sbi->gc_thread->boost_zoned_gc_percent);
>> +				sbi->gc_thread->boost_zoned_gc_percent) &&
>> +				has_enough_dirty_blocks(sbi, LIMIT_GC_DIRTY_SECTION_NUM);
>>   	return has_enough_invalid_blocks(sbi);
>>   }
>> -- 
>> 2.34.1


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-17  7:08     ` Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-17  7:57       ` Chao Yu via Linux-f2fs-devel
  2025-09-17  8:13         ` Liao Yuanhong via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-17  7:57 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list

On 9/17/25 15:08, Liao Yuanhong wrote:
> 
> On 9/15/2025 4:36 PM, Chao Yu wrote:
>> On 9/9/25 21:44, Liao Yuanhong wrote:
>>> When the proportion of dirty segments within a section exceeds the
>>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>>> indicating that these sections should not be released. However, if all
>>> section costs within the scanning range of get_victim() are UINT_MAX,
>>> background GC will still occur. Add a condition to prevent this situation.
>> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
>> segno for GC?
>>
>> Thanks,
> 
> You're right, segno won't update in this scenario, and this patch feature is redundant.

Oh, I meant, if f2fs_get_victim() fails to select a valid victim due to the reason you
described, f2fs_get_victim() will return 0, and f2fs_gc() will migrate segment #NULL_SEGNO?
Or am I missing something?

Thanks,

> 
> 
> Thanks,
> 
> Liao
> 
>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>> ---
>>>   fs/f2fs/gc.c | 5 +++++
>>>   1 file changed, 5 insertions(+)
>>>
>>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>>> index 4a8c08f970e3..ffc3188416f4 100644
>>> --- a/fs/f2fs/gc.c
>>> +++ b/fs/f2fs/gc.c
>>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>>           }
>>>       }
>>>   +    if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>>> +        ret = -ENODATA;
>>> +        goto out;
>>> +    }
>>> +
>>>       /* get victim for GC_AT/AT_SSR */
>>>       if (is_atgc) {
>>>           lookup_victim_by_age(sbi, &p);



_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-17  7:57       ` Chao Yu via Linux-f2fs-devel
@ 2025-09-17  8:13         ` Liao Yuanhong via Linux-f2fs-devel
  2025-09-18  2:16           ` Chao Yu via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-17  8:13 UTC (permalink / raw)
  To: Chao Yu, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list


On 9/17/2025 3:57 PM, Chao Yu wrote:
> On 9/17/25 15:08, Liao Yuanhong wrote:
>> On 9/15/2025 4:36 PM, Chao Yu wrote:
>>> On 9/9/25 21:44, Liao Yuanhong wrote:
>>>> When the proportion of dirty segments within a section exceeds the
>>>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>>>> indicating that these sections should not be released. However, if all
>>>> section costs within the scanning range of get_victim() are UINT_MAX,
>>>> background GC will still occur. Add a condition to prevent this situation.
>>> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
>>> segno for GC?
>>>
>>> Thanks,
>> You're right, segno won't update in this scenario, and this patch feature is redundant.
> Oh, I meant, if f2fs_get_victim() fails to select a valid victim due to the reason you
> described, f2fs_get_victim() will return 0, and f2fs_gc() will migrate segment #NULL_SEGNO?
> Or am I missing something?
>
> Thanks,

Yes. In this scenario, since it won't enter the|p.min_cost > 
cost|condition,|p.min_segno|will retain its initial value|||NULL_SEGNO|. 
This is consistent with what you described.


Thanks,

Liao

>>
>> Thanks,
>>
>> Liao
>>
>>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>>> ---
>>>>    fs/f2fs/gc.c | 5 +++++
>>>>    1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>>>> index 4a8c08f970e3..ffc3188416f4 100644
>>>> --- a/fs/f2fs/gc.c
>>>> +++ b/fs/f2fs/gc.c
>>>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>>>            }
>>>>        }
>>>>    +    if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>>>> +        ret = -ENODATA;
>>>> +        goto out;
>>>> +    }
>>>> +
>>>>        /* get victim for GC_AT/AT_SSR */
>>>>        if (is_atgc) {
>>>>            lookup_victim_by_age(sbi, &p);


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-17  8:13         ` Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-18  2:16           ` Chao Yu via Linux-f2fs-devel
  2025-09-20  2:49             ` Liao Yuanhong via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-18  2:16 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list

On 9/17/25 16:13, Liao Yuanhong wrote:
> 
> On 9/17/2025 3:57 PM, Chao Yu wrote:
>> On 9/17/25 15:08, Liao Yuanhong wrote:
>>> On 9/15/2025 4:36 PM, Chao Yu wrote:
>>>> On 9/9/25 21:44, Liao Yuanhong wrote:
>>>>> When the proportion of dirty segments within a section exceeds the
>>>>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>>>>> indicating that these sections should not be released. However, if all
>>>>> section costs within the scanning range of get_victim() are UINT_MAX,
>>>>> background GC will still occur. Add a condition to prevent this situation.
>>>> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
>>>> segno for GC?
>>>>
>>>> Thanks,
>>> You're right, segno won't update in this scenario, and this patch feature is redundant.
>> Oh, I meant, if f2fs_get_victim() fails to select a valid victim due to the reason you
>> described, f2fs_get_victim() will return 0, and f2fs_gc() will migrate segment #NULL_SEGNO?
>> Or am I missing something?
>>
>> Thanks,
> 
> Yes. In this scenario, since it won't enter the|p.min_cost > cost|condition,|p.min_segno|will retain its initial value|||NULL_SEGNO|. This is consistent with what you described.

Do you have a script to reproduce this bug?

Thanks,

> 
> 
> Thanks,
> 
> Liao
> 
>>>
>>> Thanks,
>>>
>>> Liao
>>>
>>>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>>>> ---
>>>>>    fs/f2fs/gc.c | 5 +++++
>>>>>    1 file changed, 5 insertions(+)
>>>>>
>>>>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>>>>> index 4a8c08f970e3..ffc3188416f4 100644
>>>>> --- a/fs/f2fs/gc.c
>>>>> +++ b/fs/f2fs/gc.c
>>>>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>>>>            }
>>>>>        }
>>>>>    +    if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>>>>> +        ret = -ENODATA;
>>>>> +        goto out;
>>>>> +    }
>>>>> +
>>>>>        /* get victim for GC_AT/AT_SSR */
>>>>>        if (is_atgc) {
>>>>>            lookup_victim_by_age(sbi, &p);



_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-18  2:16           ` Chao Yu via Linux-f2fs-devel
@ 2025-09-20  2:49             ` Liao Yuanhong via Linux-f2fs-devel
  2025-09-23  6:43               ` Chao Yu via Linux-f2fs-devel
  0 siblings, 1 reply; 13+ messages in thread
From: Liao Yuanhong via Linux-f2fs-devel @ 2025-09-20  2:49 UTC (permalink / raw)
  To: Chao Yu, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list


On 9/18/2025 10:16 AM, Chao Yu wrote:
> On 9/17/25 16:13, Liao Yuanhong wrote:
>> On 9/17/2025 3:57 PM, Chao Yu wrote:
>>> On 9/17/25 15:08, Liao Yuanhong wrote:
>>>> On 9/15/2025 4:36 PM, Chao Yu wrote:
>>>>> On 9/9/25 21:44, Liao Yuanhong wrote:
>>>>>> When the proportion of dirty segments within a section exceeds the
>>>>>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>>>>>> indicating that these sections should not be released. However, if all
>>>>>> section costs within the scanning range of get_victim() are UINT_MAX,
>>>>>> background GC will still occur. Add a condition to prevent this situation.
>>>>> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
>>>>> segno for GC?
>>>>>
>>>>> Thanks,
>>>> You're right, segno won't update in this scenario, and this patch feature is redundant.
>>> Oh, I meant, if f2fs_get_victim() fails to select a valid victim due to the reason you
>>> described, f2fs_get_victim() will return 0, and f2fs_gc() will migrate segment #NULL_SEGNO?
>>> Or am I missing something?
>>>
>>> Thanks,
>> Yes. In this scenario, since it won't enter the|p.min_cost > cost|condition,|p.min_segno|will retain its initial value|||NULL_SEGNO|. This is consistent with what you described.
> Do you have a script to reproduce this bug?
>
> Thanks,

I didn't explain it clearly. What I mean is that this patch is 
redundant, the original code is fine.


Thanks,

Liao

>>
>> Thanks,
>>
>> Liao
>>
>>>> Thanks,
>>>>
>>>> Liao
>>>>
>>>>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>>>>> ---
>>>>>>     fs/f2fs/gc.c | 5 +++++
>>>>>>     1 file changed, 5 insertions(+)
>>>>>>
>>>>>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>>>>>> index 4a8c08f970e3..ffc3188416f4 100644
>>>>>> --- a/fs/f2fs/gc.c
>>>>>> +++ b/fs/f2fs/gc.c
>>>>>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>>>>>             }
>>>>>>         }
>>>>>>     +    if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>>>>>> +        ret = -ENODATA;
>>>>>> +        goto out;
>>>>>> +    }
>>>>>> +
>>>>>>         /* get victim for GC_AT/AT_SSR */
>>>>>>         if (is_atgc) {
>>>>>>             lookup_victim_by_age(sbi, &p);


_______________________________________________
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] 13+ messages in thread

* Re: [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC
  2025-09-20  2:49             ` Liao Yuanhong via Linux-f2fs-devel
@ 2025-09-23  6:43               ` Chao Yu via Linux-f2fs-devel
  0 siblings, 0 replies; 13+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-09-23  6:43 UTC (permalink / raw)
  To: Liao Yuanhong, Jaegeuk Kim, open list:F2FS FILE SYSTEM, open list

On 9/20/25 10:49, Liao Yuanhong wrote:
> 
> On 9/18/2025 10:16 AM, Chao Yu wrote:
>> On 9/17/25 16:13, Liao Yuanhong wrote:
>>> On 9/17/2025 3:57 PM, Chao Yu wrote:
>>>> On 9/17/25 15:08, Liao Yuanhong wrote:
>>>>> On 9/15/2025 4:36 PM, Chao Yu wrote:
>>>>>> On 9/9/25 21:44, Liao Yuanhong wrote:
>>>>>>> When the proportion of dirty segments within a section exceeds the
>>>>>>> valid_thresh_ratio, the gc_cost of that section is set to UINT_MAX,
>>>>>>> indicating that these sections should not be released. However, if all
>>>>>>> section costs within the scanning range of get_victim() are UINT_MAX,
>>>>>>> background GC will still occur. Add a condition to prevent this situation.
>>>>>> For this case, f2fs_get_victim() will return 0, and f2fs_gc() will use unchanged
>>>>>> segno for GC?
>>>>>>
>>>>>> Thanks,
>>>>> You're right, segno won't update in this scenario, and this patch feature is redundant.
>>>> Oh, I meant, if f2fs_get_victim() fails to select a valid victim due to the reason you
>>>> described, f2fs_get_victim() will return 0, and f2fs_gc() will migrate segment #NULL_SEGNO?
>>>> Or am I missing something?
>>>>
>>>> Thanks,
>>> Yes. In this scenario, since it won't enter the|p.min_cost > cost|condition,|p.min_segno|will retain its initial value|||NULL_SEGNO|. This is consistent with what you described.
>> Do you have a script to reproduce this bug?
>>
>> Thanks,
> 
> I didn't explain it clearly. What I mean is that this patch is redundant, the original code is fine.

Oh, I see. I don't see any problem in f2fs_get_victim() as well.

Thanks,

> 
> 
> Thanks,
> 
> Liao
> 
>>>
>>> Thanks,
>>>
>>> Liao
>>>
>>>>> Thanks,
>>>>>
>>>>> Liao
>>>>>
>>>>>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>>>>>> ---
>>>>>>>     fs/f2fs/gc.c | 5 +++++
>>>>>>>     1 file changed, 5 insertions(+)
>>>>>>>
>>>>>>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
>>>>>>> index 4a8c08f970e3..ffc3188416f4 100644
>>>>>>> --- a/fs/f2fs/gc.c
>>>>>>> +++ b/fs/f2fs/gc.c
>>>>>>> @@ -936,6 +936,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,
>>>>>>>             }
>>>>>>>         }
>>>>>>>     +    if (f2fs_sb_has_blkzoned(sbi) && p.min_cost == UINT_MAX) {
>>>>>>> +        ret = -ENODATA;
>>>>>>> +        goto out;
>>>>>>> +    }
>>>>>>> +
>>>>>>>         /* get victim for GC_AT/AT_SSR */
>>>>>>>         if (is_atgc) {
>>>>>>>             lookup_victim_by_age(sbi, &p);



_______________________________________________
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] 13+ messages in thread

end of thread, other threads:[~2025-09-23  6:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 13:44 [f2fs-dev] [PATCH 0/2] f2fs: Some optimizations for background GC in Zoned UFS Liao Yuanhong via Linux-f2fs-devel
2025-09-09 13:44 ` [f2fs-dev] [PATCH 1/2] f2fs: Optimize excessive write operations caused by continuous background garbage collection " Liao Yuanhong via Linux-f2fs-devel
2025-09-15  8:25   ` Chao Yu via Linux-f2fs-devel
2025-09-16  2:28   ` Jaegeuk Kim via Linux-f2fs-devel
2025-09-17  7:15     ` Liao Yuanhong via Linux-f2fs-devel
2025-09-09 13:44 ` [f2fs-dev] [PATCH 2/2] f2fs: Enhance the subsequent logic of valid_thresh_ratio to prevent unnecessary background GC Liao Yuanhong via Linux-f2fs-devel
2025-09-15  8:36   ` Chao Yu via Linux-f2fs-devel
2025-09-17  7:08     ` Liao Yuanhong via Linux-f2fs-devel
2025-09-17  7:57       ` Chao Yu via Linux-f2fs-devel
2025-09-17  8:13         ` Liao Yuanhong via Linux-f2fs-devel
2025-09-18  2:16           ` Chao Yu via Linux-f2fs-devel
2025-09-20  2:49             ` Liao Yuanhong via Linux-f2fs-devel
2025-09-23  6:43               ` Chao Yu via Linux-f2fs-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).