When the original request is longer than 1 << min_order, min_order is raised to fls(ac_o_ex.fe_len). For a power-of-two length that is one order too high: a 512-cluster request is never trimmed to 512 and falls through to CR_GOAL_LEN_SLOW even when 512-cluster free extents exist. Use order_base_2() so the trimmed goal is the smallest power of two that covers the original request. Reproducer: every group has only 512-block free extents. 2 MiB-aligned O_DIRECT writes to a file with a 64 MiB i_size; 9 of 12 allocations reach CR_BEST_AVAIL_LEN: write size before after 511 blocks 9 x CR_BEST_AVAIL_LEN 9 x CR_BEST_AVAIL_LEN 512 blocks 9 x CR_GOAL_LEN_SLOW 9 x CR_BEST_AVAIL_LEN Fixes: 7e170922f06b ("ext4: Add allocation criteria 1.5 (CR1_5)") Signed-off-by: Muhammad Umer --- fs/ext4/mballoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 37825743f..8743ff5be 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1093,7 +1093,7 @@ static int ext4_mb_scan_groups_best_avail(struct ext4_allocation_context *ac, } if (1 << min_order < ac->ac_o_ex.fe_len) - min_order = fls(ac->ac_o_ex.fe_len); + min_order = order_base_2(ac->ac_o_ex.fe_len); start = group; end = ext4_get_allocation_groups_count(ac); -- 2.53.0