Skip to content

Commit f975d6b

Browse files
committed
ext4: teach ext4_statfs() to deal with clusters if bigalloc is enabled
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 24aaa8e commit f975d6b

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎fs/ext4/super.c‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4580,16 +4580,34 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
45804580
return err;
45814581
}
45824582

4583+
/*
4584+
* Note: calculating the overhead so we can be compatible with
4585+
* historical BSD practice is quite difficult in the face of
4586+
* clusters/bigalloc. This is because multiple metadata blocks from
4587+
* different block group can end up in the same allocation cluster.
4588+
* Calculating the exact overhead in the face of clustered allocation
4589+
* requires either O(all block bitmaps) in memory or O(number of block
4590+
* groups**2) in time. We will still calculate the superblock for
4591+
* older file systems --- and if we come across with a bigalloc file
4592+
* system with zero in s_overhead_clusters the estimate will be close to
4593+
* correct especially for very large cluster sizes --- but for newer
4594+
* file systems, it's better to calculate this figure once at mkfs
4595+
* time, and store it in the superblock. If the superblock value is
4596+
* present (even for non-bigalloc file systems), we will use it.
4597+
*/
45834598
static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
45844599
{
45854600
struct super_block *sb = dentry->d_sb;
45864601
struct ext4_sb_info *sbi = EXT4_SB(sb);
45874602
struct ext4_super_block *es = sbi->s_es;
4603+
struct ext4_group_desc *gdp;
45884604
u64 fsid;
45894605
s64 bfree;
45904606

45914607
if (test_opt(sb, MINIX_DF)) {
45924608
sbi->s_overhead_last = 0;
4609+
} else if (es->s_overhead_clusters) {
4610+
sbi->s_overhead_last = le32_to_cpu(es->s_overhead_clusters);
45934611
} else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
45944612
ext4_group_t i, ngroups = ext4_get_groups_count(sb);
45954613
ext4_fsblk_t overhead = 0;
@@ -4604,32 +4622,25 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
46044622
* All of the blocks before first_data_block are
46054623
* overhead
46064624
*/
4607-
overhead = le32_to_cpu(es->s_first_data_block);
4625+
overhead = EXT4_B2C(sbi, le32_to_cpu(es->s_first_data_block));
46084626

46094627
/*
4610-
* Add the overhead attributed to the superblock and
4611-
* block group descriptors. If the sparse superblocks
4612-
* feature is turned on, then not all groups have this.
4628+
* Add the overhead found in each block group
46134629
*/
46144630
for (i = 0; i < ngroups; i++) {
4615-
overhead += ext4_bg_has_super(sb, i) +
4616-
ext4_bg_num_gdb(sb, i);
4631+
gdp = ext4_get_group_desc(sb, i, NULL);
4632+
overhead += ext4_num_overhead_clusters(sb, i, gdp);
46174633
cond_resched();
46184634
}
4619-
4620-
/*
4621-
* Every block group has an inode bitmap, a block
4622-
* bitmap, and an inode table.
4623-
*/
4624-
overhead += ngroups * (2 + sbi->s_itb_per_group);
46254635
sbi->s_overhead_last = overhead;
46264636
smp_wmb();
46274637
sbi->s_blocks_last = ext4_blocks_count(es);
46284638
}
46294639

46304640
buf->f_type = EXT4_SUPER_MAGIC;
46314641
buf->f_bsize = sb->s_blocksize;
4632-
buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last;
4642+
buf->f_blocks = (ext4_blocks_count(es) -
4643+
EXT4_C2B(sbi, sbi->s_overhead_last));
46334644
bfree = percpu_counter_sum_positive(&sbi->s_freeclusters_counter) -
46344645
percpu_counter_sum_positive(&sbi->s_dirtyclusters_counter);
46354646
/* prevent underflow in case that few free space is available */

0 commit comments

Comments
 (0)