Re: [PATCH v2 11/13] ext4: update extent status cache when zeroing extents

From: Zhang Yi

Date: Thu Dec 03 2026 - 04:32:07 EST


On 11/27/2026 11:10 PM, Ojaswin Mujoo wrote:
> In case of zeroout fallback, make sure to mark the zeroed ranges as written
> in the extent status tree. Be careful of only doing so once we are sure the
> zeroout has succeeded and we have converted the extent to written.
>

I don't think this is correct, because it violates the EXT4_EX_NOCACHE
rule. In the writeback context, we do not hold i_rwsem or
invalidate_lock, so we must not load or insert any extent cache outside
the range being mapped or converted. Otherwise, this would resurrect the
issue fixed by 402e38e6b71f. The comment in
ext4_convert_unwritten_extents() before calling ext4_map_blocks()
already explains this.

In the non-EXT4_EX_NOCACHE case, I think the range inserted by
ext4_split_convert_extents() should already cover the zeroed part. As I
understand it, there should be no need to insert it separately, right?

Thanks,
Yi.

> Signed-off-by: Ojaswin Mujoo <ojaswin@xxxxxxxxxxxxx>
> ---
> fs/ext4/extents.c | 26 +++++++++++++++++++++++++-
> 1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 0f5d9f3c42a9..e8ebc518e58b 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3341,8 +3341,15 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
> ext4_lblk_t ee_block;
> uint64_t lblk, pblk, len;
> int is_unwrit;
> - int err = 0;
> + int err = 0, i, nr_zeroed = 0;
> loff_t map_end, ex_end;
> + /*
> + * zeroed[] is used to record ranges successfully zeroed so only these
> + * can be added to the cache
> + */
> + struct {
> + uint64_t lblk, len, pblk;
> + } zeroed[2];
>
> depth = ext_depth(inode);
> ex = path[depth].p_ext;
> @@ -3397,6 +3404,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
> if (err)
> /* ZEROOUT failed, just return original error */
> return err;
> +
> + zeroed[nr_zeroed].lblk = lblk;
> + zeroed[nr_zeroed].len = len;
> + zeroed[nr_zeroed++].pblk = pblk;
> }
>
> /* zeroout right */
> @@ -3413,6 +3424,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
> if (err)
> /* ZEROOUT failed, just return original error */
> return err;
> +
> + zeroed[nr_zeroed].lblk = lblk;
> + zeroed[nr_zeroed].len = len;
> + zeroed[nr_zeroed++].pblk = pblk;
> }
> } else if (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN) {
> /*
> @@ -3435,6 +3450,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
> if (err)
> /* ZEROOUT failed, just return original error */
> return err;
> +
> + zeroed[nr_zeroed].lblk = lblk;
> + zeroed[nr_zeroed].len = len;
> + zeroed[nr_zeroed++].pblk = pblk;
> } else {
> /*
> * We no longer perform unwritten to unwritten splits in IO paths.
> @@ -3450,6 +3469,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
>
> ext4_ext_mark_initialized(ex);
>
> + for (i = 0; i < nr_zeroed; i++)
> + ext4_es_insert_extent(inode, zeroed[i].lblk, zeroed[i].len,
> + zeroed[i].pblk, EXTENT_STATUS_WRITTEN,
> + false);
> +
> err = ext4_ext_dirty(handle, inode, path + depth);
> if (err)
> return err;
>