mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>
Subject: [PATCH 4/5] f2fs: cache: support asynchronous write_end_io
Date: Wed,  7 Oct 2026 11:49:48 +0000	[thread overview]
Message-ID: <20261007114949.2428048-4-chao@kernel.org> (raw)
In-Reply-To: <20261007114949.2428048-1-chao@kernel.org>

From: Chao Yu <chao@kernel.org>

Currently, f2fs_cache_write_end_io() synchronously traverses all
cached blocks in the write bio to perform node footer sanity checks,
warm node cleanup, and writeback completion. If called from atomic
context (e.g. interrupt context) with a large batch of metadata
blocks, this traversal can induce significant IRQ latency.

Furthermore, f2fs_write_end_io() already implements asynchronous
offloading via workqueue when in atomic context and exceeding the
max_atc_write_bio_size threshold.

To avoid code duplication and mitigate atomic context latency for
metadata cache writes:
1. Unify the write completion handler by pointing all write bios to
   f2fs_write_end_io() with bio->bi_private = sbi.
2. In f2fs_write_end_bio(), check f2fs_is_cache_bio(bio) to dispatch
   to f2fs_cache_write_end_bio().
3. Simplify f2fs_zone_write_end_io() to call f2fs_write_end_io() directly.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/data.c | 92 +++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 50 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 6d4ba5e77906..0a6aa24caa07 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -298,6 +298,40 @@ static void f2fs_read_end_io(struct bio *bio)
 	f2fs_verify_and_finish_bio(bio, intask);
 }
 
+static void f2fs_cache_write_end_bio(struct bio *bio)
+{
+	struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
+	struct f2fs_sb_info *sbi = entry->cache->sbi;
+	struct f2fs_cached_block *next;
+
+	if (bio->bi_status != BLK_STS_OK)
+		f2fs_stop_checkpoint(sbi, true,
+			STOP_CP_REASON_WRITE_FAIL);
+
+	while (entry) {
+		next = entry->next_entry;
+		entry->next_entry = NULL;
+
+		if (f2fs_is_node_cache(entry)) {
+			f2fs_sanity_check_node_footer(sbi, entry,
+				entry->index, NODE_TYPE_REGULAR, true);
+			f2fs_bug_on(sbi, entry->index != nid_of_node(sbi, entry));
+		}
+		if (f2fs_in_warm_node_list(sbi, entry))
+			f2fs_del_fsync_node_entry(sbi, entry);
+
+		dec_cache_count(sbi, F2FS_WB_CP_DATA);
+
+		if (!get_nr_caches(sbi, F2FS_WB_CP_DATA) &&
+				wq_has_sleeper(&sbi->cp_wait))
+			wake_up(&sbi->cp_wait);
+
+		f2fs_end_cache_writeback(entry);
+		entry = next;
+	}
+	bio_put(bio);
+}
+
 static void f2fs_write_end_bio(struct bio *bio)
 {
 	struct f2fs_sb_info *sbi = bio->bi_private;
@@ -306,6 +340,11 @@ static void f2fs_write_end_bio(struct bio *bio)
 	if (time_to_inject(sbi, FAULT_WRITE_IO))
 		bio->bi_status = BLK_STS_IOERR;
 
+	if (f2fs_is_cache_bio(bio)) {
+		f2fs_cache_write_end_bio(bio);
+		return;
+	}
+
 	bio_for_each_folio_all(fi, bio) {
 		struct folio *folio = fi.folio;
 		enum count_type type;
@@ -404,45 +443,6 @@ static void f2fs_cache_read_end_io(struct bio *bio)
 	bio_put(bio);
 }
 
-static void f2fs_cache_write_end_io(struct bio *bio)
-{
-	struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
-	struct f2fs_sb_info *sbi = entry->cache->sbi;
-	struct f2fs_cached_block *next;
-
-	iostat_update_and_unbind_ctx(bio);
-
-	if (time_to_inject(sbi, FAULT_WRITE_IO))
-		bio->bi_status = BLK_STS_IOERR;
-
-	if (bio->bi_status != BLK_STS_OK)
-		f2fs_stop_checkpoint(sbi, true,
-			STOP_CP_REASON_WRITE_FAIL);
-
-	while (entry) {
-		next = entry->next_entry;
-		entry->next_entry = NULL;
-
-		if (f2fs_is_node_cache(entry)) {
-			f2fs_sanity_check_node_footer(sbi, entry,
-				entry->index, NODE_TYPE_REGULAR, true);
-			f2fs_bug_on(sbi, entry->index != nid_of_node(sbi, entry));
-		}
-		if (f2fs_in_warm_node_list(sbi, entry))
-			f2fs_del_fsync_node_entry(sbi, entry);
-
-		dec_cache_count(sbi, F2FS_WB_CP_DATA);
-
-		if (!get_nr_caches(sbi, F2FS_WB_CP_DATA) &&
-				wq_has_sleeper(&sbi->cp_wait))
-			wake_up(&sbi->cp_wait);
-
-		f2fs_end_cache_writeback(entry);
-		entry = next;
-	}
-	bio_put(bio);
-}
-
 #ifdef CONFIG_BLK_DEV_ZONED
 static void f2fs_zone_write_end_io(struct bio *bio)
 {
@@ -450,10 +450,7 @@ static void f2fs_zone_write_end_io(struct bio *bio)
 
 	bio->bi_private = io->bi_private;
 	complete(&io->zone_wait);
-	if (f2fs_is_cache_bio(bio))
-		f2fs_cache_write_end_io(bio);
-	else
-		f2fs_write_end_io(bio);
+	f2fs_write_end_io(bio);
 }
 #endif
 
@@ -548,13 +545,8 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
 		else
 			bio->bi_end_io = f2fs_read_end_io;
 	} else {
-		if (fio->is_cache) {
-			bio->bi_end_io = f2fs_cache_write_end_io;
-		} else {
-			bio->bi_end_io = f2fs_write_end_io;
-			bio->bi_private = sbi;
-		}
-
+		bio->bi_end_io = f2fs_write_end_io;
+		bio->bi_private = sbi;
 		bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi,
 						fio->type, fio->temp);
 		bio->bi_write_stream = f2fs_io_type_to_write_stream(bdev, fio->type,
-- 
2.49.0


  parent reply	other threads:[~2026-10-07 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 11:49 [PATCH 1/5] f2fs: cache: introduce metadata_cache sysfs node Chao Yu
2026-10-07 11:49 ` [PATCH 2/5] f2fs: cache: shrink meta and node caches in f2fs_balance_fs_bg Chao Yu
2026-10-07 11:49 ` [PATCH 3/5] f2fs: cache: wake up f2fs_writeback when exceeding threshold Chao Yu
2026-10-07 11:49 ` Chao Yu [this message]
2026-10-07 11:49 ` [PATCH 5/5] f2fs: introduce max_atc_write_bio_entry_cnt 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=20261007114949.2428048-4-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@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®