Re: [PATCH v3 01/20] ext4: set goal start correctly in ext4_mb_normalize_request

From: IBM
Date: Sun Mar 12 2023 - 22:07:45 EST


Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx> writes:

> We need to set ac_g_ex to notify the goal start used in
> ext4_mb_find_by_goal. Set ac_g_ex instead of ac_f_ex in
> ext4_mb_normalize_request.
> Besides we should assure goal start is in range [first_data_block,
> blocks_count) as ext4_mb_initialize_context does.

Thanks for looking into the failed test case.
Patch looks good to me. After going through the change, I also feel we
should be updating ac_g_ex instead of ac_f_ex.

Good spotting! Please feel free to add -

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>

>
> Signed-off-by: Kemeng Shi <shikemeng@xxxxxxxxxxxxxxx>
> ---
> fs/ext4/mballoc.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 5b2ae37a8b80..36cd545f5ab4 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -3993,6 +3993,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
> struct ext4_allocation_request *ar)
> {
> struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
> + struct ext4_super_block *es = sbi->s_es;
> int bsbits, max;
> ext4_lblk_t end;
> loff_t size, start_off;
> @@ -4188,18 +4189,20 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
> ac->ac_g_ex.fe_len = EXT4_NUM_B2C(sbi, size);
>
> /* define goal start in order to merge */
> - if (ar->pright && (ar->lright == (start + size))) {
> + if (ar->pright && (ar->lright == (start + size)) &&
> + ar->pright - size >= le32_to_cpu(es->s_first_data_block)) {
> /* merge to the right */
> ext4_get_group_no_and_offset(ac->ac_sb, ar->pright - size,
> - &ac->ac_f_ex.fe_group,
> - &ac->ac_f_ex.fe_start);
> + &ac->ac_g_ex.fe_group,
> + &ac->ac_g_ex.fe_start);
> ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
> }
> - if (ar->pleft && (ar->lleft + 1 == start)) {
> + if (ar->pleft && (ar->lleft + 1 == start) &&
> + ar->pleft + 1 < ext4_blocks_count(es)) {
> /* merge to the left */
> ext4_get_group_no_and_offset(ac->ac_sb, ar->pleft + 1,
> - &ac->ac_f_ex.fe_group,
> - &ac->ac_f_ex.fe_start);
> + &ac->ac_g_ex.fe_group,
> + &ac->ac_g_ex.fe_start);
> ac->ac_flags |= EXT4_MB_HINT_TRY_GOAL;
> }
>
> --
> 2.30.0