Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Ojaswin Mujoo <ojaswin@linux.ibm.com>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] ext4: don't zeroout if we have inflight unwritten IOs in buffered iomap path
Date: Mon, 02 Nov 2026 23:56:22 +0530	[thread overview]
Message-ID: <20261102-ext4-endio-zero-bug-v1-7-266d2bb9e6dc@linux.ibm.com> (raw)
In-Reply-To: <20261102-ext4-endio-zero-bug-v1-0-266d2bb9e6dc@linux.ibm.com>

The i_conv_pending_ios counter tracks the number of unwritten IOs that
are currently undergoing endio conversion, and is used to prevent
ext4_can_zeroout() from zeroing out unwritten extents that have valid
data pending conversion.

Enable the tracking for the buffered iomap writeback path by incrementing
i_conv_pending_ios once per submitted unwritten ioend in
ext4_iomap_writeback_submit() and decrement it after extent conversion.

Fixes: 8c4f6e337634 ("ext4: introduce a mount option for iomap buffered I/O path")
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 fs/ext4/inode.c   |  3 +++
 fs/ext4/page-io.c | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9d7d4da0071f..0c924ad8210b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4585,6 +4585,9 @@ static int ext4_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
 	if (ioend->io_bio.bi_end_io)
 		bio_clear_flag(&ioend->io_bio, BIO_COMPLETE_IN_TASK);
 
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_inc(inode);
+
 	return iomap_ioend_writeback_submit(wpc, error);
 }
 
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 00abef904702..e99816017a18 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -652,6 +652,21 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 	int credits;
 	int ret, err;
 
+	/*
+	 * We increment conv_pending for each IO we submit but endio might have
+	 * merged them into a single ioend. The data of all merged sub-ioends is
+	 * covered by a single conversion, so drop their counts keeping just
+	 * the one count for the single ioend we will try to convert.
+	 */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN) {
+		struct iomap_ioend *sub;
+
+		list_for_each_entry(sub, &ioend->io_list, io_list) {
+			if (sub->io_flags & IOMAP_IOEND_UNWRITTEN)
+				ext4_conv_pending_dec(inode);
+		}
+	}
+
 	ret = blk_status_to_errno(ioend->io_bio.bi_status);
 	if (is_disksize_grow)
 		trace_ext4_iomap_wb_disksize_pending_complete(ioend->io_inode,
@@ -704,6 +719,10 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 			 inode->i_ino, ret);
 	}
 out:
+	/* Drop the count of the head ioend now that conversion is done. */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_dec(inode);
+
 	iomap_finish_ioends(ioend, ret);
 }
 

-- 
2.55.0


  parent reply	other threads:[~2026-11-02 18:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 18:26 [PATCH 0/8] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs Ojaswin Mujoo
2026-11-02 18:26 ` [PATCH 1/8] ext4: add extra_flags param to ext4_convert_unwritten_extents() Ojaswin Mujoo
2026-11-02 18:30   ` sashiko-bot
2026-11-02 18:26 ` [PATCH 2/8] ext4: fix endio zeroout corruption by tracking unwritten to-be-converted IOs Ojaswin Mujoo
2026-11-02 18:44   ` sashiko-bot
2026-11-02 18:26 ` [PATCH 3/8] ext4: add tracing for i_conv_pending_ios tracking Ojaswin Mujoo
2026-11-02 18:30   ` sashiko-bot
2026-11-02 18:26 ` [PATCH 4/8] ext4: don't zeroout if we have inflight unwritten IOs in non buffered-iomap path Ojaswin Mujoo
2026-11-02 18:38   ` sashiko-bot
2026-11-02 18:26 ` [PATCH 5/8] ext4: don't zeroout if we have inflight direct IOs Ojaswin Mujoo
2026-11-02 18:47   ` sashiko-bot
2026-11-02 18:26 ` [PATCH 6/8] ext4: make sure zero range WRITE_ZEROES uses NO_CONV_ACC flag Ojaswin Mujoo
2026-11-02 18:47   ` sashiko-bot
2026-11-02 18:26 ` Ojaswin Mujoo [this message]
2026-11-02 18:38   ` [PATCH 7/8] ext4: don't zeroout if we have inflight unwritten IOs in buffered iomap path sashiko-bot
2026-11-02 18:26 ` [PATCH 8/8] ext4: optimize inflight dio tracking for zeroout Ojaswin Mujoo
2026-11-02 18:43   ` sashiko-bot

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=20261102-ext4-endio-zero-bug-v1-7-266d2bb9e6dc@linux.ibm.com \
    --to=ojaswin@linux.ibm.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /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