]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
f2fs: improve check for enough free sections
authorJoanne Chang <joannechien@google.com>
Fri, 12 Dec 2025 08:40:34 +0000 (08:40 +0000)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 16 Dec 2025 00:49:25 +0000 (00:49 +0000)
commit4a210a5be279bfd5514dac3f5ef2c737cd984e84
tree93da618a4128ef6da3ebb1d8e8e20201f7715304
parent903c6e95bc9a4a3556d37e727853fc0ffb7f3acb
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
>= 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”.

Signed-off-by: Joanne Chang <joannechien@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c
fs/f2fs/segment.h