]> Gentwo Git Trees - linux/.git/commitdiff
ext4: support large block size in ext4_calculate_overhead()
authorBaokun Li <libaokun1@huawei.com>
Fri, 21 Nov 2025 09:06:37 +0000 (17:06 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 29 Nov 2025 03:35:26 +0000 (22:35 -0500)
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>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Message-ID: <20251121090654.631996-8-libaokun@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/super.c

index 2286cd1e3cb83472789a889ae733e6e61578a0fd..998ddce49093138aaaf87a34f4eb62c1eb3ebec5 100644 (file)
@@ -4191,7 +4191,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;
@@ -4216,7 +4216,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();
        }
 
@@ -4239,7 +4239,7 @@ int ext4_calculate_overhead(struct super_block *sb)
        }
        sbi->s_overhead = overhead;
        smp_wmb();
-       free_page((unsigned long) buf);
+       kvfree(buf);
        return 0;
 }