From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH 3/6] f2fs: cache: fix to submit cached DATA bio when waiting writeback of meta cache
Date: Tue, 1 Dec 2026 11:08:45 +0000 [thread overview]
Message-ID: <20261201110842.1825797-9-chao@kernel.org> (raw)
In-Reply-To: <20261201110842.1825797-7-chao@kernel.org>
From: Chao Yu <chao@kernel.org>
GC migrates data blocks of post-read and atomic files via meta cache
entries, and writes them w/ DATA bios in move_data_block(), however,
f2fs_cache_wait_writeback() only submits cached META bio for a meta
cache entry, so it may wait forever for a DATA bio which GC has not
submitted yet, e.g. an ABBA deadlock found by consistency test w/
atomic write workers and gc_urgent:
- lock A: writeback state (F2FS_BLOCK_WRITEBACK) of the meta cache
entry of new block B, it's cleared only after the DATA bio cached by
GC is submitted and completed
- lock B: lock of node cache entry N
GC thread atomic commit
- do_garbage_collect
- gc_data_segment (phase 4)
- move_data_block
- f2fs_start_cache_writeback(B) (set WRITEBACK of B: lock A)
- f2fs_submit_cache_write
: B's DATA bio is cached, not
submitted until the end of
do_garbage_collect
- f2fs_commit_atomic_write
- __replace_atomic_write_block
- f2fs_get_dnode_of_data
(lock N: lock B)
- f2fs_truncate_data_blocks_range
- f2fs_invalidate_blocks(B)
- f2fs_truncate_meta_caches
- f2fs_cache_wait_writeback
- ..._wait_writeback_cond(META)
: submits META bio only
- wait_on_bit_io(WRITEBACK)
(wait for lock A, held by GC)
- is_alive (next block)
- f2fs_get_node_cache(N)
(wait for lock B, held by commit)
Then checkpoint, writeback and all syncs hang behind them.
Before commit 7a1cf2a76b71 ("f2fs: cache: use meta cache"), GC staged
such blocks in META_MAPPING folios, and f2fs_truncate_meta_inode_pages()
submitted cached DATA bio of meta inode before waiting on their
writeback, the conversion to f2fs_truncate_meta_caches() lost it.
Let's submit cached DATA bio as well in f2fs_cache_wait_writeback_cond()
when waiting writeback of a meta cache entry w/ META type.
Cc: stable@vger.kernel.org
Fixes: 7a1cf2a76b71 ("f2fs: cache: use meta cache")
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/cache.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/f2fs/cache.c b/fs/f2fs/cache.c
index 6cac7662fc1a..f22acf3e51ff 100644
--- a/fs/f2fs/cache.c
+++ b/fs/f2fs/cache.c
@@ -32,6 +32,12 @@ void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
/* submit cached bio */
f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, type);
+ /*
+ * GC writes meta cache entries w/ DATA bio in move_data_block(),
+ * submit it as well, or we may wait for a bio cached by GC forever.
+ */
+ if (type == META)
+ f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, DATA);
wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
TASK_UNINTERRUPTIBLE);
--
2.49.0
next prev parent reply other threads:[~2026-12-01 11:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 11:08 [PATCH 1/6] f2fs: fix to clear SBI_IS_CLOSE in __f2fs_remount() Chao Yu
2026-12-01 11:08 ` [PATCH 2/6] f2fs: quota: fix to recheck quota flush after taking node_change in checkpoint Chao Yu
2026-12-01 11:08 ` Chao Yu [this message]
2026-12-01 11:08 ` [PATCH 4/6] f2fs: atomic: fix to keep committed data of atomic file in f2fs_write_failed() Chao Yu
2026-12-01 11:08 ` [PATCH 5/6] f2fs: atomic: fix to avoid preallocating blocks in original inode for atomic file Chao Yu
2026-12-01 11:08 ` [PATCH 6/6] f2fs: atomic: fix to disallow shrinking atomic file via truncate Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201110842.1825797-9-chao@kernel.org \
--to=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®