diff mbox series

[v6,02/11] ext4: call ext4_mb_mark_context in ext4_free_blocks_simple

Message ID 20230826155028.4019470-3-shikemeng@huaweicloud.com
State Superseded
Headers show
Series cleanups and unit test for mballoc | expand

Commit Message

Kemeng Shi Aug. 26, 2023, 3:50 p.m. UTC
call ext4_mb_mark_context in ext4_free_blocks_simple to:
1. remove repeat code
2. pair update of free_clusters in ext4_mb_new_blocks_simple.
3. add missing ext4_lock_group/ext4_unlock_group protection.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 35 +++--------------------------------
 1 file changed, 3 insertions(+), 32 deletions(-)

Comments

Ritesh Harjani (IBM) Aug. 31, 2023, 2:25 p.m. UTC | #1
Kemeng Shi <shikemeng@huaweicloud.com> writes:

> call ext4_mb_mark_context in ext4_free_blocks_simple to:
> 1. remove repeat code
> 2. pair update of free_clusters in ext4_mb_new_blocks_simple.
> 3. add missing ext4_lock_group/ext4_unlock_group protection.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/mballoc.c | 35 +++--------------------------------
>  1 file changed, 3 insertions(+), 32 deletions(-)

Looks good to me. Please feel free to add - 

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

(One small comment below for previous patch)

