f2fs: prevent the current section from being selected as a victim during GC
PATCH v4 1/1 f2fs: prevent the current section from being selected as a victim during GC
When selecting a victim using next_victim_seg in a large section, the selected section might already have been cleared and designated as the new current section, making it actively in use.
This behavior causes inconsistency between the SIT and SSA.
F2FS-fs (dm-54): Inconsistent segment (70961) type [0, 1] in SSA and SIT
Call trace: dump_backtrace+0xe8/0x10c show_stack+0x18/0x28 dump_stack_lvl+0x50/0x6c dump_stack+0x18/0x28 f2fs_stop_checkpoint+0x1c/0x3c do_garbage_collect+0x41c/0x271c f2fs_gc+0x27c/0x828 gc_thread_func+0x290/0x88c kthread+0x11c/0x164 ret_from_fork+0x10/0x20
issue scenario
segs_per_sec=2
- seg#0 and seg#1 are all dirty
- all valid blocks are removed in seg#1
- gc select this sec and next_victim_seg=seg#0
- migrate seg#0, next_victim_seg=seg#1
- checkpoint -> sec(seg#0, seg#1) becomes free
- allocator assigns sec(seg#0, seg#1) to curseg
- gc tries to migrate seg#1
--- fs/f2fs/segment.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/f2fs/segment.h +8 -1
@@ -474,8 +474,15 @@ static inline void __set_test_and_free(struct f2fs_sb_info *sbi, next =find_next_bit (free_i->free_segmap, start_segno +SEGS_PER_SEC (sbi), start_segno);if (next >= start_segno + usable_segs) { -if (test_and_clear_bit (secno, free_i->free_secmap)) +if (test_and_clear_bit (secno, free_i->free_secmap)) { free_i->free_sections++; + +if (GET_SEC_FROM_SEG (sbi->next_victim_seg[BG_GC ]) == secno) + sbi->next_victim_seg[BG_GC ] =NULL_SEGNO ; + +if (GET_SEC_FROM_SEG (sbi->next_victim_seg[FG_GC ]) == secno) + sbi->next_victim_seg[FG_GC ] =NULL_SEGNO ; + } } } skip_free:
Signature · 1 line
2.33.0
Quoted 28 lines · yohan.joung
When selecting a victim using
next_victim_segin a large section, the selected section might already have been cleared and designated as the new current section, making it actively in use.
This behavior causes inconsistency between the SIT and SSA.F2FS-fs (dm-54): Inconsistent segment (70961) type [0, 1] in SSA and SIT
Call trace: dump_backtrace+0xe8/0x10c show_stack+0x18/0x28 dump_stack_lvl+0x50/0x6c dump_stack+0x18/0x28 f2fs_stop_checkpoint+0x1c/0x3c do_garbage_collect+0x41c/0x271c f2fs_gc+0x27c/0x828 gc_thread_func+0x290/0x88c kthread+0x11c/0x164 ret_from_fork+0x10/0x20issue scenario
segs_per_sec=2
- seg#0 and seg#1 are all dirty
- all valid blocks are removed in seg#1
- gc select this sec and next_victim_seg=seg#0
- migrate seg#0, next_victim_seg=seg#1
- checkpoint ->sec(seg#0, seg#1)becomes free
- allocator assignssec(seg#0, seg#1)to curseg
- gc tries to migrate seg#1
Quoted 2 lines
Signed-off-by yohan.joung <[email protected]>Signed-off-by Chao Yu <[email protected]>
Thanks,
kernel test robot
build botkernel test robot noticed the following build errors:
Hi yohan.joung,
kernel test robot noticed the following build errors:
[auto build test ERROR on jaegeuk-f2fs/dev-test]
[also build test ERROR on jaegeuk-f2fs/dev linus/master v6.14 next-20250403] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/yohan-joung/f2fs-prevent-the-current-section-from-being-selected-as-a-victim-during-GC/20250403-151057 base: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test patch link: https://lore.kernel.org/r/20250403071016.2940-1-yohan.joung%40sk.com patch subject: [PATCH v4] f2fs: prevent the current section from being selected as a victim during GC config: i386-buildonly-randconfig-005-20250403 (https://download.01.org/0day-ci/archive/20250403/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250403/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from fs/f2fs/checkpoint.c:20:
fs/f2fs/segment.h: In function '__set_test_and_free':
>> fs/f2fs/segment.h:480:81: error: macro "GET_SEC_FROM_SEG" requires 2 arguments, but only 1 given
480 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
| ^
fs/f2fs/segment.h:105: note: macro "GET_SEC_FROM_SEG" defined here
105 | #define GET_SEC_FROM_SEG(sbi, segno) \
|
>> fs/f2fs/segment.h:480:37: error: 'GET_SEC_FROM_SEG' undeclared (first use in this function)
480 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
| ^~~~~~~~~~~~~~~~
fs/f2fs/segment.h:480:37: note: each undeclared identifier is reported only once for each function it appears in
fs/f2fs/segment.h:483:81: error: macro "GET_SEC_FROM_SEG" requires 2 arguments, but only 1 given
483 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[FG_GC]) == secno)
| ^
fs/f2fs/segment.h:105: note: macro "GET_SEC_FROM_SEG" defined here
105 | #define GET_SEC_FROM_SEG(sbi, segno) \
| vim +/GET_SEC_FROM_SEG +480 fs/f2fs/segment.h
458
459 static inline void __set_test_and_free(struct f2fs_sb_info *sbi,
460 unsigned int segno, bool inmem)
461 {
462 struct free_segmap_info *free_i = FREE_I(sbi);
463 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
464 unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
465 unsigned int next;
466 unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi);
467
468 spin_lock(&free_i->segmap_lock);
469 if (test_and_clear_bit(segno, free_i->free_segmap)) {
470 free_i->free_segments++;
471
472 if (!inmem && IS_CURSEC(sbi, secno))
473 goto skip_free;
474 next = find_next_bit(free_i->free_segmap,
475 start_segno + SEGS_PER_SEC(sbi), start_segno);
476 if (next >= start_segno + usable_segs) {
477 if (test_and_clear_bit(secno, free_i->free_secmap)) {
478 free_i->free_sections++;
479
> 480 if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
481 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
482
483 if (GET_SEC_FROM_SEG(sbi->next_victim_seg[FG_GC]) == secno)
484 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
485 }
486 }
487 }
488 skip_free:
489 spin_unlock(&free_i->segmap_lock);
490 }
491
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi yohan.joung,
kernel test robot noticed the following build errors:
[auto build test ERROR on jaegeuk-f2fs/dev-test]
[also build test ERROR on jaegeuk-f2fs/dev linus/master v6.14 next-20250403] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/yohan-joung/f2fs-prevent-the-current-section-from-being-selected-as-a-victim-during-GC/20250403-151057 base: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test patch link: https://lore.kernel.org/r/20250403071016.2940-1-yohan.joung%40sk.com patch subject: [PATCH v4] f2fs: prevent the current section from being selected as a victim during GC config: i386-buildonly-randconfig-003-20250403 (https://download.01.org/0day-ci/archive/20250403/[email protected]/config) compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250403/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from fs/f2fs/file.c:30:
>> fs/f2fs/segment.h:480:53: error: too few arguments provided to function-like macro invocation
480 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
| ^
fs/f2fs/segment.h:105:9: note: macro 'GET_SEC_FROM_SEG' defined here
105 | #define GET_SEC_FROM_SEG(sbi, segno) \
| ^
>> fs/f2fs/segment.h:480:9: error: use of undeclared identifier 'GET_SEC_FROM_SEG'
480 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
| ^
fs/f2fs/segment.h:483:53: error: too few arguments provided to function-like macro invocation
483 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[FG_GC]) == secno)
| ^
fs/f2fs/segment.h:105:9: note: macro 'GET_SEC_FROM_SEG' defined here
105 | #define GET_SEC_FROM_SEG(sbi, segno) \
| ^
fs/f2fs/segment.h:483:9: error: use of undeclared identifier 'GET_SEC_FROM_SEG'
483 | if (GET_SEC_FROM_SEG(sbi->next_victim_seg[FG_GC]) == secno)
| ^4 errors generated.
vim +480 fs/f2fs/segment.h
458
459 static inline void __set_test_and_free(struct f2fs_sb_info *sbi,
460 unsigned int segno, bool inmem)
461 {
462 struct free_segmap_info *free_i = FREE_I(sbi);
463 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno);
464 unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno);
465 unsigned int next;
466 unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi);
467
468 spin_lock(&free_i->segmap_lock);
469 if (test_and_clear_bit(segno, free_i->free_segmap)) {
470 free_i->free_segments++;
471
472 if (!inmem && IS_CURSEC(sbi, secno))
473 goto skip_free;
474 next = find_next_bit(free_i->free_segmap,
475 start_segno + SEGS_PER_SEC(sbi), start_segno);
476 if (next >= start_segno + usable_segs) {
477 if (test_and_clear_bit(secno, free_i->free_secmap)) {
478 free_i->free_sections++;
479
> 480 if (GET_SEC_FROM_SEG(sbi->next_victim_seg[BG_GC]) == secno)
481 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
482
483 if (GET_SEC_FROM_SEG(sbi->next_victim_seg[FG_GC]) == secno)
484 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
485 }
486 }
487 }
488 skip_free:
489 spin_unlock(&free_i->segmap_lock);
490 }
491
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki