f2fs: fix to skip empty sections in f2fs_get_victim
PATCH v2 1/1 f2fs: fix to skip empty sections in f2fs_get_victim
From: Daeho Jeong <[email protected]>
In age-based victim selection (ATGC, AT_SSR, or GC_CB), f2fs_get_victim can encounter sections with zero valid blocks. This situation often arises when checkpoint is disabled or due to race conditions between SIT updates and dirty list management.
In such cases, f2fs_get_section_mtime() returns INVALID_MTIME, which subsequently triggers a fatal f2fs_bug_on(sbi, mtime == INVALID_MTIME) in add_victim_entry() or get_cb_cost().
This patch adds a check in f2fs_get_victim's selection loop to skip sections with no valid blocks. This prevents unnecessary age calculations for empty sections and avoids the associated kernel panic. This change also allows removing redundant checks in add_victim_entry().
---
v2: changed the check position.
--- fs/f2fs/gc.c | 3 +++ 1 file changed, 3 insertions(+)
fs/f2fs/gc.c +3 -0
@@ -907,6 +907,9 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result,if (!f2fs_segment_has_free_slot (sbi, segno)) goto next; } + +if (!get_valid_blocks (sbi, segno, true)) + goto next; }if (gc_type ==BG_GC &&test_bit (secno, dirty_i->victim_secmap))
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
Quoted 11 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
In age-based victim selection (ATGC,
AT_SSR, orGC_CB),f2fs_get_victimcan encounter sections with zero valid blocks. This situation often arises when checkpoint is disabled or due to race conditions between SIT updates and dirty list management.In such cases,
f2fs_get_section_mtime()returnsINVALID_MTIME, which subsequently triggers a fatalf2fs_bug_on(sbi, mtime == INVALID_MTIME)inadd_victim_entry()orget_cb_cost().
Quoted 6 lines
This patch adds a check in f2fs_get_victim's selection loop to skip sections with no valid blocks. This prevents unnecessary age calculations for empty sections and avoids the associated kernel panic. This change also allows removing redundant checks in
add_victim_entry().Signed-off-by Daeho Jeong <[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 8 lines · On Mon, 16 Mar 2026 11:59:21 -0700 you wrote:
From: Daeho Jeong <[email protected]>
In age-based victim selection (ATGC,
AT_SSR, orGC_CB),f2fs_get_victimcan encounter sections with zero valid blocks. This situation often arises when checkpoint is disabled or due to race conditions between SIT updates and dirty list management.[...]
Here is the summary with links:
- [f2fs-dev,v2] f2fs: fix to skip empty sections in f2fs_get_victim
https://git.kernel.org/jaegeuk/f2fs/c/3dd8312599c4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html