Skip to contentSkip to conversation

f2fs:Fix incomplete search range in f2fs_get_victim when f2fs_need_rand_seg is enabled

PATCH Applied liujinbao1 2 participants 3 messages Feb 13 – Mar 5 F2FS file system

lore
Share & tools
lore

liujinbao1

author
#0 lore raw

PATCH v2 1/1 f2fs:Fix incomplete search range in f2fs_get_victim when f2fs_need_rand_seg is enabled

From: liujinbao1 <[email protected]>

During the f2fs_get_victim process, when the f2fs_need_rand_seg is enabled in select_policy, p->offset is a random value, and the search range is from p->offset to MAIN_SECS. When segno >= last_segment, the loop breaks and exits directly without searching the range from 0 to p->offset.This results in an incomplete search when the random offset is not zero.

---
 fs/f2fs/gc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +3 -2
index 384fa7e2085b..a5b333bbb201 100644
@@ -312,10 +312,11 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
 		p->max_search = sbi->max_victim_search;
 
 	/* let's select beginning hot/small space first. */
-	if (f2fs_need_rand_seg(sbi))
+	if (f2fs_need_rand_seg(sbi)) {
 		p->offset = get_random_u32_below(MAIN_SECS(sbi) *
 						SEGS_PER_SEC(sbi));
-	else if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
+		SIT_I(sbi)->last_victim[p->gc_mode] = p->offset;
+	} else if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
 		p->offset = 0;
 	else
 		p->offset = SIT_I(sbi)->last_victim[p->gc_mode];
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by Chao Yu on v2 1/1
#1 lore raw
Quoted 9 lines · On 2026/2/13 20:26, liujinbao1 wrote:

From: liujinbao1 <[email protected]>

During the f2fs_get_victim process, when the f2fs_need_rand_seg is enabled in select_policy, p->offset is a random value, and the search range is from p->offset to MAIN_SECS. When segno >= last_segment, the loop breaks and exits directly without searching the range from 0 to p->offset.This results in an incomplete search when the random offset is not zero.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
In reply to liujinbao1

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 9 lines · On Fri, 13 Feb 2026 20:26:30 +0800 you wrote:

From: liujinbao1 <[email protected]>

During the f2fs_get_victim process, when the f2fs_need_rand_seg is enabled in select_policy, p->offset is a random value, and the search range is from p->offset to MAIN_SECS. When segno >= last_segment, the loop breaks and exits directly without searching the range from 0 to p->offset.This results in an incomplete search when the random offset is not zero.

[...]

Here is the summary with links:
- [f2fs-dev,v2] f2fs:Fix incomplete search range in f2fs_get_victim when f2fs_need_rand_seg is enabled

    https://git.kernel.org/jaegeuk/f2fs/c/279709ed388c

You are awesome, thank you!

Signature · 10 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel