]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ext4: correct calculation of s_mb_preallocated
authorKemeng Shi <shikemeng@huaweicloud.com>
Fri, 3 Mar 2023 17:21:04 +0000 (01:21 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 6 Apr 2023 05:13:11 +0000 (01:13 -0400)
We will add pa_free to s_mb_preallocated when new ext4_prealloc_space is
created. In ext4_mb_new_inode_pa, we will call ext4_mb_use_inode_pa
before adding pa_free to s_mb_preallocated. However, ext4_mb_use_inode_pa
will consume pa_free for block allocation which triggerred the creation
of ext4_prealloc_space. Add pa_free to s_mb_preallocated before
ext4_mb_use_inode_pa to correct calculation of s_mb_preallocated.
There is no such problem in ext4_mb_new_group_pa as pa_free of group pa
is consumed in ext4_mb_release_context instead of ext4_mb_use_group_pa.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://lore.kernel.org/r/20230303172120.3800725-5-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mballoc.c

index c3c4d9e26b39e12ab43c4d508308b1d464d04e33..e549e88c304b2b75bdf5b985ccf98bcc6b55b6b2 100644 (file)
@@ -4671,8 +4671,8 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
                 pa->pa_len, pa->pa_lstart);
        trace_ext4_mb_new_inode_pa(ac, pa);
 
-       ext4_mb_use_inode_pa(ac, pa);
        atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
+       ext4_mb_use_inode_pa(ac, pa);
 
        ei = EXT4_I(ac->ac_inode);
        grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);