Skip to contentSkip to conversation

f2fs: fix to avoid potential reference count leak in do_garbage_collect()

PATCH Applied Chao Yu 3 participants 3 messages Oct 16 – Oct 19 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix to avoid potential reference count leak in do_garbage_collect()

From: Chao Yu <[email protected]>

In do_garbage_collect(), we have reserved reference counts on summary cache of all segments, once gc_thread encounter freezing, we need to release all reference counts.

Cc Daeho Jeong <[email protected]>
Fixes 02d91398a602 ("f2fs: fix to freeze GC and discard threads quickly")
---
 fs/f2fs/gc.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
fs/f2fs/gc.c +3 -7
index 5bb117e5e811..ad6f604cc27f 100644
@@ -1901,6 +1901,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 		if (block_end_segno > end_segno)
 			block_end_segno = end_segno;
 
+		if (unlikely(freezing(current)))
+			goto next_block;
+
 		if (is_cursec(sbi, GET_SEC_FROM_SEG(sbi, segno))) {
 			f2fs_err(sbi, "%s: segment %u is used by log",
 							__func__, segno);
@@ -1968,12 +1971,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 				sbi->next_victim_seg[gc_type] =
 					(cur_segno + 1 < sec_end_segno) ?
 					cur_segno + 1 : NULL_SEGNO;
-
-			if (unlikely(freezing(current))) {
-				f2fs_put_cache(sum_entry, false);
-				f2fs_put_cache(sum_entry, false);
-				goto stop;
-			}
 		}
 next_block:
 		f2fs_put_cache(sum_entry, false);
@@ -1981,7 +1978,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 		segno = block_end_segno;
 	}
 
-stop:
 	if (submitted)
 		f2fs_submit_merged_write(sbi, data_type);
 
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 51 lines · On Thu, Oct 15, 2026 at 7:22 PM Chao Yu via Linux-f2fs-devel…

From: Chao Yu <[email protected]>

In do_garbage_collect(), we have reserved reference counts on summary cache of all segments, once gc_thread encounter freezing, we need to release all reference counts.

Cc Daeho Jeong <[email protected]>
Fixes 02d91398a602 ("f2fs: fix to freeze GC and discard threads quickly")
---
 fs/f2fs/gc.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
fs/f2fs/gc.c +3 -8
index 5bb117e5e811..ad6f604cc27f 100644
@@ -1901,6 +1901,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
                if (block_end_segno > end_segno)
                        block_end_segno = end_segno;
 
+               if (unlikely(freezing(current)))
+                       goto next_block;
+
                if (is_cursec(sbi, GET_SEC_FROM_SEG(sbi, segno))) {
                        f2fs_err(sbi, "%s: segment %u is used by log",
                                                        __func__, segno);
@@ -1968,12 +1971,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
                                sbi->next_victim_seg[gc_type] =
                                        (cur_segno + 1 < sec_end_segno) ?
                                        cur_segno + 1 : NULL_SEGNO;
-
-                       if (unlikely(freezing(current))) {
-                               f2fs_put_cache(sum_entry, false);
-                               f2fs_put_cache(sum_entry, false);
-                               goto stop;
-                       }
                }
 next_block:
                f2fs_put_cache(sum_entry, false);
@@ -1981,7 +1978,6 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
                segno = block_end_segno;
        }
 
-stop:
        if (submitted)
                f2fs_submit_merged_write(sbi, data_type);
 
--
Quoted 3 lines

2.49.0

Thanks,

Quoted 5 lines

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

#2 lore raw
In reply to Chao Yu
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:

Hello:

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

Quoted 6 lines · On Fri, 16 Oct 2026 10:17:37 +0800 you wrote:

From: Chao Yu <[email protected]>

In do_garbage_collect(), we have reserved reference counts on summary cache of all segments, once gc_thread encounter freezing, we need to release all reference counts.

Quoted 6 lines
Cc Daeho Jeong <[email protected]>
Fixes 02d91398a602 ("f2fs: fix to freeze GC and discard threads quickly")

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: fix to avoid potential reference count leak in do_garbage_collect()

    https://git.kernel.org/jaegeuk/f2fs/c/894ca8b85666

You are awesome, thank you!

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