* [PATCH] f2fs: introduce reserved_pin_section sysfs entry
@ 2025-06-12 14:05 Chao Yu
2025-06-13 5:11 ` [f2fs-dev] " wangzijie
0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2025-06-12 14:05 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu
This patch introduces /sys/fs/f2fs/<dev>/reserved_pin_section for tuning
@needed parameter of has_not_enough_free_secs(), if we configure it w/
zero, it can avoid f2fs_gc() as much as possible while fallocating on
pinned file.
Signed-off-by: Chao Yu <chao@kernel.org>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++
fs/f2fs/f2fs.h | 3 +++
fs/f2fs/file.c | 5 ++---
fs/f2fs/super.c | 3 +++
fs/f2fs/sysfs.c | 9 +++++++++
5 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index bf03263b9f46..c2a233f2a085 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -861,3 +861,12 @@ Description: This is a read-only entry to show the value of sb.s_encoding_flags,
SB_ENC_STRICT_MODE_FL 0x00000001
SB_ENC_NO_COMPAT_FALLBACK_FL 0x00000002
============================ ==========
+
+What: /sys/fs/f2fs/<disk>/reserved_pin_section
+Date: June 2025
+Contact: "Chao Yu" <chao@kernel.org>
+Description: This threshold is used to control triggering garbage collection while
+ fallocating on pinned file, so, it can guarantee there is enough free
+ reserved section before preallocating on pinned file.
+ By default, the value is ovp_sections, especially, for zoned ufs, the
+ value is 1.
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9333a22b9a01..fa27498202a3 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1724,6 +1724,9 @@ struct f2fs_sb_info {
/* for skip statistic */
unsigned long long skipped_gc_rwsem; /* FG_GC only */
+ /* free sections reserved for pinned file */
+ unsigned int reserved_pin_section;
+
/* threshold for gc trials on pinned files */
unsigned short gc_pin_file_threshold;
struct f2fs_rwsem pin_sem;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 696131e655ed..a909f79db178 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1887,9 +1887,8 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
}
}
- if (has_not_enough_free_secs(sbi, 0, f2fs_sb_has_blkzoned(sbi) ?
- ZONED_PIN_SEC_REQUIRED_COUNT :
- GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
+ if (has_not_enough_free_secs(sbi, 0,
+ sbi->reserved_pin_section)) {
f2fs_down_write(&sbi->gc_lock);
stat_inc_gc_call_count(sbi, FOREGROUND);
err = f2fs_gc(sbi, &gc_control);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 57adeff5ef25..48b97a95fd63 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4975,6 +4975,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
sbi->last_valid_block_count = sbi->total_valid_block_count;
sbi->reserved_blocks = 0;
sbi->current_reserved_blocks = 0;
+ sbi->reserved_pin_section = f2fs_sb_has_blkzoned(sbi) ?
+ ZONED_PIN_SEC_REQUIRED_COUNT :
+ GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi));
limit_reserve_root(sbi);
adjust_unusable_cap_perc(sbi);
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 75134d69a0bd..51be7ffb38c5 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -824,6 +824,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}
+ if (!strcmp(a->attr.name, "reserved_pin_section")) {
+ if (t > GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))
+ return -EINVAL;
+ *ui = (unsigned int)t;
+ return count;
+ }
+
*ui = (unsigned int)t;
return count;
@@ -1130,6 +1137,7 @@ F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
#endif
F2FS_SBI_GENERAL_RW_ATTR(carve_out);
+F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
/* STAT_INFO ATTR */
#ifdef CONFIG_F2FS_STAT_FS
@@ -1323,6 +1331,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(last_age_weight),
ATTR_LIST(max_read_extent_count),
ATTR_LIST(carve_out),
+ ATTR_LIST(reserved_pin_section),
NULL,
};
ATTRIBUTE_GROUPS(f2fs);
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: introduce reserved_pin_section sysfs entry
2025-06-12 14:05 [PATCH] f2fs: introduce reserved_pin_section sysfs entry Chao Yu
@ 2025-06-13 5:11 ` wangzijie
2025-06-13 5:31 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: wangzijie @ 2025-06-13 5:11 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: chao, jaegeuk, linux-kernel
> This patch introduces /sys/fs/f2fs/<dev>/reserved_pin_section for tuning
> @needed parameter of has_not_enough_free_secs(), if we configure it w/
> zero, it can avoid f2fs_gc() as much as possible while fallocating on
> pinned file.
>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++
> fs/f2fs/f2fs.h | 3 +++
> fs/f2fs/file.c | 5 ++---
> fs/f2fs/super.c | 3 +++
> fs/f2fs/sysfs.c | 9 +++++++++
> 5 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index bf03263b9f46..c2a233f2a085 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -861,3 +861,12 @@ Description: This is a read-only entry to show the value of sb.s_encoding_flags,
> SB_ENC_STRICT_MODE_FL 0x00000001
> SB_ENC_NO_COMPAT_FALLBACK_FL 0x00000002
> ============================ ==========
> +
> +What: /sys/fs/f2fs/<disk>/reserved_pin_section
> +Date: June 2025
> +Contact: "Chao Yu" <chao@kernel.org>
> +Description: This threshold is used to control triggering garbage collection while
> + fallocating on pinned file, so, it can guarantee there is enough free
> + reserved section before preallocating on pinned file.
> + By default, the value is ovp_sections, especially, for zoned ufs, the
> + value is 1.
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 9333a22b9a01..fa27498202a3 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1724,6 +1724,9 @@ struct f2fs_sb_info {
> /* for skip statistic */
> unsigned long long skipped_gc_rwsem; /* FG_GC only */
>
> + /* free sections reserved for pinned file */
> + unsigned int reserved_pin_section;
> +
> /* threshold for gc trials on pinned files */
> unsigned short gc_pin_file_threshold;
> struct f2fs_rwsem pin_sem;
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 696131e655ed..a909f79db178 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1887,9 +1887,8 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
> }
> }
>
> - if (has_not_enough_free_secs(sbi, 0, f2fs_sb_has_blkzoned(sbi) ?
> - ZONED_PIN_SEC_REQUIRED_COUNT :
> - GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
> + if (has_not_enough_free_secs(sbi, 0,
> + sbi->reserved_pin_section)) {
> f2fs_down_write(&sbi->gc_lock);
> stat_inc_gc_call_count(sbi, FOREGROUND);
> err = f2fs_gc(sbi, &gc_control);
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 57adeff5ef25..48b97a95fd63 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -4975,6 +4975,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
> sbi->last_valid_block_count = sbi->total_valid_block_count;
> sbi->reserved_blocks = 0;
> sbi->current_reserved_blocks = 0;
> + sbi->reserved_pin_section = f2fs_sb_has_blkzoned(sbi) ?
> + ZONED_PIN_SEC_REQUIRED_COUNT :
> + GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi));
> limit_reserve_root(sbi);
> adjust_unusable_cap_perc(sbi);
Hi Chao,
It seems like we cannot use overprovision_segments(sbi) directly before f2fs_build_segment_manager().
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 75134d69a0bd..51be7ffb38c5 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -824,6 +824,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> return count;
> }
>
> + if (!strcmp(a->attr.name, "reserved_pin_section")) {
> + if (t > GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))
> + return -EINVAL;
> + *ui = (unsigned int)t;
> + return count;
> + }
> +
> *ui = (unsigned int)t;
>
> return count;
> @@ -1130,6 +1137,7 @@ F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
> F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
> #endif
> F2FS_SBI_GENERAL_RW_ATTR(carve_out);
> +F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
>
> /* STAT_INFO ATTR */
> #ifdef CONFIG_F2FS_STAT_FS
> @@ -1323,6 +1331,7 @@ static struct attribute *f2fs_attrs[] = {
> ATTR_LIST(last_age_weight),
> ATTR_LIST(max_read_extent_count),
> ATTR_LIST(carve_out),
> + ATTR_LIST(reserved_pin_section),
> NULL,
> };
> ATTRIBUTE_GROUPS(f2fs);
> --
> 2.40.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] 3+ messages in thread
* Re: [f2fs-dev] [PATCH] f2fs: introduce reserved_pin_section sysfs entry
2025-06-13 5:11 ` [f2fs-dev] " wangzijie
@ 2025-06-13 5:31 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2025-06-13 5:31 UTC (permalink / raw)
To: wangzijie, linux-f2fs-devel; +Cc: chao, jaegeuk, linux-kernel
On 2025/6/13 13:11, wangzijie wrote:
>> This patch introduces /sys/fs/f2fs/<dev>/reserved_pin_section for tuning
>> @needed parameter of has_not_enough_free_secs(), if we configure it w/
>> zero, it can avoid f2fs_gc() as much as possible while fallocating on
>> pinned file.
>>
>> Signed-off-by: Chao Yu <chao@kernel.org>
>> ---
>> Documentation/ABI/testing/sysfs-fs-f2fs | 9 +++++++++
>> fs/f2fs/f2fs.h | 3 +++
>> fs/f2fs/file.c | 5 ++---
>> fs/f2fs/super.c | 3 +++
>> fs/f2fs/sysfs.c | 9 +++++++++
>> 5 files changed, 26 insertions(+), 3 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
>> index bf03263b9f46..c2a233f2a085 100644
>> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
>> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
>> @@ -861,3 +861,12 @@ Description: This is a read-only entry to show the value of sb.s_encoding_flags,
>> SB_ENC_STRICT_MODE_FL 0x00000001
>> SB_ENC_NO_COMPAT_FALLBACK_FL 0x00000002
>> ============================ ==========
>> +
>> +What: /sys/fs/f2fs/<disk>/reserved_pin_section
>> +Date: June 2025
>> +Contact: "Chao Yu" <chao@kernel.org>
>> +Description: This threshold is used to control triggering garbage collection while
>> + fallocating on pinned file, so, it can guarantee there is enough free
>> + reserved section before preallocating on pinned file.
>> + By default, the value is ovp_sections, especially, for zoned ufs, the
>> + value is 1.
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 9333a22b9a01..fa27498202a3 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -1724,6 +1724,9 @@ struct f2fs_sb_info {
>> /* for skip statistic */
>> unsigned long long skipped_gc_rwsem; /* FG_GC only */
>>
>> + /* free sections reserved for pinned file */
>> + unsigned int reserved_pin_section;
>> +
>> /* threshold for gc trials on pinned files */
>> unsigned short gc_pin_file_threshold;
>> struct f2fs_rwsem pin_sem;
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 696131e655ed..a909f79db178 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1887,9 +1887,8 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
>> }
>> }
>>
>> - if (has_not_enough_free_secs(sbi, 0, f2fs_sb_has_blkzoned(sbi) ?
>> - ZONED_PIN_SEC_REQUIRED_COUNT :
>> - GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
>> + if (has_not_enough_free_secs(sbi, 0,
>> + sbi->reserved_pin_section)) {
>> f2fs_down_write(&sbi->gc_lock);
>> stat_inc_gc_call_count(sbi, FOREGROUND);
>> err = f2fs_gc(sbi, &gc_control);
>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>> index 57adeff5ef25..48b97a95fd63 100644
>> --- a/fs/f2fs/super.c
>> +++ b/fs/f2fs/super.c
>> @@ -4975,6 +4975,9 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
>> sbi->last_valid_block_count = sbi->total_valid_block_count;
>> sbi->reserved_blocks = 0;
>> sbi->current_reserved_blocks = 0;
>> + sbi->reserved_pin_section = f2fs_sb_has_blkzoned(sbi) ?
>> + ZONED_PIN_SEC_REQUIRED_COUNT :
>> + GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi));
>> limit_reserve_root(sbi);
>> adjust_unusable_cap_perc(sbi);
>
> Hi Chao,
> It seems like we cannot use overprovision_segments(sbi) directly before f2fs_build_segment_manager().
Oops, ovp_segments is in f2fs_sm_info, I missed that, let me fix in v2.
Thanks,
>
>> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
>> index 75134d69a0bd..51be7ffb38c5 100644
>> --- a/fs/f2fs/sysfs.c
>> +++ b/fs/f2fs/sysfs.c
>> @@ -824,6 +824,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
>> return count;
>> }
>>
>> + if (!strcmp(a->attr.name, "reserved_pin_section")) {
>> + if (t > GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))
>> + return -EINVAL;
>> + *ui = (unsigned int)t;
>> + return count;
>> + }
>> +
>> *ui = (unsigned int)t;
>>
>> return count;
>> @@ -1130,6 +1137,7 @@ F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
>> F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
>> #endif
>> F2FS_SBI_GENERAL_RW_ATTR(carve_out);
>> +F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
>>
>> /* STAT_INFO ATTR */
>> #ifdef CONFIG_F2FS_STAT_FS
>> @@ -1323,6 +1331,7 @@ static struct attribute *f2fs_attrs[] = {
>> ATTR_LIST(last_age_weight),
>> ATTR_LIST(max_read_extent_count),
>> ATTR_LIST(carve_out),
>> + ATTR_LIST(reserved_pin_section),
>> NULL,
>> };
>> ATTRIBUTE_GROUPS(f2fs);
>> --
>> 2.40.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] 3+ messages in thread
end of thread, other threads:[~2025-06-13 5:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 14:05 [PATCH] f2fs: introduce reserved_pin_section sysfs entry Chao Yu
2025-06-13 5:11 ` [f2fs-dev] " wangzijie
2025-06-13 5:31 ` Chao Yu
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).