ext4: Use atomic_t's in struct flex_groups
Theodore Ts'o
maintainerPATCH 1/1 ext4: Use atomic_t's in struct flex_groups
Reduce pressure on the sb_bgl_lock family of locks by using atomic_t's to track the number of free blocks and inodes in each flex_group.
Signed-off-by "Theodore Ts'o" <[email protected]>
--- fs/ext4/balloc.c | 5 ++--- fs/ext4/ext4.h | 4 ++-- fs/ext4/ialloc.c | 33 +++++++++++++++------------------ fs/ext4/mballoc.c | 9 +++------ fs/ext4/resize.c | 8 ++++---- fs/ext4/super.c | 8 ++++---- 6 files changed, 30 insertions(+), 37 deletions(-)
fs/ext4/balloc.c +2 -3
@@ -470,9 +470,8 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,if (sbi->s_log_groups_per_flex) {ext4_group_t flex_group =ext4_flex_group (sbi, block_group); -spin_lock (sb_bgl_lock (sbi, flex_group)); - sbi->s_flex_groups[flex_group].free_blocks += blocks_freed; -spin_unlock (sb_bgl_lock (sbi, flex_group)); +atomic_add (blocks_freed, + &sbi->s_flex_groups[flex_group].free_blocks); }/* * request to reload the buddy with the
fs/ext4/ext4.h +2 -2
@@ -169,8 +169,8 @@ struct ext4_group_desc*/ struct flex_groups { -__u32 free_inodes; -__u32 free_blocks; +atomic_t free_inodes; +atomic_t free_blocks; };#define EXT4_BG_INODE_UNINIT 0x0001/* Inode table/bitmap not in use */
fs/ext4/ialloc.c +15 -18
@@ -189,7 +189,6 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)struct ext4_super_block *es;struct ext4_sb_info *sbi;int fatal =0 , err, count, cleared; -ext4_group_t flex_group;if (atomic_read (&inode->i_count) >1 ) { printk(KERN_ERR "ext4_free_inode: inode has count=%d\n",
@@ -277,10 +276,10 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)percpu_counter_dec (&sbi->s_dirs_counter);if (sbi->s_log_groups_per_flex) { - flex_group =ext4_flex_group (sbi, block_group); -spin_lock (sb_bgl_lock (sbi, flex_group)); - sbi->s_flex_groups[flex_group].free_inodes++; -spin_unlock (sb_bgl_lock (sbi, flex_group)); +ext4_group_t f; + + f =ext4_flex_group (sbi, block_group); +atomic_inc (&sbi->s_flex_groups[f].free_inodes); } }BUFFER_TRACE (bh2,"call ext4_handle_dirty_metadata" );
@@ -360,9 +359,9 @@ static int find_group_flex(struct super_block *sb, struct inode *parent, sbi->s_log_groups_per_flex; find_close_to_parent: - flexbg_free_blocks = flex_group[best_flex].free_blocks; + flexbg_free_blocks =atomic_read (&flex_group[best_flex].free_blocks); flex_freeb_ratio = flexbg_free_blocks *100 / blocks_per_flex; -if (flex_group[best_flex].free_inodes && +if (atomic_read (&flex_group[best_flex].free_inodes) && flex_freeb_ratio > free_block_ratio) goto found_flexbg;
@@ -375,24 +374,24 @@ find_close_to_parent:if (i == parent_fbg_group || i == parent_fbg_group -1 )continue ; - flexbg_free_blocks = flex_group[i].free_blocks; + flexbg_free_blocks =atomic_read (&flex_group[i].free_blocks); flex_freeb_ratio = flexbg_free_blocks *100 / blocks_per_flex;if (flex_freeb_ratio > free_block_ratio && - flex_group[i].free_inodes) { + (atomic_read (&flex_group[i].free_inodes))) { best_flex = i; goto found_flexbg; } -if (flex_group[best_flex].free_inodes ==0 || - (flex_group[i].free_blocks > - flex_group[best_flex].free_blocks && - flex_group[i].free_inodes)) +if ((atomic_read (&flex_group[best_flex].free_inodes) ==0 ) || + ((atomic_read (&flex_group[i].free_blocks) > +atomic_read (&flex_group[best_flex].free_blocks)) && +atomic_read (&flex_group[i].free_inodes))) best_flex = i; } -if (!flex_group[best_flex].free_inodes || - !flex_group[best_flex].free_blocks) +if (!atomic_read (&flex_group[best_flex].free_inodes) || + !atomic_read (&flex_group[best_flex].free_blocks))return -1 ; found_flexbg:
@@ -958,9 +957,7 @@ got:if (sbi->s_log_groups_per_flex) { flex_group =ext4_flex_group (sbi, group); -spin_lock (sb_bgl_lock (sbi, flex_group)); - sbi->s_flex_groups[flex_group].free_inodes--; -spin_unlock (sb_bgl_lock (sbi, flex_group)); +atomic_dec (&sbi->s_flex_groups[flex_group].free_inodes); } inode->i_uid =current_fsuid ();
fs/ext4/mballoc.c +3 -6
@@ -3041,9 +3041,8 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,if (sbi->s_log_groups_per_flex) {ext4_group_t flex_group =ext4_flex_group (sbi, ac->ac_b_ex.fe_group); -spin_lock (sb_bgl_lock (sbi, flex_group)); - sbi->s_flex_groups[flex_group].free_blocks -= ac->ac_b_ex.fe_len; -spin_unlock (sb_bgl_lock (sbi, flex_group)); +atomic_sub (ac->ac_b_ex.fe_len, + &sbi->s_flex_groups[flex_group].free_blocks); } err =ext4_handle_dirty_metadata (handle,NULL , bitmap_bh);
@@ -4871,9 +4870,7 @@ do_more:if (sbi->s_log_groups_per_flex) {ext4_group_t flex_group =ext4_flex_group (sbi, block_group); -spin_lock (sb_bgl_lock (sbi, flex_group)); - sbi->s_flex_groups[flex_group].free_blocks += count; -spin_unlock (sb_bgl_lock (sbi, flex_group)); +atomic_add (count, &sbi->s_flex_groups[flex_group].free_blocks); }ext4_mb_release_desc (&e4b);
fs/ext4/resize.c +4 -4
@@ -938,10 +938,10 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) {ext4_group_t flex_group; flex_group =ext4_flex_group (sbi, input->group); - sbi->s_flex_groups[flex_group].free_blocks += - input->free_blocks_count; - sbi->s_flex_groups[flex_group].free_inodes += -EXT4_INODES_PER_GROUP (sb); +atomic_add (input->free_blocks_count, + &sbi->s_flex_groups[flex_group].free_blocks); +atomic_add (EXT4_INODES_PER_GROUP (sb), + &sbi->s_flex_groups[flex_group].free_inodes); }ext4_handle_dirty_metadata (handle,NULL , sbi->s_sbh);
fs/ext4/super.c +4 -4
@@ -1619,10 +1619,10 @@ static int ext4_fill_flex_info(struct super_block *sb) gdp =ext4_get_group_desc (sb, i, &bh); flex_group =ext4_flex_group (sbi, i); - sbi->s_flex_groups[flex_group].free_inodes += -ext4_free_inodes_count (sb, gdp); - sbi->s_flex_groups[flex_group].free_blocks += -ext4_free_blks_count (sb, gdp); +atomic_set (&sbi->s_flex_groups[flex_group].free_inodes, +ext4_free_inodes_count (sb, gdp)); +atomic_set (&sbi->s_flex_groups[flex_group].free_blocks, +ext4_free_blks_count (sb, gdp)); }return 1 ;
Signature · 1 line
1.5.6.3
Theodore Ts'o
maintainerPATCH 1/1 ext4: Use struct flex_groups to calculate get_orlov_stats()
Instead of looping over all of the block groups in a flex group summing their summary statistics, start tracking used_dirs in struct flex_groups, and use struct flex_groups instead. This should save a bit of CPU for mkdir-heavy workloads.
Signed-off-by "Theodore Ts'o" <[email protected]>
--- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 45 ++++++++++++++++++++++++++++----------------- fs/ext4/super.c | 2 ++ 3 files changed, 31 insertions(+), 17 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -171,6 +171,7 @@ struct ext4_group_descstruct flex_groups {atomic_t free_inodes;atomic_t free_blocks; +atomic_t used_dirs; };#define EXT4_BG_INODE_UNINIT 0x0001/* Inode table/bitmap not in use */
fs/ext4/ialloc.c +28 -17
65 lines not on this page · raw message
fs/ext4/super.c +2 -0
@@ -1623,6 +1623,8 @@ static int ext4_fill_flex_info(struct super_block *sb) ext4_free_inodes_count(sb, gdp));atomic_set (&sbi->s_flex_groups[flex_group].free_blocks,ext4_free_blks_count (sb, gdp)); +atomic_set (&sbi->s_flex_groups[flex_group].used_dirs, +ext4_used_dirs_count (sb, gdp)); }return 1 ;
Signature · 1 line
1.5.6.3