Skip to content

Commit 026d0d2

Browse files
Kiselev, Olegtytso
authored andcommitted
ext4: reduce computation of overhead during resize
This patch avoids doing an O(n**2)-complexity walk through every flex group. Instead, it uses the already computed overhead information for the newly allocated space, and simply adds it to the previously calculated overhead stored in the superblock. This drastically reduces the time taken to resize very large bigalloc filesystems (from 3+ hours for a 64TB fs down to milliseconds). Signed-off-by: Oleg Kiselev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 4a734f0 commit 026d0d2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

fs/ext4/resize.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,17 @@ static int ext4_setup_new_descs(handle_t *handle, struct super_block *sb,
13831383
return err;
13841384
}
13851385

1386+
static void ext4_add_overhead(struct super_block *sb,
1387+
const ext4_fsblk_t overhead)
1388+
{
1389+
struct ext4_sb_info *sbi = EXT4_SB(sb);
1390+
struct ext4_super_block *es = sbi->s_es;
1391+
1392+
sbi->s_overhead += overhead;
1393+
es->s_overhead_clusters = cpu_to_le32(sbi->s_overhead);
1394+
smp_wmb();
1395+
}
1396+
13861397
/*
13871398
* ext4_update_super() updates the super block so that the newly added
13881399
* groups can be seen by the filesystem.
@@ -1484,9 +1495,17 @@ static void ext4_update_super(struct super_block *sb,
14841495
}
14851496

14861497
/*
1487-
* Update the fs overhead information
1498+
* Update the fs overhead information.
1499+
*
1500+
* For bigalloc, if the superblock already has a properly calculated
1501+
* overhead, update it with a value based on numbers already computed
1502+
* above for the newly allocated capacity.
14881503
*/
1489-
ext4_calculate_overhead(sb);
1504+
if (ext4_has_feature_bigalloc(sb) && (sbi->s_overhead != 0))
1505+
ext4_add_overhead(sb,
1506+
EXT4_NUM_B2C(sbi, blocks_count - free_blocks));
1507+
else
1508+
ext4_calculate_overhead(sb);
14901509
es->s_overhead_clusters = cpu_to_le32(sbi->s_overhead);
14911510

14921511
if (test_opt(sb, DEBUG))

0 commit comments

Comments
 (0)