Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Muhammad Umer <mumer.mobi@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
	libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, yi.zhang@huawei.com,
	Muhammad Umer <mumer.mobi@gmail.com>
Subject: [PATCH 2/2] ext4: fix off-by-one in CR_BEST_AVAIL_LEN min_order
Date: Sun, 22 Nov 2026 13:56:30 -0500	[thread overview]
Message-ID: <20261122185630.2112-3-mumer.mobi@gmail.com> (raw)
In-Reply-To: <20261122185630.2112-1-mumer.mobi@gmail.com>

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 <mumer.mobi@gmail.com>
---
 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


  parent reply	other threads:[~2026-11-22 18:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 18:56 [PATCH 0/2] ext4: fix goal trimming in CR_BEST_AVAIL_LEN Muhammad Umer
2026-11-22 18:56 ` [PATCH 1/2] ext4: scan all groups before trimming the goal " Muhammad Umer
2026-11-22 18:56 ` Muhammad Umer [this message]
2026-11-22 19:01 ` [PATCH 0/2] ext4: fix goal trimming " sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122185630.2112-3-mumer.mobi@gmail.com \
    --to=mumer.mobi@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox