* [PATCH] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
@ 2025-08-05 13:22 Liao Yuanhong
2025-08-06 7:09 ` [PATCH v2] " Liao Yuanhong
2025-08-07 7:44 ` [PATCH v3] " Liao Yuanhong
0 siblings, 2 replies; 6+ messages in thread
From: Liao Yuanhong @ 2025-08-05 13:22 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, liaoyuanhong
Currently, we have encountered some issues while testing ZUFS. In
situations near the storage limit (e.g., 50GB remaining), and after
simulating fragmentation by repeatedly writing and deleting data, we found
that application installation and startup tests conducted after idling for
a few minutes take significantly longer several times that of traditional
UFS. Tracing the operations revealed that the majority of I/Os were issued
by background GC, which blocks normal I/O operations.
Under normal circumstances, ZUFS indeed requires more background GC and
employs a more aggressive GC strategy. However, I aim to find a way to
minimize the impact on regular I/O operations under these near-limit
conditions. To address this, I have introduced a bggc_block_io feature,
which controls the prioritization of background GC in the presence of I/Os.
This switch can be adjusted at the framework level to implement different
strategies. If set to ALL_IO_PRIOR, all background GC operations will be
skipped during active I/O issuance. The default option remains consistent
with the current strategy, ensuring no change in behavior.
Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
fs/f2fs/f2fs.h | 12 +++++++++++-
fs/f2fs/super.c | 1 +
fs/f2fs/sysfs.c | 9 +++++++++
4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index bc0e7fefc39d..12fda11d4da5 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -883,3 +883,16 @@ Date: June 2025
Contact: "Daeho Jeong" <daehojeong@google.com>
Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
Default: 1
+
+What: /sys/fs/f2fs/<disk>/bggc_block_io
+Date: August 2025
+Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
+Description: Used to adjust the BG_GC priority when issuing IO, with a default value
+ of 1.
+
+ ================== =============================================
+ value description
+ bggc_block_io = 0 Prioritize background GC
+ bggc_block_io = 1 Stop background GC only when issuing read I/O
+ bggc_block_io = 2 Stop background GC when issuing I/O
+ ================== =============================================
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 46be7560548c..22ea648436ec 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
};
+enum bggc_block_io_policy {
+ BGGC_PRIOR,
+ READ_IO_PRIOR,
+ ALL_IO_PRIOR,
+};
+
/*
* An implementation of an rwsem that is explicitly unfair to readers. This
* prevents priority inversion when a low-priority reader acquires the read lock
@@ -1608,6 +1614,8 @@ struct f2fs_sb_info {
unsigned int max_open_zones; /* max open zone resources of the zoned device */
/* For adjust the priority writing position of data in zone UFS */
unsigned int blkzone_alloc_policy;
+ /* Used to adjust the BG_GC priority when issuing IO */
+ unsigned int bggc_block_io;
#endif
/* for node-related operations */
@@ -2999,7 +3007,9 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
return true;
if (zoned_gc) {
- if (is_inflight_read_io(sbi))
+ if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
+ return false;
+ if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
return false;
} else {
if (is_inflight_io(sbi, type))
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index e16c4e2830c2..99f46b8855ec 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4632,6 +4632,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
#ifdef CONFIG_BLK_DEV_ZONED
sbi->max_open_zones = UINT_MAX;
sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
+ sbi->bggc_block_io = READ_IO_PRIOR;
#endif
for (i = 0; i < max_devices; i++) {
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index f736052dea50..efea15209788 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -674,6 +674,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
sbi->blkzone_alloc_policy = t;
return count;
}
+
+ if (!strcmp(a->attr.name, "bggc_block_io")) {
+ if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
+ return -EINVAL;
+ sbi->bggc_block_io = t;
+ return count;
+ }
#endif
#ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -1172,6 +1179,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
#ifdef CONFIG_BLK_DEV_ZONED
F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
+F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
#endif
F2FS_SBI_GENERAL_RW_ATTR(carve_out);
F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
@@ -1342,6 +1350,7 @@ static struct attribute *f2fs_attrs[] = {
#ifdef CONFIG_BLK_DEV_ZONED
ATTR_LIST(unusable_blocks_per_sec),
ATTR_LIST(blkzone_alloc_policy),
+ ATTR_LIST(bggc_block_io),
#endif
#ifdef CONFIG_F2FS_FS_COMPRESSION
ATTR_LIST(compr_written_block),
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
2025-08-05 13:22 [PATCH] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO Liao Yuanhong
@ 2025-08-06 7:09 ` Liao Yuanhong
2025-08-07 8:38 ` Chao Yu
2025-08-07 7:44 ` [PATCH v3] " Liao Yuanhong
1 sibling, 1 reply; 6+ messages in thread
From: Liao Yuanhong @ 2025-08-06 7:09 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Liao Yuanhong
Currently, we have encountered some issues while testing ZUFS. In
situations near the storage limit (e.g., 50GB remaining), and after
simulating fragmentation by repeatedly writing and deleting data, we found
that application installation and startup tests conducted after idling for
a few minutes take significantly longer several times that of traditional
UFS. Tracing the operations revealed that the majority of I/Os were issued
by background GC, which blocks normal I/O operations.
Under normal circumstances, ZUFS indeed requires more background GC and
employs a more aggressive GC strategy. However, I aim to find a way to
minimize the impact on regular I/O operations under these near-limit
conditions. To address this, I have introduced a bggc_block_io feature,
which controls the prioritization of background GC in the presence of I/Os.
This switch can be adjusted at the framework level to implement different
strategies. If set to ALL_IO_PRIOR, all background GC operations will be
skipped during active I/O issuance. The default option remains consistent
with the current strategy, ensuring no change in behavior.
Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
Changes in v2:
Non ZUFS can also be adjusted through this option.
---
Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
fs/f2fs/f2fs.h | 18 +++++++++++-------
fs/f2fs/super.c | 2 ++
fs/f2fs/sysfs.c | 9 +++++++++
4 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index bc0e7fefc39d..12fda11d4da5 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -883,3 +883,16 @@ Date: June 2025
Contact: "Daeho Jeong" <daehojeong@google.com>
Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
Default: 1
+
+What: /sys/fs/f2fs/<disk>/bggc_block_io
+Date: August 2025
+Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
+Description: Used to adjust the BG_GC priority when issuing IO, with a default value
+ of 1.
+
+ ================== =============================================
+ value description
+ bggc_block_io = 0 Prioritize background GC
+ bggc_block_io = 1 Stop background GC only when issuing read I/O
+ bggc_block_io = 2 Stop background GC when issuing I/O
+ ================== =============================================
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 46be7560548c..fe41b733fbc2 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
};
+enum bggc_block_io_policy {
+ BGGC_PRIOR,
+ READ_IO_PRIOR,
+ ALL_IO_PRIOR,
+};
+
/*
* An implementation of an rwsem that is explicitly unfair to readers. This
* prevents priority inversion when a low-priority reader acquires the read lock
@@ -1804,6 +1810,7 @@ struct f2fs_sb_info {
spinlock_t dev_lock; /* protect dirty_device */
bool aligned_blksize; /* all devices has the same logical blksize */
unsigned int first_seq_zone_segno; /* first segno in sequential zone */
+ unsigned int bggc_block_io; /* For adjust the BG_GC priority when issuing IO */
/* For write statistics */
u64 sectors_written_start;
@@ -2998,13 +3005,10 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
if (sbi->gc_mode == GC_URGENT_HIGH)
return true;
- if (zoned_gc) {
- if (is_inflight_read_io(sbi))
- return false;
- } else {
- if (is_inflight_io(sbi, type))
- return false;
- }
+ if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
+ return false;
+ if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
+ return false;
if (sbi->gc_mode == GC_URGENT_MID)
return true;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index e16c4e2830c2..a21cecc5424e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4629,9 +4629,11 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
sbi->aligned_blksize = true;
+ sbi->bggc_block_io = ALL_IO_PRIOR;
#ifdef CONFIG_BLK_DEV_ZONED
sbi->max_open_zones = UINT_MAX;
sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
+ sbi->bggc_block_io = READ_IO_PRIOR;
#endif
for (i = 0; i < max_devices; i++) {
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index f736052dea50..efea15209788 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -674,6 +674,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
sbi->blkzone_alloc_policy = t;
return count;
}
+
+ if (!strcmp(a->attr.name, "bggc_block_io")) {
+ if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
+ return -EINVAL;
+ sbi->bggc_block_io = t;
+ return count;
+ }
#endif
#ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -1172,6 +1179,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
#ifdef CONFIG_BLK_DEV_ZONED
F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
+F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
#endif
F2FS_SBI_GENERAL_RW_ATTR(carve_out);
F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
@@ -1342,6 +1350,7 @@ static struct attribute *f2fs_attrs[] = {
#ifdef CONFIG_BLK_DEV_ZONED
ATTR_LIST(unusable_blocks_per_sec),
ATTR_LIST(blkzone_alloc_policy),
+ ATTR_LIST(bggc_block_io),
#endif
#ifdef CONFIG_F2FS_FS_COMPRESSION
ATTR_LIST(compr_written_block),
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
2025-08-05 13:22 [PATCH] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO Liao Yuanhong
2025-08-06 7:09 ` [PATCH v2] " Liao Yuanhong
@ 2025-08-07 7:44 ` Liao Yuanhong
1 sibling, 0 replies; 6+ messages in thread
From: Liao Yuanhong @ 2025-08-07 7:44 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, Liao Yuanhong
Currently, we have encountered some issues while testing ZUFS. In
situations near the storage limit (e.g., 50GB remaining), and after
simulating fragmentation by repeatedly writing and deleting data, we found
that application installation and startup tests conducted after idling for
a few minutes take significantly longer several times that of traditional
UFS. Tracing the operations revealed that the majority of I/Os were issued
by background GC, which blocks normal I/O operations.
Under normal circumstances, ZUFS indeed requires more background GC and
employs a more aggressive GC strategy. However, I aim to find a way to
minimize the impact on regular I/O operations under these near-limit
conditions. To address this, I have introduced a bggc_block_io feature,
which controls the prioritization of background GC in the presence of I/Os.
This switch can be adjusted at the framework level to implement different
strategies. If set to ALL_IO_PRIOR, all background GC operations will be
skipped during active I/O issuance. The default option remains consistent
with the current strategy, ensuring no change in behavior.
---
Changes in v3:
Modified the issue where it does not work after closing
CONFIG_BLK_DEV_ZONED.
Changes in v2:
Non ZUFS can also be adjusted through this option.
Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
fs/f2fs/f2fs.h | 18 +++++++++++-------
fs/f2fs/super.c | 2 ++
fs/f2fs/sysfs.c | 9 +++++++++
4 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index bc0e7fefc39d..12fda11d4da5 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -883,3 +883,16 @@ Date: June 2025
Contact: "Daeho Jeong" <daehojeong@google.com>
Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
Default: 1
+
+What: /sys/fs/f2fs/<disk>/bggc_block_io
+Date: August 2025
+Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
+Description: Used to adjust the BG_GC priority when issuing IO, with a default value
+ of 1.
+
+ ================== =============================================
+ value description
+ bggc_block_io = 0 Prioritize background GC
+ bggc_block_io = 1 Stop background GC only when issuing read I/O
+ bggc_block_io = 2 Stop background GC when issuing I/O
+ ================== =============================================
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 46be7560548c..fe41b733fbc2 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
};
+enum bggc_block_io_policy {
+ BGGC_PRIOR,
+ READ_IO_PRIOR,
+ ALL_IO_PRIOR,
+};
+
/*
* An implementation of an rwsem that is explicitly unfair to readers. This
* prevents priority inversion when a low-priority reader acquires the read lock
@@ -1804,6 +1810,7 @@ struct f2fs_sb_info {
spinlock_t dev_lock; /* protect dirty_device */
bool aligned_blksize; /* all devices has the same logical blksize */
unsigned int first_seq_zone_segno; /* first segno in sequential zone */
+ unsigned int bggc_block_io; /* For adjust the BG_GC priority when issuing IO */
/* For write statistics */
u64 sectors_written_start;
@@ -2998,13 +3005,10 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
if (sbi->gc_mode == GC_URGENT_HIGH)
return true;
- if (zoned_gc) {
- if (is_inflight_read_io(sbi))
- return false;
- } else {
- if (is_inflight_io(sbi, type))
- return false;
- }
+ if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
+ return false;
+ if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
+ return false;
if (sbi->gc_mode == GC_URGENT_MID)
return true;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index e16c4e2830c2..a21cecc5424e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4629,9 +4629,11 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
sbi->aligned_blksize = true;
+ sbi->bggc_block_io = ALL_IO_PRIOR;
#ifdef CONFIG_BLK_DEV_ZONED
sbi->max_open_zones = UINT_MAX;
sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
+ sbi->bggc_block_io = READ_IO_PRIOR;
#endif
for (i = 0; i < max_devices; i++) {
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index f736052dea50..381f29ae90fc 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -866,6 +866,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}
+ if (!strcmp(a->attr.name, "bggc_block_io")) {
+ if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
+ return -EINVAL;
+ sbi->bggc_block_io = t;
+ return count;
+ }
+
*ui = (unsigned int)t;
return count;
@@ -1175,6 +1182,7 @@ F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
#endif
F2FS_SBI_GENERAL_RW_ATTR(carve_out);
F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
+F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
/* STAT_INFO ATTR */
#ifdef CONFIG_F2FS_STAT_FS
@@ -1303,6 +1311,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(discard_idle_interval),
ATTR_LIST(gc_idle_interval),
ATTR_LIST(umount_discard_timeout),
+ ATTR_LIST(bggc_block_io),
#ifdef CONFIG_F2FS_IOSTAT
ATTR_LIST(iostat_enable),
ATTR_LIST(iostat_period_ms),
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
2025-08-06 7:09 ` [PATCH v2] " Liao Yuanhong
@ 2025-08-07 8:38 ` Chao Yu
2025-08-07 9:12 ` Liao Yuanhong
0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu @ 2025-08-07 8:38 UTC (permalink / raw)
To: Liao Yuanhong, Jaegeuk Kim; +Cc: chao, linux-f2fs-devel, linux-kernel
On 8/6/25 15:09, Liao Yuanhong wrote:
> Currently, we have encountered some issues while testing ZUFS. In
> situations near the storage limit (e.g., 50GB remaining), and after
> simulating fragmentation by repeatedly writing and deleting data, we found
> that application installation and startup tests conducted after idling for
> a few minutes take significantly longer several times that of traditional
> UFS. Tracing the operations revealed that the majority of I/Os were issued
> by background GC, which blocks normal I/O operations.
>
> Under normal circumstances, ZUFS indeed requires more background GC and
> employs a more aggressive GC strategy. However, I aim to find a way to
> minimize the impact on regular I/O operations under these near-limit
> conditions. To address this, I have introduced a bggc_block_io feature,
> which controls the prioritization of background GC in the presence of I/Os.
> This switch can be adjusted at the framework level to implement different
> strategies. If set to ALL_IO_PRIOR, all background GC operations will be
> skipped during active I/O issuance. The default option remains consistent
> with the current strategy, ensuring no change in behavior.
>
> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
> ---
> Changes in v2:
> Non ZUFS can also be adjusted through this option.
> ---
> Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
> fs/f2fs/f2fs.h | 18 +++++++++++-------
> fs/f2fs/super.c | 2 ++
> fs/f2fs/sysfs.c | 9 +++++++++
> 4 files changed, 35 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index bc0e7fefc39d..12fda11d4da5 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -883,3 +883,16 @@ Date: June 2025
> Contact: "Daeho Jeong" <daehojeong@google.com>
> Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
> Default: 1
> +
> +What: /sys/fs/f2fs/<disk>/bggc_block_io
> +Date: August 2025
> +Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
> +Description: Used to adjust the BG_GC priority when issuing IO, with a default value
> + of 1.
Default value is 2 if CONFIG_BLK_DEV_ZONED is off?
Thanks,
> +
> + ================== =============================================
> + value description
> + bggc_block_io = 0 Prioritize background GC
> + bggc_block_io = 1 Stop background GC only when issuing read I/O
> + bggc_block_io = 2 Stop background GC when issuing I/O
> + ================== =============================================
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 46be7560548c..fe41b733fbc2 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
> BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
> };
>
> +enum bggc_block_io_policy {
> + BGGC_PRIOR,
> + READ_IO_PRIOR,
> + ALL_IO_PRIOR,
> +};
> +
> /*
> * An implementation of an rwsem that is explicitly unfair to readers. This
> * prevents priority inversion when a low-priority reader acquires the read lock
> @@ -1804,6 +1810,7 @@ struct f2fs_sb_info {
> spinlock_t dev_lock; /* protect dirty_device */
> bool aligned_blksize; /* all devices has the same logical blksize */
> unsigned int first_seq_zone_segno; /* first segno in sequential zone */
> + unsigned int bggc_block_io; /* For adjust the BG_GC priority when issuing IO */
>
> /* For write statistics */
> u64 sectors_written_start;
> @@ -2998,13 +3005,10 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
> if (sbi->gc_mode == GC_URGENT_HIGH)
> return true;
>
> - if (zoned_gc) {
> - if (is_inflight_read_io(sbi))
> - return false;
> - } else {
> - if (is_inflight_io(sbi, type))
> - return false;
> - }
> + if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
> + return false;
> + if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
> + return false;
>
> if (sbi->gc_mode == GC_URGENT_MID)
> return true;
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index e16c4e2830c2..a21cecc5424e 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -4629,9 +4629,11 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
>
> logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
> sbi->aligned_blksize = true;
> + sbi->bggc_block_io = ALL_IO_PRIOR;
> #ifdef CONFIG_BLK_DEV_ZONED
> sbi->max_open_zones = UINT_MAX;
> sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
> + sbi->bggc_block_io = READ_IO_PRIOR;
> #endif
>
> for (i = 0; i < max_devices; i++) {
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index f736052dea50..efea15209788 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -674,6 +674,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> sbi->blkzone_alloc_policy = t;
> return count;
> }
> +
> + if (!strcmp(a->attr.name, "bggc_block_io")) {
> + if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
> + return -EINVAL;
> + sbi->bggc_block_io = t;
> + return count;
> + }
> #endif
>
> #ifdef CONFIG_F2FS_FS_COMPRESSION
> @@ -1172,6 +1179,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
> #ifdef CONFIG_BLK_DEV_ZONED
> F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
> F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
> +F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
> #endif
> F2FS_SBI_GENERAL_RW_ATTR(carve_out);
> F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
> @@ -1342,6 +1350,7 @@ static struct attribute *f2fs_attrs[] = {
> #ifdef CONFIG_BLK_DEV_ZONED
> ATTR_LIST(unusable_blocks_per_sec),
> ATTR_LIST(blkzone_alloc_policy),
> + ATTR_LIST(bggc_block_io),
> #endif
> #ifdef CONFIG_F2FS_FS_COMPRESSION
> ATTR_LIST(compr_written_block),
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
2025-08-07 8:38 ` Chao Yu
@ 2025-08-07 9:12 ` Liao Yuanhong
2025-08-08 0:50 ` Chao Yu
0 siblings, 1 reply; 6+ messages in thread
From: Liao Yuanhong @ 2025-08-07 9:12 UTC (permalink / raw)
To: Chao Yu, Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel
On 8/7/2025 4:38 PM, Chao Yu wrote:
> On 8/6/25 15:09, Liao Yuanhong wrote:
>> Currently, we have encountered some issues while testing ZUFS. In
>> situations near the storage limit (e.g., 50GB remaining), and after
>> simulating fragmentation by repeatedly writing and deleting data, we found
>> that application installation and startup tests conducted after idling for
>> a few minutes take significantly longer several times that of traditional
>> UFS. Tracing the operations revealed that the majority of I/Os were issued
>> by background GC, which blocks normal I/O operations.
>>
>> Under normal circumstances, ZUFS indeed requires more background GC and
>> employs a more aggressive GC strategy. However, I aim to find a way to
>> minimize the impact on regular I/O operations under these near-limit
>> conditions. To address this, I have introduced a bggc_block_io feature,
>> which controls the prioritization of background GC in the presence of I/Os.
>> This switch can be adjusted at the framework level to implement different
>> strategies. If set to ALL_IO_PRIOR, all background GC operations will be
>> skipped during active I/O issuance. The default option remains consistent
>> with the current strategy, ensuring no change in behavior.
>>
>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>> ---
>> Changes in v2:
>> Non ZUFS can also be adjusted through this option.
>> ---
>> Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
>> fs/f2fs/f2fs.h | 18 +++++++++++-------
>> fs/f2fs/super.c | 2 ++
>> fs/f2fs/sysfs.c | 9 +++++++++
>> 4 files changed, 35 insertions(+), 7 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
>> index bc0e7fefc39d..12fda11d4da5 100644
>> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
>> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
>> @@ -883,3 +883,16 @@ Date: June 2025
>> Contact: "Daeho Jeong" <daehojeong@google.com>
>> Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
>> Default: 1
>> +
>> +What: /sys/fs/f2fs/<disk>/bggc_block_io
>> +Date: August 2025
>> +Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
>> +Description: Used to adjust the BG_GC priority when issuing IO, with a default value
>> + of 1.
> Default value is 2 if CONFIG_BLK_DEV_ZONED is off?
>
> Thanks,
Sorry, I missed updating the description. Is it more reasonable to set
the default value to 0 for versions that disable CONFIG_BLK_DEV_ZONED?
If so, I will submit a new version to correct the description and
initial value settings here. Thanks, Liao
>> +
>> + ================== =============================================
>> + value description
>> + bggc_block_io = 0 Prioritize background GC
>> + bggc_block_io = 1 Stop background GC only when issuing read I/O
>> + bggc_block_io = 2 Stop background GC when issuing I/O
>> + ================== =============================================
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 46be7560548c..fe41b733fbc2 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
>> BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
>> };
>>
>> +enum bggc_block_io_policy {
>> + BGGC_PRIOR,
>> + READ_IO_PRIOR,
>> + ALL_IO_PRIOR,
>> +};
>> +
>> /*
>> * An implementation of an rwsem that is explicitly unfair to readers. This
>> * prevents priority inversion when a low-priority reader acquires the read lock
>> @@ -1804,6 +1810,7 @@ struct f2fs_sb_info {
>> spinlock_t dev_lock; /* protect dirty_device */
>> bool aligned_blksize; /* all devices has the same logical blksize */
>> unsigned int first_seq_zone_segno; /* first segno in sequential zone */
>> + unsigned int bggc_block_io; /* For adjust the BG_GC priority when issuing IO */
>>
>> /* For write statistics */
>> u64 sectors_written_start;
>> @@ -2998,13 +3005,10 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
>> if (sbi->gc_mode == GC_URGENT_HIGH)
>> return true;
>>
>> - if (zoned_gc) {
>> - if (is_inflight_read_io(sbi))
>> - return false;
>> - } else {
>> - if (is_inflight_io(sbi, type))
>> - return false;
>> - }
>> + if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
>> + return false;
>> + if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
>> + return false;
>>
>> if (sbi->gc_mode == GC_URGENT_MID)
>> return true;
>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>> index e16c4e2830c2..a21cecc5424e 100644
>> --- a/fs/f2fs/super.c
>> +++ b/fs/f2fs/super.c
>> @@ -4629,9 +4629,11 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
>>
>> logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
>> sbi->aligned_blksize = true;
>> + sbi->bggc_block_io = ALL_IO_PRIOR;
>> #ifdef CONFIG_BLK_DEV_ZONED
>> sbi->max_open_zones = UINT_MAX;
>> sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
>> + sbi->bggc_block_io = READ_IO_PRIOR;
>> #endif
>>
>> for (i = 0; i < max_devices; i++) {
>> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
>> index f736052dea50..efea15209788 100644
>> --- a/fs/f2fs/sysfs.c
>> +++ b/fs/f2fs/sysfs.c
>> @@ -674,6 +674,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
>> sbi->blkzone_alloc_policy = t;
>> return count;
>> }
>> +
>> + if (!strcmp(a->attr.name, "bggc_block_io")) {
>> + if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
>> + return -EINVAL;
>> + sbi->bggc_block_io = t;
>> + return count;
>> + }
>> #endif
>>
>> #ifdef CONFIG_F2FS_FS_COMPRESSION
>> @@ -1172,6 +1179,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
>> #ifdef CONFIG_BLK_DEV_ZONED
>> F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
>> F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
>> +F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
>> #endif
>> F2FS_SBI_GENERAL_RW_ATTR(carve_out);
>> F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
>> @@ -1342,6 +1350,7 @@ static struct attribute *f2fs_attrs[] = {
>> #ifdef CONFIG_BLK_DEV_ZONED
>> ATTR_LIST(unusable_blocks_per_sec),
>> ATTR_LIST(blkzone_alloc_policy),
>> + ATTR_LIST(bggc_block_io),
>> #endif
>> #ifdef CONFIG_F2FS_FS_COMPRESSION
>> ATTR_LIST(compr_written_block),
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO
2025-08-07 9:12 ` Liao Yuanhong
@ 2025-08-08 0:50 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2025-08-08 0:50 UTC (permalink / raw)
To: Liao Yuanhong, Jaegeuk Kim; +Cc: chao, linux-f2fs-devel, linux-kernel
On 2025/8/7 17:12, Liao Yuanhong wrote:
>
> On 8/7/2025 4:38 PM, Chao Yu wrote:
>> On 8/6/25 15:09, Liao Yuanhong wrote:
>>> Currently, we have encountered some issues while testing ZUFS. In
>>> situations near the storage limit (e.g., 50GB remaining), and after
>>> simulating fragmentation by repeatedly writing and deleting data, we found
>>> that application installation and startup tests conducted after idling for
>>> a few minutes take significantly longer several times that of traditional
>>> UFS. Tracing the operations revealed that the majority of I/Os were issued
>>> by background GC, which blocks normal I/O operations.
>>>
>>> Under normal circumstances, ZUFS indeed requires more background GC and
>>> employs a more aggressive GC strategy. However, I aim to find a way to
>>> minimize the impact on regular I/O operations under these near-limit
>>> conditions. To address this, I have introduced a bggc_block_io feature,
>>> which controls the prioritization of background GC in the presence of I/Os.
>>> This switch can be adjusted at the framework level to implement different
>>> strategies. If set to ALL_IO_PRIOR, all background GC operations will be
>>> skipped during active I/O issuance. The default option remains consistent
>>> with the current strategy, ensuring no change in behavior.
>>>
>>> Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
>>> ---
>>> Changes in v2:
>>> Non ZUFS can also be adjusted through this option.
>>> ---
>>> Documentation/ABI/testing/sysfs-fs-f2fs | 13 +++++++++++++
>>> fs/f2fs/f2fs.h | 18 +++++++++++-------
>>> fs/f2fs/super.c | 2 ++
>>> fs/f2fs/sysfs.c | 9 +++++++++
>>> 4 files changed, 35 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
>>> index bc0e7fefc39d..12fda11d4da5 100644
>>> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
>>> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
>>> @@ -883,3 +883,16 @@ Date: June 2025
>>> Contact: "Daeho Jeong" <daehojeong@google.com>
>>> Description: Control GC algorithm for boost GC. 0: cost benefit, 1: greedy
>>> Default: 1
>>> +
>>> +What: /sys/fs/f2fs/<disk>/bggc_block_io
>>> +Date: August 2025
>>> +Contact: "Liao Yuanhong" <liaoyuanhong@vivo.com>
>>> +Description: Used to adjust the BG_GC priority when issuing IO, with a default value
>>> + of 1.
>> Default value is 2 if CONFIG_BLK_DEV_ZONED is off?
>>
>> Thanks,
>
> Sorry, I missed updating the description. Is it more reasonable to set the default value to 0 for versions that disable CONFIG_BLK_DEV_ZONED? If so, I will submit a new version to correct the description and initial value settings here. Thanks, Liao
Before this patch, the default behavior is something like ALL_IO_PRIOR?
What do you think of defining ALL_IO_PRIOR w/ 0, and use it by default?
Thanks,
>
>>> +
>>> + ================== =============================================
>>> + value description
>>> + bggc_block_io = 0 Prioritize background GC
>>> + bggc_block_io = 1 Stop background GC only when issuing read I/O
>>> + bggc_block_io = 2 Stop background GC when issuing I/O
>>> + ================== =============================================
>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>> index 46be7560548c..fe41b733fbc2 100644
>>> --- a/fs/f2fs/f2fs.h
>>> +++ b/fs/f2fs/f2fs.h
>>> @@ -155,6 +155,12 @@ enum blkzone_allocation_policy {
>>> BLKZONE_ALLOC_PRIOR_CONV, /* Prioritize writing to conventional zones */
>>> };
>>> +enum bggc_block_io_policy {
>>> + BGGC_PRIOR,
>>> + READ_IO_PRIOR,
>>> + ALL_IO_PRIOR,
>>> +};
>>> +
>>> /*
>>> * An implementation of an rwsem that is explicitly unfair to readers. This
>>> * prevents priority inversion when a low-priority reader acquires the read lock
>>> @@ -1804,6 +1810,7 @@ struct f2fs_sb_info {
>>> spinlock_t dev_lock; /* protect dirty_device */
>>> bool aligned_blksize; /* all devices has the same logical blksize */
>>> unsigned int first_seq_zone_segno; /* first segno in sequential zone */
>>> + unsigned int bggc_block_io; /* For adjust the BG_GC priority when issuing IO */
>>> /* For write statistics */
>>> u64 sectors_written_start;
>>> @@ -2998,13 +3005,10 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
>>> if (sbi->gc_mode == GC_URGENT_HIGH)
>>> return true;
>>> - if (zoned_gc) {
>>> - if (is_inflight_read_io(sbi))
>>> - return false;
>>> - } else {
>>> - if (is_inflight_io(sbi, type))
>>> - return false;
>>> - }
>>> + if (sbi->bggc_block_io == READ_IO_PRIOR && is_inflight_read_io(sbi))
>>> + return false;
>>> + if (sbi->bggc_block_io == ALL_IO_PRIOR && is_inflight_io(sbi, type))
>>> + return false;
>>> if (sbi->gc_mode == GC_URGENT_MID)
>>> return true;
>>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>>> index e16c4e2830c2..a21cecc5424e 100644
>>> --- a/fs/f2fs/super.c
>>> +++ b/fs/f2fs/super.c
>>> @@ -4629,9 +4629,11 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
>>> logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
>>> sbi->aligned_blksize = true;
>>> + sbi->bggc_block_io = ALL_IO_PRIOR;
>>> #ifdef CONFIG_BLK_DEV_ZONED
>>> sbi->max_open_zones = UINT_MAX;
>>> sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ;
>>> + sbi->bggc_block_io = READ_IO_PRIOR;
>>> #endif
>>> for (i = 0; i < max_devices; i++) {
>>> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
>>> index f736052dea50..efea15209788 100644
>>> --- a/fs/f2fs/sysfs.c
>>> +++ b/fs/f2fs/sysfs.c
>>> @@ -674,6 +674,13 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
>>> sbi->blkzone_alloc_policy = t;
>>> return count;
>>> }
>>> +
>>> + if (!strcmp(a->attr.name, "bggc_block_io")) {
>>> + if (t < BGGC_PRIOR || t > ALL_IO_PRIOR)
>>> + return -EINVAL;
>>> + sbi->bggc_block_io = t;
>>> + return count;
>>> + }
>>> #endif
>>> #ifdef CONFIG_F2FS_FS_COMPRESSION
>>> @@ -1172,6 +1179,7 @@ F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
>>> #ifdef CONFIG_BLK_DEV_ZONED
>>> F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
>>> F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
>>> +F2FS_SBI_GENERAL_RW_ATTR(bggc_block_io);
>>> #endif
>>> F2FS_SBI_GENERAL_RW_ATTR(carve_out);
>>> F2FS_SBI_GENERAL_RW_ATTR(reserved_pin_section);
>>> @@ -1342,6 +1350,7 @@ static struct attribute *f2fs_attrs[] = {
>>> #ifdef CONFIG_BLK_DEV_ZONED
>>> ATTR_LIST(unusable_blocks_per_sec),
>>> ATTR_LIST(blkzone_alloc_policy),
>>> + ATTR_LIST(bggc_block_io),
>>> #endif
>>> #ifdef CONFIG_F2FS_FS_COMPRESSION
>>> ATTR_LIST(compr_written_block),
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-08 0:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 13:22 [PATCH] f2fs: Add bggc_block_io to adjust the priority of BG_GC when issuing IO Liao Yuanhong
2025-08-06 7:09 ` [PATCH v2] " Liao Yuanhong
2025-08-07 8:38 ` Chao Yu
2025-08-07 9:12 ` Liao Yuanhong
2025-08-08 0:50 ` Chao Yu
2025-08-07 7:44 ` [PATCH v3] " Liao Yuanhong
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).