>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index e2be572deb75..c803f74aaf63 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -6414,43 +6414,14 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
>  static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block,
>  					unsigned long count)
>  {
> -	struct buffer_head *bitmap_bh;
> +	struct ext4_mark_context mc;
>  	struct super_block *sb = inode->i_sb;
> -	struct ext4_group_desc *gdp;
> -	struct buffer_head *gdp_bh;
>  	ext4_group_t group;
>  	ext4_grpblk_t blkoff;
> -	int already_freed = 0, err, i;
>  
> +	ext4_mb_prepare_mark_context(&mc, sb, 0);

It looks like we always use 0 or 1 as the state for struct
ext4_mark_context. In that case we can keep state member of this struct
as bool instead of int. 


>  	ext4_get_group_no_and_offset(sb, block, &group, &blkoff);
> -	bitmap_bh = ext4_read_block_bitmap(sb, group);
> -	if (IS_ERR(bitmap_bh)) {
> -		pr_warn("Failed to read block bitmap\n");
> -		return;
> -	}
> -	gdp = ext4_get_group_desc(sb, group, &gdp_bh);
> -	if (!gdp)
> -		goto err_out;
> -
> -	for (i = 0; i < count; i++) {
> -		if (!mb_test_bit(blkoff + i, bitmap_bh->b_data))
> -			already_freed++;
> -	}
> -	mb_clear_bits(bitmap_bh->b_data, blkoff, count);
> -	err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh);
> -	if (err)
> -		goto err_out;
> -	ext4_free_group_clusters_set(
> -		sb, gdp, ext4_free_group_clusters(sb, gdp) +
> -		count - already_freed);
> -	ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh);
> -	ext4_group_desc_csum_set(sb, group, gdp);
> -	ext4_handle_dirty_metadata(NULL, NULL, gdp_bh);
> -	sync_dirty_buffer(bitmap_bh);
> -	sync_dirty_buffer(gdp_bh);
> -
> -err_out:
> -	brelse(bitmap_bh);
> +	ext4_mb_mark_context(&mc, group, blkoff, count);
>  }
>  
>  /**
> -- 
> 2.30.0
Kemeng Shi Sept. 4, 2023, 2:51 a.m. UTC | #2
on 8/31/2023 10:25 PM, Ritesh Harjani wrote:
> Kemeng Shi <shikemeng@huaweicloud.com> writes:
> 
>> call ext4_mb_mark_context in ext4_free_blocks_simple to:
>> 1. remove repeat code
>> 2. pair update of free_clusters in ext4_mb_new_blocks_simple.
>> 3. add missing ext4_lock_group/ext4_unlock_group protection.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>>  fs/ext4/mballoc.c | 35 +++--------------------------------
>>  1 file changed, 3 insertions(+), 32 deletions(-)
> 
> Looks good to me. Please feel free to add - 
> 
> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> 
> (One small comment below for previous patch)
> 
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index e2be572deb75..c803f74aaf63 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -6414,43 +6414,14 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
>>  static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block,
>>  					unsigned long count)
>>  {
>> -	struct buffer_head *bitmap_bh;
>> +	struct ext4_mark_context mc;
>>  	struct super_block *sb = inode->i_sb;
>> -	struct ext4_group_desc *gdp;
>> -	struct buffer_head *gdp_bh;
>>  	ext4_group_t group;
>>  	ext4_grpblk_t blkoff;
>> -	int already_freed = 0, err, i;
>>  
>> +	ext4_mb_prepare_mark_context(&mc, sb, 0);
> 
> It looks like we always use 0 or 1 as the state for struct
> ext4_mark_context. In that case we can keep state member of this struct
> as bool instead of int. 
Get it. Thanks for pointing it out!
> 
> 
>>  	ext4_get_group_no_and_offset(sb, block, &group, &blkoff);
>> -	bitmap_bh = ext4_read_block_bitmap(sb, group);
>> -	if (IS_ERR(bitmap_bh)) {
>> -		pr_warn("Failed to read block bitmap\n");
>> -		return;
>> -	}
>> -	gdp = ext4_get_group_desc(sb, group, &gdp_bh);
>> -	if (!gdp)
>> -		goto err_out;
>> -
>> -	for (i = 0; i < count; i++) {
>> -		if (!mb_test_bit(blkoff + i, bitmap_bh->b_data))
>> -			already_freed++;
>> -	}
>> -	mb_clear_bits(bitmap_bh->b_data, blkoff, count);
>> -	err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh);
>> -	if (err)
>> -		goto err_out;
>> -	ext4_free_group_clusters_set(
>> -		sb, gdp, ext4_free_group_clusters(sb, gdp) +
>> -		count - already_freed);
>> -	ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh);
>> -	ext4_group_desc_csum_set(sb, group, gdp);
>> -	ext4_handle_dirty_metadata(NULL, NULL, gdp_bh);
>> -	sync_dirty_buffer(bitmap_bh);
>> -	sync_dirty_buffer(gdp_bh);
>> -
>> -err_out:
>> -	brelse(bitmap_bh);
>> +	ext4_mb_mark_context(&mc, group, blkoff, count);
>>  }
>>  
>>  /**
>> -- 
>> 2.30.0
>
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index e2be572deb75..c803f74aaf63 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -6414,43 +6414,14 @@  ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
 static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block,
 					unsigned long count)
 {
-	struct buffer_head *bitmap_bh;
+	struct ext4_mark_context mc;
 	struct super_block *sb = inode->i_sb;
-	struct ext4_group_desc *gdp;
-	struct buffer_head *gdp_bh;
 	ext4_group_t group;
 	ext4_grpblk_t blkoff;
-	int already_freed = 0, err, i;
 
+	ext4_mb_prepare_mark_context(&mc, sb, 0);
 	ext4_get_group_no_and_offset(sb, block, &group, &blkoff);
-	bitmap_bh = ext4_read_block_bitmap(sb, group);
-	if (IS_ERR(bitmap_bh)) {
-		pr_warn("Failed to read block bitmap\n");
-		return;
-	}
-	gdp = ext4_get_group_desc(sb, group, &gdp_bh);
-	if (!gdp)
-		goto err_out;
-
-	for (i = 0; i < count; i++) {
-		if (!mb_test_bit(blkoff + i, bitmap_bh->b_data))
-			already_freed++;
-	}
-	mb_clear_bits(bitmap_bh->b_data, blkoff, count);
-	err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh);
-	if (err)
-		goto err_out;
-	ext4_free_group_clusters_set(
-		sb, gdp, ext4_free_group_clusters(sb, gdp) +
-		count - already_freed);
-	ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh);
-	ext4_group_desc_csum_set(sb, group, gdp);
-	ext4_handle_dirty_metadata(NULL, NULL, gdp_bh);
-	sync_dirty_buffer(bitmap_bh);
-	sync_dirty_buffer(gdp_bh);
-
-err_out:
-	brelse(bitmap_bh);
+	ext4_mb_mark_context(&mc, group, blkoff, count);
 }
 
 /**