]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
f2fs: fix to not account invalid blocks in get_left_section_blocks()
authorChao Yu <chao@kernel.org>
Fri, 28 Nov 2025 09:25:07 +0000 (17:25 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 4 Dec 2025 02:00:05 +0000 (02:00 +0000)
w/ LFS mode, in get_left_section_blocks(), we should not account the
blocks which were used before and now are invalided, otherwise those
blocks will be counted as freed one in has_curseg_enough_space(), result
in missing to trigger GC in time.

Cc: stable@kernel.org
Fixes: 249ad438e1d9 ("f2fs: add a method for calculating the remaining blocks in the current segment in LFS mode.")
Fixes: bf34c93d2645 ("f2fs: check curseg space before foreground GC")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/segment.h

index 0b54d87409b083bf8e0d03d275aff84d2068894d..07dcbcbeb7c6d3dbb2d1abeaacc8e703f5700a81 100644 (file)
@@ -612,10 +612,12 @@ static inline int reserved_sections(struct f2fs_sb_info *sbi)
 static inline unsigned int get_left_section_blocks(struct f2fs_sb_info *sbi,
                                        enum log_type type, unsigned int segno)
 {
-       if (f2fs_lfs_mode(sbi) && __is_large_section(sbi))
-               return CAP_BLKS_PER_SEC(sbi) - SEGS_TO_BLKS(sbi,
-                       (segno - GET_START_SEG_FROM_SEC(sbi, segno))) -
+       if (f2fs_lfs_mode(sbi)) {
+               unsigned int used_blocks = __is_large_section(sbi) ? SEGS_TO_BLKS(sbi,
+                               (segno - GET_START_SEG_FROM_SEC(sbi, segno))) : 0;
+               return CAP_BLKS_PER_SEC(sbi) - used_blocks -
                        CURSEG_I(sbi, type)->next_blkoff;
+       }
        return CAP_BLKS_PER_SEC(sbi) - get_ckpt_valid_blocks(sbi, segno, true);
 }