Skip to content

Commit a71ce8c

Browse files
Badari PulavartyLinus Torvalds
authored andcommitted
ext3: statfs speed up
This is a patch that speeds up statfs. It is very simple - the "overhead" calculation, which takes a huge amount of time for large filesystems, never changes unless the size of the filesystem itself changes. That means we can store it in memory and only recalculate if the filesystem has been resized (almost never). It also fixes a minor problem that we never update the on-disk superblock free blocks/inodes counts until the filesystem is unmounted. While not fatal, we may as well update that on disk when we have the information, and it makes things like debugfs and dumpe2fs report a bit more accurate info. Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com> Signed-off-by: Andreas Dilger <adilger@clusterfs.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2235219 commit a71ce8c

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎fs/ext3/super.c‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,19 +2426,19 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
24262426
struct super_block *sb = dentry->d_sb;
24272427
struct ext3_sb_info *sbi = EXT3_SB(sb);
24282428
struct ext3_super_block *es = sbi->s_es;
2429-
ext3_fsblk_t overhead;
2430-
int i;
24312429
u64 fsid;
24322430

2433-
if (test_opt (sb, MINIX_DF))
2434-
overhead = 0;
2435-
else {
2436-
unsigned long ngroups;
2437-
ngroups = EXT3_SB(sb)->s_groups_count;
2431+
if (test_opt(sb, MINIX_DF)) {
2432+
sbi->s_overhead_last = 0;
2433+
} else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
2434+
unsigned long ngroups = sbi->s_groups_count, i;
2435+
ext3_fsblk_t overhead = 0;
24382436
smp_rmb();
24392437

24402438
/*
2441-
* Compute the overhead (FS structures)
2439+
* Compute the overhead (FS structures). This is constant
2440+
* for a given filesystem unless the number of block groups
2441+
* changes so we cache the previous value until it does.
24422442
*/
24432443

24442444
/*
@@ -2462,18 +2462,23 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
24622462
* Every block group has an inode bitmap, a block
24632463
* bitmap, and an inode table.
24642464
*/
2465-
overhead += (ngroups * (2 + EXT3_SB(sb)->s_itb_per_group));
2465+
overhead += ngroups * (2 + sbi->s_itb_per_group);
2466+
sbi->s_overhead_last = overhead;
2467+
smp_wmb();
2468+
sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
24662469
}
24672470

24682471
buf->f_type = EXT3_SUPER_MAGIC;
24692472
buf->f_bsize = sb->s_blocksize;
2470-
buf->f_blocks = le32_to_cpu(es->s_blocks_count) - overhead;
2473+
buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last;
24712474
buf->f_bfree = percpu_counter_sum(&sbi->s_freeblocks_counter);
2475+
es->s_free_blocks_count = cpu_to_le32(buf->f_bfree);
24722476
buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count);
24732477
if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count))
24742478
buf->f_bavail = 0;
24752479
buf->f_files = le32_to_cpu(es->s_inodes_count);
24762480
buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter);
2481+
es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
24772482
buf->f_namelen = EXT3_NAME_LEN;
24782483
fsid = le64_to_cpup((void *)es->s_uuid) ^
24792484
le64_to_cpup((void *)es->s_uuid + sizeof(u64));

‎include/linux/ext3_fs_sb.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct ext3_sb_info {
3838
unsigned long s_gdb_count; /* Number of group descriptor blocks */
3939
unsigned long s_desc_per_block; /* Number of group descriptors per block */
4040
unsigned long s_groups_count; /* Number of groups in the fs */
41+
unsigned long s_overhead_last; /* Last calculated overhead */
42+
unsigned long s_blocks_last; /* Last seen block count */
4143
struct buffer_head * s_sbh; /* Buffer containing the super block */
4244
struct ext3_super_block * s_es; /* Pointer to the super block in the buffer */
4345
struct buffer_head ** s_group_desc;

0 commit comments

Comments
 (0)