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 v2 02/13] ext4: introduce CONVERT_PENDING extent status type
Date: Fri, 27 Nov 2026 20:40:49 +0530 [thread overview]
Message-ID: <20261127-ext4-endio-zero-bug-v2-2-4106968e4d15@linux.ibm.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com>
Add support to track ranges that are in an unwritten state but actaully
cover valid data. These are the unwritten ranges which have an in progress
disk IO, but are not yet converted to written via endio handling.
Upcoming patches will use this extent type to avoid zerooing out such
ranges during endio extent splitting, because they cover valid data.
The lifecycle of an extent undergoing write is now as follows:
1. Say we start with an extent (0,10,unwrit) which is also cached in es.
Ondisk: [0,10,unwrit]
es cache: [0,10,unwrit]
2. We perform a write to (0, 5):
Ondisk: [0,10,unwrit]
es cache: [0,5,conv_pending][5,10,unwrit]
3. IO is finished and endio handler converts (0,5) to written:
ondisk: [0,5,writ][5,10,unwrit]
es cache: [0,5,writ][5,10,unwrit]
An extent of CONVERT_PENDING type will behave similar to an UNWRITTEN
extent for most of the purposes like read. Just that we will take special
care in es cache to make sure the conv_pending range is not split or merged
so that we don't lose the status. Similarly, it also can't be evicted from
memory because we don't want to lost the status.
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/extents_status-test.c | 8 ++++----
fs/ext4/extents_status.c | 18 ++++++++++++++++++
fs/ext4/extents_status.h | 11 ++++++++++-
include/trace/events/ext4.h | 4 +++-
4 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/extents_status-test.c b/fs/ext4/extents_status-test.c
index 825d12513e4a..014475bae07c 100644
--- a/fs/ext4/extents_status-test.c
+++ b/fs/ext4/extents_status-test.c
@@ -452,13 +452,13 @@ static void test_es_bitfield_written_and_unwritten_encoding(struct kunit *test)
static void test_es_bitfield_delayed_and_hole_encoding(struct kunit *test)
{
struct extent_status es = {};
- /* 59-bit physical block field (64 - 5 status bits) all ones */
- const ext4_fsblk_t max_59bit_pblk = 0x07ffffffffffffffULL;
+ /* 58-bit physical block field (64 - 6 status bits) all ones */
+ const ext4_fsblk_t max_pblk = ~ES_MASK;
ext4_es_store_pblock_status(&es, ~0ULL, EXTENT_STATUS_DELAYED);
KUNIT_EXPECT_TRUE(test, ext4_es_is_delayed(&es));
KUNIT_EXPECT_FALSE(test, ext4_es_is_mapped(&es));
- KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), max_59bit_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), max_pblk);
KUNIT_EXPECT_EQ(test, ext4_es_show_pblock(&es), 0ULL);
ext4_es_store_pblock_status(&es, 0ULL, EXTENT_STATUS_HOLE);
@@ -472,7 +472,7 @@ test_es_bitfield_referenced_and_pblock_update_preserve_state(struct kunit *test)
{
struct extent_status es = {};
const ext4_fsblk_t initial_pblk = 0x123456789abcULL;
- const ext4_fsblk_t updated_pblk = 0x07ffffffffffffffULL;
+ const ext4_fsblk_t updated_pblk = ~ES_MASK;
ext4_es_store_pblock_status(&es, initial_pblk, EXTENT_STATUS_WRITTEN);
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index b7fb8502f9d4..28528f19be1d 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -529,6 +529,9 @@ static inline bool ext4_es_must_keep(struct extent_status *es)
if (ext4_es_is_delayed(es))
return true;
+ if (ext4_es_is_convert_pending(es))
+ return true;
+
return false;
}
@@ -594,6 +597,12 @@ static int ext4_es_can_be_merged(struct extent_status *es1,
if (ext4_es_type(es1) != ext4_es_type(es2))
return 0;
+ /*
+ * Don't merge block range that's about to get converted to written.
+ */
+ if (ext4_es_is_convert_pending(es1))
+ return 0;
+
if (((__u64) es1->es_len) + es2->es_len > EXT_MAX_BLOCKS) {
pr_warn("ES assertion failed when merging extents. "
"The sum of lengths of es1 (%d) and es2 (%d) "
@@ -1076,6 +1085,15 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
ext4_es_type(&chkes) == EXTENT_STATUS_DELAYED)
return;
+ /*
+ * An ondisk unwritten extent is allowed to conflict with
+ * convert_pending since the latter signifies an ondisk unwritten extent
+ * about to be converted to written due to endio.
+ */
+ if (status == EXTENT_STATUS_UNWRITTEN &&
+ ext4_es_type(&chkes) == EXTENT_STATUS_CONVERT_PENDING)
+ return;
+
ext4_warning_inode(inode,
"ES cache extent failed: add [%d,%d,%llu,0x%x] conflict with existing [%d,%d,%llu,0x%x]\n",
lblk, len, pblk, status, chkes.es_lblk, chkes.es_len,
diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
index 01cddcaaa68e..2247f811f6c3 100644
--- a/fs/ext4/extents_status.h
+++ b/fs/ext4/extents_status.h
@@ -36,6 +36,7 @@ enum {
ES_DELAYED_B,
ES_HOLE_B,
ES_REFERENCED_B,
+ ES_CONVERT_PENDING_B,
ES_FLAGS
};
@@ -51,10 +52,12 @@ enum {
#define EXTENT_STATUS_DELAYED (1 << ES_DELAYED_B)
#define EXTENT_STATUS_HOLE (1 << ES_HOLE_B)
#define EXTENT_STATUS_REFERENCED (1 << ES_REFERENCED_B)
+#define EXTENT_STATUS_CONVERT_PENDING (1 << ES_CONVERT_PENDING_B)
#define ES_TYPE_MASK ((ext4_fsblk_t)(EXTENT_STATUS_WRITTEN | \
EXTENT_STATUS_UNWRITTEN | \
EXTENT_STATUS_DELAYED | \
+ EXTENT_STATUS_CONVERT_PENDING | \
EXTENT_STATUS_HOLE))
#define ES_TYPE_VALID(type) ((type) && !((type) & ((type) - 1)))
@@ -173,7 +176,13 @@ static inline int ext4_es_is_written(struct extent_status *es)
static inline int ext4_es_is_unwritten(struct extent_status *es)
{
- return (ext4_es_type(es) & EXTENT_STATUS_UNWRITTEN) != 0;
+ return (ext4_es_type(es) &
+ (EXTENT_STATUS_UNWRITTEN | EXTENT_STATUS_CONVERT_PENDING)) != 0;
+}
+
+static inline int ext4_es_is_convert_pending(struct extent_status *es)
+{
+ return (ext4_es_type(es) & EXTENT_STATUS_CONVERT_PENDING) != 0;
}
static inline int ext4_es_is_delayed(struct extent_status *es)
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 92048da9dae4..4313694cd4e9 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -77,13 +77,15 @@ TRACE_DEFINE_ENUM(ES_UNWRITTEN_B);
TRACE_DEFINE_ENUM(ES_DELAYED_B);
TRACE_DEFINE_ENUM(ES_HOLE_B);
TRACE_DEFINE_ENUM(ES_REFERENCED_B);
+TRACE_DEFINE_ENUM(ES_CONVERT_PENDING_B);
#define show_extent_status(status) __print_flags(status, "", \
{ EXTENT_STATUS_WRITTEN, "W" }, \
{ EXTENT_STATUS_UNWRITTEN, "U" }, \
{ EXTENT_STATUS_DELAYED, "D" }, \
{ EXTENT_STATUS_HOLE, "H" }, \
- { EXTENT_STATUS_REFERENCED, "R" })
+ { EXTENT_STATUS_REFERENCED, "R" }, \
+ { EXTENT_STATUS_CONVERT_PENDING, "C" })
#define show_falloc_mode(mode) __print_flags(mode, "|", \
{ FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"}, \
--
2.55.0
next prev parent reply other threads:[~2026-11-27 15:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:10 [PATCH v2 00/13] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 01/13] ext4: disable zeroout fallback in ext4_split_extent() Ojaswin Mujoo
2026-11-27 15:10 ` Ojaswin Mujoo [this message]
2026-11-27 15:10 ` [PATCH v2 03/13] ext4: preserve convert pending extents when adding unwrit extents to es cache Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 04/13] ext4: add es helper to convert unwrit to convert pending without changing i_es_seq Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 06/13] ext4: add tracking for unwritten to-be-converted ranges in dio write path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 07/13] ext4: add tracking for unwritten to-be-converted ranges in non iomap buffered path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in " Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 09/13] ext4: don't zeroout if conv pending ranges are present Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 10/13] ext4: add tracepoints for extent split and convert Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 11/13] ext4: update extent status cache when zeroing extents Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 12/13] ext4: don't drop the extents in case extent split fails Ojaswin Mujoo
2026-11-27 15:11 ` [PATCH v2 13/13] ext4: re-enable zeroout fallback Ojaswin Mujoo
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=20261127-ext4-endio-zero-bug-v2-2-4106968e4d15@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
all inboxes | Powered by JetHome®