linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Yi <yi.zhang@huaweicloud.com>
To: tytso@mit.edu, linux-ext4@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	willy@infradead.org, adilger.kernel@dilger.ca, jack@suse.cz,
	yi.zhang@huawei.com, libaokun1@huawei.com, yukuai3@huawei.com,
	yangerkun@huawei.com
Subject: Re: [PATCH v2 5/8] ext4: correct the journal credits calculations of allocating blocks
Date: Mon, 19 May 2025 10:48:28 +0800	[thread overview]
Message-ID: <2e127ed8-20a2-4610-8fd8-e2095bde0577@huaweicloud.com> (raw)
In-Reply-To: <20250512063319.3539411-6-yi.zhang@huaweicloud.com>

Hi Ted.

On 2025/5/12 14:33, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> The journal credits calculation in ext4_ext_index_trans_blocks() is
> currently inadequate. It only multiplies the depth of the extents tree
> and doesn't account for the blocks that may be required for adding the
> leaf extents themselves.
> 
> After enabling large folios, we can easily run out of handle credits,
> triggering a warning in jbd2_journal_dirty_metadata() on filesystems
> with a 1KB block size. This occurs because we may need more extents when
> iterating through each large folio in
> ext4_do_writepages()->mpage_map_and_submit_extent(). Therefore, we
> should modify ext4_ext_index_trans_blocks() to include a count of the
> leaf extents in the worst case as well.
> 
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> ---
>  fs/ext4/extents.c |  5 +++--
>  fs/ext4/inode.c   | 10 ++++------
>  2 files changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index c616a16a9f36..e759941bd262 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -2405,9 +2405,10 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int extents)
>  	depth = ext_depth(inode);
>  
>  	if (extents <= 1)
> -		index = depth * 2;
> +		index = depth * 2 + extents;
>  	else
> -		index = depth * 3;
> +		index = depth * 3 +
> +			DIV_ROUND_UP(extents, ext4_ext_space_block(inode, 0));
>  
>  	return index;
>  }

This patch conflicts with Jan's patch e18d4f11d240 ("ext4: fix
calculation of credits for extent tree modification") in
ext4_ext_index_trans_blocks(), the conflict should be resolved when
merging this patch. However, I checked the merged commit of this patch
in your dev branch[1], and the changes in ext4_ext_index_trans_blocks()
seem to be incorrect, which could result in insufficient credit
reservations on 1K block size filesystems.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git/commit/?h=dev&id=d80af138eb8873eb13f5fece1adabb3ca4325134

I think the correct conflict resolution in ext4_ext_index_trans_blocks()
should be:

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9053fe68ee4c..431d66181721 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2409,9 +2409,10 @@ int ext4_ext_index_trans_blocks(struct inode *inode, int extents)
         * the time we actually modify the tree. Assume the worst case.
         */
        if (extents <= 1)
-               index = EXT4_MAX_EXTENT_DEPTH * 2;
+               index = EXT4_MAX_EXTENT_DEPTH * 2 + extents;
        else
-               index = EXT4_MAX_EXTENT_DEPTH * 3;
+               index = EXT4_MAX_EXTENT_DEPTH * 3 +
+                       DIV_ROUND_UP(extents, ext4_ext_space_block(inode, 0));

        return index;

Best Regards,
Yi.


> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index ffbf444b56d4..3e962a760d71 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5792,18 +5792,16 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
>  	int ret;
>  
>  	/*
> -	 * How many index blocks need to touch to map @lblocks logical blocks
> -	 * to @pextents physical extents?
> +	 * How many index and lead blocks need to touch to map @lblocks
> +	 * logical blocks to @pextents physical extents?
>  	 */
>  	idxblocks = ext4_index_trans_blocks(inode, lblocks, pextents);
>  
> -	ret = idxblocks;
> -
>  	/*
>  	 * Now let's see how many group bitmaps and group descriptors need
>  	 * to account
>  	 */
> -	groups = idxblocks + pextents;
> +	groups = idxblocks;
>  	gdpblocks = groups;
>  	if (groups > ngroups)
>  		groups = ngroups;
> @@ -5811,7 +5809,7 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
>  		gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count;
>  
>  	/* bitmaps and block group descriptor blocks */
> -	ret += groups + gdpblocks;
> +	ret = idxblocks + groups + gdpblocks;
>  
>  	/* Blocks for super block, inode, quota and xattr blocks */
>  	ret += EXT4_META_TRANS_BLOCKS(inode->i_sb);


  reply	other threads:[~2025-05-19  2:48 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  6:33 [PATCH v2 0/8] ext4: enable large folio for regular files Zhang Yi
2025-05-12  6:33 ` [PATCH v2 1/8] ext4: make ext4_mpage_readpages() support large folios Zhang Yi
2025-05-20 10:41   ` Ojaswin Mujoo
2025-05-12  6:33 ` [PATCH v2 2/8] ext4: make regular file's buffered write path " Zhang Yi
2025-05-12  6:33 ` [PATCH v2 3/8] ext4: make __ext4_block_zero_page_range() support large folio Zhang Yi
2025-05-20 10:41   ` Ojaswin Mujoo
2025-05-12  6:33 ` [PATCH v2 4/8] ext4/jbd2: convert jbd2_journal_blocks_per_page() to " Zhang Yi
2025-05-19 20:16   ` Jan Kara
2025-05-20 12:46     ` Zhang Yi
2025-05-21 10:31       ` Jan Kara
2025-05-12  6:33 ` [PATCH v2 5/8] ext4: correct the journal credits calculations of allocating blocks Zhang Yi
2025-05-19  2:48   ` Zhang Yi [this message]
2025-05-19 15:48     ` Theodore Ts'o
2025-05-20 13:04       ` Zhang Yi
2025-05-19 20:24   ` Jan Kara
2025-05-20 12:53     ` Zhang Yi
2025-05-12  6:33 ` [PATCH v2 6/8] ext4: make the writeback path support large folios Zhang Yi
2025-05-20 10:42   ` Ojaswin Mujoo
2025-05-12  6:33 ` [PATCH v2 7/8] ext4: make online defragmentation " Zhang Yi
2025-05-12  6:33 ` [PATCH v2 8/8] ext4: enable large folio for regular file Zhang Yi
2025-05-16  9:05   ` kernel test robot
2025-05-20 10:48   ` Ojaswin Mujoo
2025-06-25  8:14   ` Lai, Yi
2025-06-25 13:15     ` Theodore Ts'o
2025-06-26  3:35       ` Lai, Yi
2025-06-26 11:29   ` D, Suneeth
2025-06-26 13:26     ` Zhang Yi
2025-06-26 14:56       ` Theodore Ts'o
2025-07-03 14:13         ` Zhang Yi
2025-05-16 11:48 ` [PATCH v2 0/8] ext4: enable large folio for regular files Ojaswin Mujoo
2025-05-19  1:19   ` Zhang Yi
2025-05-19 11:02     ` Ojaswin Mujoo
2025-05-19 20:33 ` Jan Kara
2025-05-20 13:09   ` Zhang Yi
2025-05-20 10:37 ` Ojaswin Mujoo
2025-05-20 13:41   ` Zhang Yi
2025-05-20 14:40 ` Theodore Ts'o

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=2e127ed8-20a2-4610-8fd8-e2095bde0577@huaweicloud.com \
    --to=yi.zhang@huaweicloud.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun1@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=willy@infradead.org \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@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;
as well as URLs for NNTP newsgroup(s).