Re: [PATCH v2 02/13] ext4: introduce CONVERT_PENDING extent status type

From: Zhang Yi

Date: Wed Dec 02 2026 - 01:53:56 EST


On 11/27/2026 11:10 PM, Ojaswin Mujoo wrote:
> 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@xxxxxxxxxxxxx>
> ---
> 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;

Why can't we merge two consecutive pending extents? AFAIK, we should
only need to ensure they are not merged with normal unwritten extents,
right?

Thanks,
Yi.