[PATCH v2 07/24] ext4: support large block size in ext4_calculate_overhead()

libaokun@huaweicloud.com posted 24 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 07/24] ext4: support large block size in ext4_calculate_overhead()
Posted by libaokun@huaweicloud.com 1 month, 1 week ago
From: Baokun Li <libaokun1@huawei.com>

ext4_calculate_overhead() used a single page for its bitmap buffer, which
worked fine when PAGE_SIZE >= block size. However, with block size greater
than page size (BS > PS) support, the bitmap can exceed a single page.

To address this, we now use kvmalloc() to allocate memory of the filesystem
block size, to properly support BS > PS.

Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a6314a3de51d..0d32370a459a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4189,7 +4189,7 @@ int ext4_calculate_overhead(struct super_block *sb)
 	unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum);
 	ext4_group_t i, ngroups = ext4_get_groups_count(sb);
 	ext4_fsblk_t overhead = 0;
-	char *buf = (char *) get_zeroed_page(GFP_NOFS);
+	char *buf = kvmalloc(sb->s_blocksize, GFP_NOFS | __GFP_ZERO);
 
 	if (!buf)
 		return -ENOMEM;
@@ -4214,7 +4214,7 @@ int ext4_calculate_overhead(struct super_block *sb)
 		blks = count_overhead(sb, i, buf);
 		overhead += blks;
 		if (blks)
-			memset(buf, 0, PAGE_SIZE);
+			memset(buf, 0, sb->s_blocksize);
 		cond_resched();
 	}
 
@@ -4237,7 +4237,7 @@ int ext4_calculate_overhead(struct super_block *sb)
 	}
 	sbi->s_overhead = overhead;
 	smp_wmb();
-	free_page((unsigned long) buf);
+	kvfree(buf);
 	return 0;
 }
 
-- 
2.46.1
Re: [PATCH v2 07/24] ext4: support large block size in ext4_calculate_overhead()
Posted by Jan Kara 1 month, 1 week ago
On Fri 07-11-25 22:42:32, libaokun@huaweicloud.com wrote:
> From: Baokun Li <libaokun1@huawei.com>
> 
> ext4_calculate_overhead() used a single page for its bitmap buffer, which
> worked fine when PAGE_SIZE >= block size. However, with block size greater
> than page size (BS > PS) support, the bitmap can exceed a single page.
> 
> To address this, we now use kvmalloc() to allocate memory of the filesystem
> block size, to properly support BS > PS.
> 
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/super.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index a6314a3de51d..0d32370a459a 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4189,7 +4189,7 @@ int ext4_calculate_overhead(struct super_block *sb)
>  	unsigned int j_blocks, j_inum = le32_to_cpu(es->s_journal_inum);
>  	ext4_group_t i, ngroups = ext4_get_groups_count(sb);
>  	ext4_fsblk_t overhead = 0;
> -	char *buf = (char *) get_zeroed_page(GFP_NOFS);
> +	char *buf = kvmalloc(sb->s_blocksize, GFP_NOFS | __GFP_ZERO);
>  
>  	if (!buf)
>  		return -ENOMEM;
> @@ -4214,7 +4214,7 @@ int ext4_calculate_overhead(struct super_block *sb)
>  		blks = count_overhead(sb, i, buf);
>  		overhead += blks;
>  		if (blks)
> -			memset(buf, 0, PAGE_SIZE);
> +			memset(buf, 0, sb->s_blocksize);
>  		cond_resched();
>  	}
>  
> @@ -4237,7 +4237,7 @@ int ext4_calculate_overhead(struct super_block *sb)
>  	}
>  	sbi->s_overhead = overhead;
>  	smp_wmb();
> -	free_page((unsigned long) buf);
> +	kvfree(buf);
>  	return 0;
>  }
>  
> -- 
> 2.46.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR