From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: Kemeng Shi <shikemeng@huaweicloud.com>,
tytso@mit.edu, adilger.kernel@dilger.ca,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 08/11] ext4: call ext4_mb_mark_context in ext4_group_add_blocks()
Date: Fri, 01 Sep 2023 15:20:09 +0530 [thread overview]
Message-ID: <8734zy8bou.fsf@doe.com> (raw)
In-Reply-To: <20230826155028.4019470-9-shikemeng@huaweicloud.com>
Kemeng Shi <shikemeng@huaweicloud.com> writes:
> Call ext4_mb_mark_context in ext4_group_add_blocks() to remove repeat code.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
> fs/ext4/mballoc.c | 84 +++++++----------------------------------------
> 1 file changed, 12 insertions(+), 72 deletions(-)
I think same comments (like in patch-5 & patch-6) hold for this and the previous patch as well where
we are seperating out bitmap free and buddy free from ext4_group_add_blocks.
-ritesh
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index bb08a71a6e61..fdffa3b40bcd 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -6681,25 +6681,22 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
> int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
> ext4_fsblk_t block, unsigned long count)
> {
> - struct buffer_head *bitmap_bh = NULL;
> - struct buffer_head *gd_bh;
> + struct ext4_mark_context mc;
> ext4_group_t block_group;
> ext4_grpblk_t bit;
> - unsigned int i;
> - struct ext4_group_desc *desc;
> struct ext4_sb_info *sbi = EXT4_SB(sb);
> struct ext4_buddy e4b;
> - int err = 0, ret, free_clusters_count;
> - ext4_grpblk_t clusters_freed;
> + int err = 0;
> ext4_fsblk_t first_cluster = EXT4_B2C(sbi, block);
> ext4_fsblk_t last_cluster = EXT4_B2C(sbi, block + count - 1);
> unsigned long cluster_count = last_cluster - first_cluster + 1;
>
> ext4_debug("Adding block(s) %llu-%llu\n", block, block + count - 1);
>
> - if (count == 0)
> + if (cluster_count == 0)
> return 0;
>
> + ext4_mb_prepare_mark_context(&mc, handle, sb, 0);
> ext4_get_group_no_and_offset(sb, block, &block_group, &bit);
> /*
> * Check to see if we are freeing blocks across a group
> @@ -6712,19 +6709,6 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
> goto error_return;
> }
>
> - bitmap_bh = ext4_read_block_bitmap(sb, block_group);
> - if (IS_ERR(bitmap_bh)) {
> - err = PTR_ERR(bitmap_bh);
> - bitmap_bh = NULL;
> - goto error_return;
> - }
> -
> - desc = ext4_get_group_desc(sb, block_group, &gd_bh);
> - if (!desc) {
> - err = -EIO;
> - goto error_return;
> - }
> -
> if (!ext4_sb_block_valid(sb, NULL, block, count)) {
> ext4_error(sb, "Adding blocks in system zones - "
> "Block = %llu, count = %lu",
> @@ -6733,74 +6717,30 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
> goto error_return;
> }
>
> - BUFFER_TRACE(bitmap_bh, "getting write access");
> - err = ext4_journal_get_write_access(handle, sb, bitmap_bh,
> - EXT4_JTR_NONE);
> + err = ext4_mb_load_buddy(sb, block_group, &e4b);
> if (err)
> goto error_return;
>
> - /*
> - * We are about to modify some metadata. Call the journal APIs
> - * to unshare ->b_data if a currently-committing transaction is
> - * using it
> - */
> - BUFFER_TRACE(gd_bh, "get_write_access");
> - err = ext4_journal_get_write_access(handle, sb, gd_bh, EXT4_JTR_NONE);
> - if (err)
> + err = ext4_mb_mark_context(&mc, block_group, bit, cluster_count,
> + EXT4_MB_BITMAP_MARKED_CHECK);
> + if (err && mc.changed == 0) {
> + ext4_mb_unload_buddy(&e4b);
> goto error_return;
> -
> - for (i = 0, clusters_freed = 0; i < cluster_count; i++) {
> - BUFFER_TRACE(bitmap_bh, "clear bit");
> - if (!mb_test_bit(bit + i, bitmap_bh->b_data)) {
> - ext4_error(sb, "bit already cleared for block %llu",
> - (ext4_fsblk_t)(block + i));
> - BUFFER_TRACE(bitmap_bh, "bit already cleared");
> - } else {
> - clusters_freed++;
> - }
> }
>
> - err = ext4_mb_load_buddy(sb, block_group, &e4b);
> - if (err)
> - goto error_return;
> -
> - ext4_lock_group(sb, block_group);
> - mb_clear_bits(bitmap_bh->b_data, bit, cluster_count);
> - free_clusters_count = clusters_freed +
> - ext4_free_group_clusters(sb, desc);
> - ext4_free_group_clusters_set(sb, desc, free_clusters_count);
> - ext4_block_bitmap_csum_set(sb, desc, bitmap_bh);
> - ext4_group_desc_csum_set(sb, block_group, desc);
> - ext4_unlock_group(sb, block_group);
> + if (mc.changed != cluster_count)
> + ext4_error(sb, "bit already cleared in group %u", block_group);
>
> ext4_lock_group(sb, block_group);
> mb_free_blocks(NULL, &e4b, bit, cluster_count);
> ext4_unlock_group(sb, block_group);
>
> percpu_counter_add(&sbi->s_freeclusters_counter,
> - clusters_freed);
> -
> - if (sbi->s_log_groups_per_flex) {
> - ext4_group_t flex_group = ext4_flex_group(sbi, block_group);
> - atomic64_add(clusters_freed,
> - &sbi_array_rcu_deref(sbi, s_flex_groups,
> - flex_group)->free_clusters);
> - }
> + mc.changed);
>
> ext4_mb_unload_buddy(&e4b);
>
> - /* We dirtied the bitmap block */
> - BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
> - err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
> -
> - /* And the group descriptor block */
> - BUFFER_TRACE(gd_bh, "dirtied group descriptor block");
> - ret = ext4_handle_dirty_metadata(handle, NULL, gd_bh);
> - if (!err)
> - err = ret;
> -
> error_return:
> - brelse(bitmap_bh);
> ext4_std_error(sb, err);
> return err;
> }
> --
> 2.30.0
next prev parent reply other threads:[~2023-09-01 9:50 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-26 15:50 [PATCH v6 00/11] cleanups and unit test for mballoc Kemeng Shi
2023-08-26 15:50 ` [PATCH v6 01/11] ext4: factor out codes to update block bitmap and group descriptor on disk from ext4_mb_mark_bb Kemeng Shi
2023-08-31 12:33 ` Ritesh Harjani
2023-08-31 13:42 ` Kemeng Shi
2023-08-31 14:07 ` Ritesh Harjani
2023-09-04 2:50 ` Kemeng Shi
2023-09-04 8:30 ` Ritesh Harjani
2023-08-26 15:50 ` [PATCH v6 02/11] ext4: call ext4_mb_mark_context in ext4_free_blocks_simple Kemeng Shi
2023-08-31 14:25 ` Ritesh Harjani
2023-09-04 2:51 ` Kemeng Shi
2023-08-26 15:50 ` [PATCH v6 03/11] ext4: extent ext4_mb_mark_context to support allocation under journal Kemeng Shi
2023-08-31 15:51 ` Ritesh Harjani
2023-08-26 15:50 ` [PATCH v6 04/11] ext4: call ext4_mb_mark_context in ext4_mb_mark_diskspace_used Kemeng Shi
2023-09-01 3:51 ` Ritesh Harjani
2023-09-04 2:54 ` Kemeng Shi
2023-08-26 15:50 ` [PATCH v6 05/11] ext4: Separate block bitmap and buddy bitmap freeing in ext4_mb_clear_bb() Kemeng Shi
2023-09-01 9:34 ` Ritesh Harjani
2023-09-04 3:00 ` Kemeng Shi
2023-09-12 7:02 ` Kemeng Shi
2023-09-12 10:13 ` Ritesh Harjani
2023-09-12 11:32 ` Kemeng Shi
2023-08-26 15:50 ` [PATCH v6 06/11] ext4: call ext4_mb_mark_context in ext4_mb_clear_bb Kemeng Shi
2023-09-01 9:38 ` Ritesh Harjani
2023-08-26 15:50 ` [PATCH v6 07/11] ext4: Separate block bitmap and buddy bitmap freeing in ext4_group_add_blocks() Kemeng Shi
2023-08-26 15:50 ` [PATCH v6 08/11] ext4: call ext4_mb_mark_context " Kemeng Shi
2023-09-01 9:50 ` Ritesh Harjani [this message]
2023-08-26 15:50 ` [PATCH v6 09/11] ext4: add some kunit stub for mballoc kunit test Kemeng Shi
2023-09-01 14:18 ` Ritesh Harjani
2023-08-26 15:50 ` [PATCH v6 10/11] ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc Kemeng Shi
2023-09-01 14:29 ` Ritesh Harjani
2023-08-26 15:50 ` [PATCH v6 11/11] ext4: run mballoc test with different layouts setting Kemeng Shi
2023-09-01 14:36 ` Ritesh Harjani
2023-09-04 3:01 ` Kemeng Shi
2023-08-29 19:02 ` [PATCH v6 00/11] cleanups and unit test for mballoc Ritesh Harjani
2023-08-30 7:22 ` Kemeng Shi
2023-08-31 14:35 ` Ritesh Harjani
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=8734zy8bou.fsf@doe.com \
--to=ritesh.list@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shikemeng@huaweicloud.com \
--cc=tytso@mit.edu \
/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).