mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: submit cached data bios before gc_merge GC
@ 2026-05-21  5:30 Wenjie Qi
  2026-05-21  8:39 ` Chao Yu
  2026-05-22  4:30 ` [f2fs-dev] " patchwork-bot+f2fs
  0 siblings, 2 replies; 3+ messages in thread
From: Wenjie Qi @ 2026-05-21  5:30 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: ruipengqi3, linux-f2fs-devel, linux-kernel, qiwenjie, qwjhust

Commit fefdf0723650 ("f2fs: fix potential deadlock in f2fs_balance_fs()")
added cached DATA bio submission before direct foreground GC in
f2fs_balance_fs().

This avoids a deadlock between writeback and GC on cached data folios.
However, when gc_merge is enabled, f2fs_balance_fs() does not execute
foreground GC in the caller. It wakes the background GC thread and waits
for that foreground request to finish.

That branch currently skips the cached DATA bio submission, so the same
foreground GC request can still start with cached DATA bios pending.

Move the cached DATA bio submission before the gc_merge branch so both
direct and merged foreground GC paths satisfy the same precondition.

Fixes: fefdf0723650 ("f2fs: fix potential deadlock in f2fs_balance_fs()")
Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
---
 fs/f2fs/segment.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 7c8ac62b1b0..1ef4edb7707 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -445,6 +445,13 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
 	if (has_enough_free_secs(sbi, 0, 0))
 		return;
 
+	/*
+	 * Submit all cached OPU/IPU DATA bios before triggering
+	 * foreground GC to avoid potential deadlocks.
+	 */
+	f2fs_submit_merged_write(sbi, DATA);
+	f2fs_submit_all_merged_ipu_writes(sbi);
+
 	if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
 				sbi->gc_thread->f2fs_gc_task) {
 		DEFINE_WAIT(wait);
@@ -464,13 +471,6 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
 			.err_gc_skipped = false,
 			.nr_free_secs = 1 };
 
-		/*
-		 * Submit all cached OPU/IPU DATA bios before triggering
-		 * foreground GC to avoid potential deadlocks.
-		 */
-		f2fs_submit_merged_write(sbi, DATA);
-		f2fs_submit_all_merged_ipu_writes(sbi);
-
 		f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
 		stat_inc_gc_call_count(sbi, FOREGROUND);
 		f2fs_gc(sbi, &gc_control);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] f2fs: submit cached data bios before gc_merge GC
  2026-05-21  5:30 [PATCH] f2fs: submit cached data bios before gc_merge GC Wenjie Qi
@ 2026-05-21  8:39 ` Chao Yu
  2026-05-22  4:30 ` [f2fs-dev] " patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2026-05-21  8:39 UTC (permalink / raw)
  To: Wenjie Qi, jaegeuk
  Cc: chao, ruipengqi3, linux-f2fs-devel, linux-kernel, qiwenjie

I've submitted the same fix previously as below:

https://lore.kernel.org/linux-f2fs-devel/20260519011438.1168155-1-chao@kernel.org

On 5/21/26 13:30, Wenjie Qi wrote:
> Commit fefdf0723650 ("f2fs: fix potential deadlock in f2fs_balance_fs()")
> added cached DATA bio submission before direct foreground GC in
> f2fs_balance_fs().
> 
> This avoids a deadlock between writeback and GC on cached data folios.
> However, when gc_merge is enabled, f2fs_balance_fs() does not execute
> foreground GC in the caller. It wakes the background GC thread and waits
> for that foreground request to finish.
> 
> That branch currently skips the cached DATA bio submission, so the same
> foreground GC request can still start with cached DATA bios pending.
> 
> Move the cached DATA bio submission before the gc_merge branch so both
> direct and merged foreground GC paths satisfy the same precondition.
> 
> Fixes: fefdf0723650 ("f2fs: fix potential deadlock in f2fs_balance_fs()")
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
>   fs/f2fs/segment.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 7c8ac62b1b0..1ef4edb7707 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -445,6 +445,13 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
>   	if (has_enough_free_secs(sbi, 0, 0))
>   		return;
>   
> +	/*
> +	 * Submit all cached OPU/IPU DATA bios before triggering
> +	 * foreground GC to avoid potential deadlocks.
> +	 */
> +	f2fs_submit_merged_write(sbi, DATA);
> +	f2fs_submit_all_merged_ipu_writes(sbi);
> +
>   	if (test_opt(sbi, GC_MERGE) && sbi->gc_thread &&
>   				sbi->gc_thread->f2fs_gc_task) {
>   		DEFINE_WAIT(wait);
> @@ -464,13 +471,6 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
>   			.err_gc_skipped = false,
>   			.nr_free_secs = 1 };
>   
> -		/*
> -		 * Submit all cached OPU/IPU DATA bios before triggering
> -		 * foreground GC to avoid potential deadlocks.
> -		 */
> -		f2fs_submit_merged_write(sbi, DATA);
> -		f2fs_submit_all_merged_ipu_writes(sbi);
> -
>   		f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
>   		stat_inc_gc_call_count(sbi, FOREGROUND);
>   		f2fs_gc(sbi, &gc_control);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: submit cached data bios before gc_merge GC
  2026-05-21  5:30 [PATCH] f2fs: submit cached data bios before gc_merge GC Wenjie Qi
  2026-05-21  8:39 ` Chao Yu
@ 2026-05-22  4:30 ` patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2026-05-22  4:30 UTC (permalink / raw)
  To: Wenjie Qi
  Cc: jaegeuk, chao, qiwenjie, linux-kernel, ruipengqi3, linux-f2fs-devel

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Thu, 21 May 2026 13:30:50 +0800 you wrote:
> Commit fefdf0723650 ("f2fs: fix potential deadlock in f2fs_balance_fs()")
> added cached DATA bio submission before direct foreground GC in
> f2fs_balance_fs().
> 
> This avoids a deadlock between writeback and GC on cached data folios.
> However, when gc_merge is enabled, f2fs_balance_fs() does not execute
> foreground GC in the caller. It wakes the background GC thread and waits
> for that foreground request to finish.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev] f2fs: submit cached data bios before gc_merge GC
    https://git.kernel.org/jaegeuk/f2fs/c/cf69827e772c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-22  4:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-21  5:30 [PATCH] f2fs: submit cached data bios before gc_merge GC Wenjie Qi
2026-05-21  8:39 ` Chao Yu
2026-05-22  4:30 ` [f2fs-dev] " patchwork-bot+f2fs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome