Re: [PATCH 3/3] ext4: Fix estimate extent index blocks in ext4_ext_index_trans_blocks()

Ojaswin Mujoo <[email protected]> Fri, 7 Aug 2026 12:07:52 +0530
Newsgroups org.kernel.vger.linux-ext4
Message-ID <[email protected]>
On Wed, Aug 05, 2026 at 05:35:49PM +0200, Jan Kara wrote:
> The estimate of the number of impacted extent tree index blocks could be
> one-too-low. If we modify say 2 extents, already two leaf index blocks

Hi Jan,

Its minor but just to be sure, by two "leaf index blocks" do you mean
the two leaf blocks that hold extents or the last index blocks which
hold pointers to leaf blocks?

> could be impacted, not just one the current estimate counts with. Fix
> the estimate.
> 
> Signed-off-by: Jan Kara <[email protected]>
> ---
>  fs/ext4/extents.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 44ab246a3176..713b2c098af5 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -2427,9 +2427,17 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int extents)
>  	 */
>  	if (extents <= 1)
>  		index = (EXT4_MAX_EXTENT_DEPTH * 2) + extents;
> -	else
> -		index = (EXT4_MAX_EXTENT_DEPTH * 3) +
> -			DIV_ROUND_UP(extents, ext4_ext_space_block(inode, 0));
> +	else {
> +		int ext_max = ext4_ext_space_block(inode, 0);
> +
> +		index = EXT4_MAX_EXTENT_DEPTH * 3;
> +		/*
> +		 * Modified extents need not start at the beginning of the
> +		 * leaf. Already two extents may need two leaf block
> +		 * modifications...
> +		 */
> +		index += DIV_ROUND_UP(extents + ext_max - 1, ext_max);
> +	}
>  
>  	return index;
>  }
> -- 
> 2.51.0
>