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