On 1/7/2026 9:15 PM, 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.

What about updating sm->last_victim[p.gc_mode] as well when p->offset is not 
zero
in select_policy()?

select_policy()
...
        /* let's select beginning hot/small space first. */
        if (f2fs_need_rand_seg(sbi)) {
                p->offset = get_random_u32_below(MAIN_SECS(sbi) *
                                                SEGS_PER_SEC(sbi));
                if (p->offset)
                        sm->last_victim[p.gc_mode] = p->offset;
        }

Then we can expect p->offset being reset to zero, and last_segment being reset 
to
sm->last_victim[p.gc_mode] in below logic?

                if (segno >= last_segment) {
                        if (sm->last_victim[p.gc_mode]) {
                                last_segment =
                                        sm->last_victim[p.gc_mode];
                                sm->last_victim[p.gc_mode] = 0;
                                p.offset = 0;
                                continue;
                        }
                        break;
                }

Thanks,


Signed-off-by: liujinbao1 <[email protected]>
---
  fs/f2fs/gc.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 384fa7e2085b..100b8fc3e65a 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -781,6 +781,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int 
*result,
        unsigned int valid_thresh_ratio = 100;
        bool is_atgc;
        int ret = 0;
+       unsigned int original_offset;
mutex_lock(&dirty_i->seglist_lock);
        last_segment = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi);
@@ -799,6 +800,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int 
*result,
        p.min_segno = NULL_SEGNO;
        p.oldest_age = 0;
        p.min_cost = get_max_cost(sbi, &p);
+       original_offset = p.offset;
is_atgc = (p.gc_mode == GC_AT || p.alloc_mode == AT_SSR);
        nsearched = 0;
@@ -859,11 +861,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned 
int *result,
                                p.offset / p.ofs_unit);
                segno = unit_no * p.ofs_unit;
                if (segno >= last_segment) {
-                       if (sm->last_victim[p.gc_mode]) {
-                               last_segment =
-                                       sm->last_victim[p.gc_mode];
-                               sm->last_victim[p.gc_mode] = 0;
+                       if (original_offset != 0) {
+                               last_segment = original_offset;
                                p.offset = 0;
+                               if (sm->last_victim[p.gc_mode])
+                                       sm->last_victim[p.gc_mode] = 0;
                                continue;
                        }
                        break;



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

Reply via email to