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

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