summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliujinbao1 <liujinbao1@xiaomi.com>2026-02-13 15:26:30 +0300
committerJaegeuk Kim <jaegeuk@kernel.org>2026-03-24 20:20:59 +0300
commit5604129b6504c2d6dfbc02515c43e6186a1285e7 (patch)
tree3413c31721d9df5957ef76f0b72eaac2fd2ed8b2
parent3cf11e6f36c170050c12171dd6fd3142711478fc (diff)
downloadlinux-5604129b6504c2d6dfbc02515c43e6186a1285e7.tar.xz
f2fs:Fix incomplete search range in f2fs_get_victim when f2fs_need_rand_seg is enabled
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. Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/gc.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index f46b2673d31f..d15e122b470c 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -316,10 +316,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];