ext4: use mb_optimize_scan regardless of inode format
Jan Kara
reviewerv3 cover ext4: use mb_optimize_scan regardless of inode format
Hello,
this patch series enables use of mballoc optimizations regardless of the inode format. See patch 2 for details.
Changes since v2:
* Added barrier into ext4_get_allocation_groups_count() as suggested by Pedro Falcato
* Collected reviewed-by tags
Changes since v1:
* Added patch to make sure mballoc doesn't select group with block numbers greater than 2^32 for indirect block based inodes
Honza
Previous versions:
Jan Kara
reviewerPATCH v3 1/2 ext4: always allocate blocks only from groups inode can use
For filesystems with more than 2^32 blocks inodes using indirect block based format cannot use blocks beyond the 32-bit limit. ext4_mb_scan_groups_linear() takes care to not select these unsupported groups for such inodes however other functions selecting groups for allocation don't. So far this is harmless because the other selection functions are used only with mb_optimize_scan and this is currently disabled for inodes with indirect blocks however in the following patch we want to enable mb_optimize_scan regardless of inode format.
--- fs/ext4/mballoc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
fs/ext4/mballoc.c +20 -9
@@ -892,6 +892,21 @@ mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) } } +static ext4_group_t ext4_get_allocation_groups_count ( +struct ext4_allocation_context *ac) +{ +ext4_group_t ngroups =ext4_get_groups_count (ac->ac_sb); + +/* non-extent files are limited to low blocks/groups */ +if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) + ngroups =EXT4_SB (ac->ac_sb)->s_blockfile_groups; + +/* Pairs with smp_wmb() in ext4_update_super() */ +smp_rmb (); + +return ngroups; +} +static int ext4_mb_scan_groups_xa_range (struct ext4_allocation_context *ac,struct xarray *xa,ext4_group_t start,ext4_group_t end)
@@ -899,7 +914,7 @@ static int ext4_mb_scan_groups_xa_range(struct ext4_allocation_context *ac,struct super_block *sb = ac->ac_sb;struct ext4_sb_info *sbi =EXT4_SB (sb);enum criteria cr = ac->ac_criteria; -ext4_group_t ngroups =ext4_get_groups_count (sb); +ext4_group_t ngroups =ext4_get_allocation_groups_count (ac);unsigned long group = start;struct ext4_group_info *grp;
@@ -951,7 +966,7 @@ static int ext4_mb_scan_groups_p2_aligned(struct ext4_allocation_context *ac,ext4_group_t start, end; start = group; - end =ext4_get_groups_count (ac->ac_sb); + end =ext4_get_allocation_groups_count (ac); wrap_around:for (i = ac->ac_2order; i <MB_NUM_ORDERS (ac->ac_sb); i++) { ret = ext4_mb_scan_groups_largest_free_order_range(ac, i,
@@ -1001,7 +1016,7 @@ static int ext4_mb_scan_groups_goal_fast(struct ext4_allocation_context *ac,ext4_group_t start, end; start = group; - end =ext4_get_groups_count (ac->ac_sb); + end =ext4_get_allocation_groups_count (ac); wrap_around: i =mb_avg_fragment_size_order (ac->ac_sb, ac->ac_g_ex.fe_len);for (; i <MB_NUM_ORDERS (ac->ac_sb); i++) {
@@ -1083,7 +1098,7 @@ static int ext4_mb_scan_groups_best_avail(struct ext4_allocation_context *ac, min_order =fls (ac->ac_o_ex.fe_len); start = group; - end =ext4_get_groups_count (ac->ac_sb); + end =ext4_get_allocation_groups_count (ac); wrap_around:for (i = order; i >= min_order; i--) {int frag_order;
@@ -1182,11 +1197,7 @@ static int ext4_mb_scan_groups(struct ext4_allocation_context *ac)int ret =0 ;ext4_group_t start;struct ext4_sb_info *sbi =EXT4_SB (ac->ac_sb); -ext4_group_t ngroups =ext4_get_groups_count (ac->ac_sb); - -/* non-extent files are limited to low blocks/groups */ -if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) - ngroups = sbi->s_blockfile_groups; +ext4_group_t ngroups =ext4_get_allocation_groups_count (ac);/* searching for the right group start from the goal value specified */ start = ac->ac_g_ex.fe_group;
Signature · 1 line
2.51.0
Re: [PATCH 1/2] ext4: always allocate blocks only from groups inode can use
Quoted 9 lines · Jan Kara
For filesystems with more than 2^32 blocks inodes using indirect block based format cannot use blocks beyond the 32-bit limit.
ext4_mb_scan_groups_linear()takes care to not select these unsupported groups for such inodes however other functions selecting groups for allocation don't. So far this is harmless because the other selection functions are used only withmb_optimize_scanand this is currently disabled for inodes with indirect blocks however in the following patch we want to enablemb_optimize_scanregardless of inode format.
Quoted 3 lines
Reviewed-by Baokun Li <[email protected]>Reviewed-by Zhang Yi <[email protected]>Signed-off-by Jan Kara <[email protected]>
Thanks for addressing my nit :)
Quoted 16 lines
--- fs/ext4/mballoc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)fs/ext4/mballoc.c +4
-0@@ -892,6 +892,21 @@ mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) } } +static ext4_group_t ext4_get_allocation_groups_count ( +struct ext4_allocation_context *ac) +{ +ext4_group_t ngroups =ext4_get_groups_count (ac->ac_sb);
fs/ext4/mballoc.c mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) · line 908
Quoted 10 lines
fs/ext4/mballoc.c +10
-0+ +/* non-extent files are limited to low blocks/groups */ +if (!(ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS ))) + ngroups =EXT4_SB (ac->ac_sb)->s_blockfile_groups; + +/* Pairs with smp_wmb() in ext4_update_super() */ +smp_rmb (); + +return ngroups; +}
For what it's worth now we get 2 smp_rmb()'s (get_groups_count() has one), but I suppose this can be fixed up later. Probably doesn't make sense to withold these patches further.
Signature · 1 line
Pedro
Re: [PATCH 1/2] ext4: always allocate blocks only from groups inode can use
In reply to Jan KaraQuoted 10 lines · Jan Kara
For filesystems with more than 2^32 blocks inodes using indirect block based format cannot use blocks beyond the 32-bit limit.
ext4_mb_scan_groups_linear()takes care to not select these unsupported groups for such inodes however other functions selecting groups for allocation don't. So far this is harmless because the other selection functions are used only withmb_optimize_scanand this is currently disabled for inodes with indirect blocks however in the following patch we want to enablemb_optimize_scanregardless of inode format.[...]
Applied, thanks!
[1/2] ext4: always allocate blocks only from groups inode can use
commit: 4865c768b563deff1b6a6384e74a62f143427b42
[2/2] ext4: use optimized mballoc scanning regardless of inode format
commit: 3574c322b1d0eb32dbd76b469cb08f9a67641599Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>
Jan Kara
reviewerPATCH v3 2/2 ext4: use optimized mballoc scanning regardless of inode format
In reply to Jan KaraCurrently we don't used mballoc optimized scanning (using max free extent order and avg free extent order group lists) for inodes with indirect block based format. This is confusing for users and I don't see a good reason for that. Even with indirect block based inode format we can spend big amount of time searching for free blocks for large filesystems with fragmented free space. To add to the confusion before commit 077d0c2c78df ("ext4: make mb_optimize_scan performance mount option work with extents") optimized scanning was applied *only* to indirect block based inodes so that commit appears as a performance regression to some users. Just use optimized scanning whenever it is enabled by mount options.
--- fs/ext4/mballoc.c | 2 -- 1 file changed, 2 deletions(-)
fs/ext4/mballoc.c +0 -2
@@ -1148,8 +1148,6 @@ static inline int should_optimize_scan(struct ext4_allocation_context *ac)return 0 ;if (ac->ac_criteria >=CR_GOAL_LEN_SLOW )return 0 ; -if (!ext4_test_inode_flag (ac->ac_inode,EXT4_INODE_EXTENTS )) -return 0 ;return 1 ; }
Signature · 1 line
2.51.0