f2fs: improve check for enough free sections
PATCH 1/1 f2fs: improve check for enough free sections
The check for enough sections in segment.h has the following issues:
1. has_not_enough_free_secs() should return "enough secs" when "free_secs
Quoted 1 line
=
upper_secs", not just structly greater. Conversely, it should only
return "not enough secs" when "free_secs < lower_secs", not when they are equal. This accounts for the possibility that blocks can fit within curseg without requiring an additional free section.
2. __get_secs_required() currently separates the needed space to section and block parts, checking them against free sections and curseg, respectively. This does not consider the case where curseg cannot hold the whole block part, but excess free sections beyond the section part can accommodate some of the block part.
3. has_curseg_enough_space() only checks CURSEG_HOT_DATA for dentry blocks, but when active_logs=6, they may be placed in WARM and COLD sections. Also, the current logic does not consider that dentry and data blocks can be put in the same section when active_logs=2 or 6.
This patch modifies the three functions to address the above issues:
1. Rename has_curseg_enough_space() to get_additional_blocks_required(). Calculate the minimum node, dentry, and data blocks curseg can accommodate. Then subtract these from the total required blocks of respective type to determine the worst-case number of blocks that must be placed in free sections.
2. In __get_secs_required(), get the number of blocks needing new sections from the new get_additional_blocks_required(). Return the upper bound of necessary free sections for these blocks. For active_logs=2 or 6, dentry blocks are combined with data blocks.
3. In has_not_enough_free_secs(), get the required sections from __get_secs_required(), and return “not enough secs” if “free_secs < required_secs”.
--- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.h | 99 ++++++++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 54 deletions(-)
fs/f2fs/gc.c +1 -1
@@ -2000,7 +2000,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) goto stop; } -__get_secs_required (sbi,NULL , &upper_secs,NULL ); + upper_secs =__get_secs_required (sbi);/* * Write checkpoint to reclaim prefree segments.
fs/f2fs/segment.h +46 -53
143 lines not on this page · raw message
Signature · 1 line
2.52.0.239.gd5f0c6e74e-goog
Quoted 32 lines · Joanne Chang
The check for enough sections in
segment.hhas the following issues:1.
has_not_enough_free_secs()should return "enough secs" when "free_secsQuoted 1 line
=
upper_secs", not just structly greater. Conversely, it should onlyreturn "not enough secs" when "
free_secs<lower_secs", not when they are equal. This accounts for the possibility that blocks can fit within curseg without requiring an additional free section.2.
__get_secs_required()currently separates the needed space to section and block parts, checking them against free sections and curseg, respectively. This does not consider the case where curseg cannot hold the whole block part, but excess free sections beyond the section part can accommodate some of the block part.3.
has_curseg_enough_space()only checksCURSEG_HOT_DATAfor dentry blocks, but when active_logs=6, they may be placed in WARM and COLD sections. Also, the current logic does not consider that dentry and data blocks can be put in the same section when active_logs=2 or 6.This patch modifies the three functions to address the above issues:
1. Rename
has_curseg_enough_space()toget_additional_blocks_required(). Calculate the minimum node, dentry, and data blocks curseg can accommodate. Then subtract these from the total required blocks of respective type to determine the worst-case number of blocks that must be placed in free sections.2. In
__get_secs_required(), get the number of blocks needing new sections from the newget_additional_blocks_required(). Return the upper bound of necessary free sections for these blocks. For active_logs=2 or 6, dentry blocks are combined with data blocks.
Quoted 5 lines
3. In
has_not_enough_free_secs(), get the required sections from__get_secs_required(), and return “not enough secs” if “free_secs < required_secs”.Signed-off-by Joanne Chang <[email protected]>
Thanks,
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 9 lines · On Fri, 12 Dec 2025 08:40:34 +0000 you wrote:
The check for enough sections in
segment.hhas the following issues:1.
has_not_enough_free_secs()should return "enough secs" when "free_secsQuoted 1 line
=
upper_secs", not just structly greater. Conversely, it should onlyreturn "not enough secs" when "
free_secs<lower_secs", not when they are equal. This accounts for the possibility that blocks can fit within curseg without requiring an additional free section.[...]
Here is the summary with links:
- [f2fs-dev,v1] f2fs: improve check for enough free sections
https://git.kernel.org/jaegeuk/f2fs/c/4a210a5be279
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html