From: Jan Kara <jack@suse.cz>
To: Zhang Yi <yi.zhang@huaweicloud.com>
Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, tytso@mit.edu,
adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com,
yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com
Subject: Re: [PATCH v3 09/10] ext4: make ext4_insert_delayed_block() insert multi-blocks
Date: Sun, 12 May 2024 23:47:51 +0200 [thread overview]
Message-ID: <20240512214751.b4dv6qnhubpuknrc@quack3> (raw)
In-Reply-To: <20240508061220.967970-10-yi.zhang@huaweicloud.com>
On Wed 08-05-24 14:12:19, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> Rename ext4_insert_delayed_block() to ext4_insert_delayed_blocks(),
> pass length parameter to make it insert multiple delalloc blocks at a
> time. For non-bigalloc case, just reserve len blocks and insert delalloc
> extent. For bigalloc case, we can ensure that the clusters in the middle
> of a extent must be unallocated, we only need to check whether the start
> and end clusters are delayed/allocated. We should subtract the space for
> the start and/or end block(s) if they are allocated.
>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Looks good to me. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/inode.c | 48 ++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 34 insertions(+), 14 deletions(-)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 6e418d3f8e87..c56386d1b10d 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -1678,24 +1678,29 @@ static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk,
> }
>
> /*
> - * ext4_insert_delayed_block - adds a delayed block to the extents status
> - * tree, incrementing the reserved cluster/block
> - * count or making a pending reservation
> - * where needed
> + * ext4_insert_delayed_blocks - adds a multiple delayed blocks to the extents
> + * status tree, incrementing the reserved
> + * cluster/block count or making pending
> + * reservations where needed
> *
> * @inode - file containing the newly added block
> - * @lblk - logical block to be added
> + * @lblk - start logical block to be added
> + * @len - length of blocks to be added
> *
> * Returns 0 on success, negative error code on failure.
> */
> -static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
> +static int ext4_insert_delayed_blocks(struct inode *inode, ext4_lblk_t lblk,
> + ext4_lblk_t len)
> {
> struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> int ret;
> - bool allocated = false;
> + bool lclu_allocated = false;
> + bool end_allocated = false;
> + ext4_lblk_t resv_clu;
> + ext4_lblk_t end = lblk + len - 1;
>
> /*
> - * If the cluster containing lblk is shared with a delayed,
> + * If the cluster containing lblk or end is shared with a delayed,
> * written, or unwritten extent in a bigalloc file system, it's
> * already been accounted for and does not need to be reserved.
> * A pending reservation must be made for the cluster if it's
> @@ -1706,21 +1711,36 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk)
> * extents status tree doesn't get a match.
> */
> if (sbi->s_cluster_ratio == 1) {
> - ret = ext4_da_reserve_space(inode, 1);
> + ret = ext4_da_reserve_space(inode, len);
> if (ret != 0) /* ENOSPC */
> return ret;
> } else { /* bigalloc */
> - ret = ext4_da_check_clu_allocated(inode, lblk, &allocated);
> + resv_clu = EXT4_B2C(sbi, end) - EXT4_B2C(sbi, lblk) + 1;
> +
> + ret = ext4_da_check_clu_allocated(inode, lblk, &lclu_allocated);
> if (ret < 0)
> return ret;
> - if (ret > 0) {
> - ret = ext4_da_reserve_space(inode, 1);
> + if (ret == 0)
> + resv_clu--;
> +
> + if (EXT4_B2C(sbi, lblk) != EXT4_B2C(sbi, end)) {
> + ret = ext4_da_check_clu_allocated(inode, end,
> + &end_allocated);
> + if (ret < 0)
> + return ret;
> + if (ret == 0)
> + resv_clu--;
> + }
> +
> + if (resv_clu) {
> + ret = ext4_da_reserve_space(inode, resv_clu);
> if (ret != 0) /* ENOSPC */
> return ret;
> }
> }
>
> - ext4_es_insert_delayed_extent(inode, lblk, 1, allocated, false);
> + ext4_es_insert_delayed_extent(inode, lblk, len, lclu_allocated,
> + end_allocated);
> return 0;
> }
>
> @@ -1825,7 +1845,7 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map,
> }
> }
>
> - retval = ext4_insert_delayed_block(inode, map->m_lblk);
> + retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len);
> up_write(&EXT4_I(inode)->i_data_sem);
> if (retval)
> return retval;
> --
> 2.39.2
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-05-13 13:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 6:12 [PATCH v3 00/10] ext4: support adding multi-delalloc blocks Zhang Yi
2024-05-08 6:12 ` [PATCH v3 01/10] ext4: factor out a common helper to query extent map Zhang Yi
2024-05-08 6:12 ` [PATCH v3 02/10] ext4: check the extent status again before inserting delalloc block Zhang Yi
2024-05-08 15:02 ` Markus Elfring
2024-05-09 8:26 ` Zhang Yi
2024-05-08 6:12 ` [PATCH v3 03/10] ext4: warn if delalloc counters are not zero on inactive Zhang Yi
2024-05-12 15:10 ` Jan Kara
2024-05-13 14:17 ` Zhang Yi
2024-05-08 6:12 ` [PATCH v3 04/10] ext4: trim delalloc extent Zhang Yi
2024-05-08 15:21 ` Markus Elfring
2024-05-09 8:27 ` Zhang Yi
2024-05-08 6:12 ` [PATCH v3 05/10] ext4: drop iblock parameter Zhang Yi
2024-05-08 6:12 ` [PATCH v3 06/10] ext4: make ext4_es_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-12 15:19 ` Jan Kara
2024-05-08 6:12 ` [PATCH v3 07/10] ext4: make ext4_da_reserve_space() reserve multi-clusters Zhang Yi
2024-05-08 6:12 ` [PATCH v3 08/10] ext4: factor out check for whether a cluster is allocated Zhang Yi
2024-05-12 15:40 ` Jan Kara
2024-05-14 2:37 ` Zhang Yi
2024-05-08 6:12 ` [PATCH v3 09/10] ext4: make ext4_insert_delayed_block() insert multi-blocks Zhang Yi
2024-05-12 21:47 ` Jan Kara [this message]
2024-05-08 6:12 ` [PATCH v3 10/10] ext4: make ext4_da_map_blocks() buffer_head unaware Zhang Yi
2024-05-12 21:51 ` Jan Kara
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=20240512214751.b4dv6qnhubpuknrc@quack3 \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=chengzhihao1@huawei.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.com \
--cc=yi.zhang@huaweicloud.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 read-only IMAP folder(s) and NNTP newsgroup(s).