All of lore.kernel.org
 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 1/2] ext4: scan all groups before trimming the goal in CR_BEST_AVAIL_LEN
Date: Sun, 22 Nov 2026 13:56:29 -0500	[thread overview]
Message-ID: <20261122185630.2112-2-mumer.mobi@gmail.com> (raw)
In-Reply-To: <20261122185630.2112-1-mumer.mobi@gmail.com>

Since commit a3ce570a5d6a ("ext4: implement linear-like traversal across
order xarrays"), ext4_mb_scan_groups_best_avail() walks every order from
the goal order down to min_order over groups [start, ngroups) before it
looks at [0, start). A group below start is only considered after the
goal has been trimmed to min_order, so a 1024-cluster free extent in
group 2 loses to a 256-cluster one in group 9.

The ordering is harmless for CR_POWER2_ALIGNED and CR_GOAL_LEN_FAST,
where every order scanned satisfies the full goal. In CR_BEST_AVAIL_LEN
a lower order means a smaller allocation, so search both ranges at each
order before trimming further.

start is rarely 0: stream allocations start at s_mb_last_groups[], and
the linear prescan moves it forward by s_mb_max_linear_groups.

Reproducer: 16 groups, groups 0-7 with only 1024-block free extents,
groups 8-15 with only 256-block free extents. 32 MiB written with 64 KiB
O_DIRECT writes to a file with a 64 MiB i_size (8 MiB normalized goal).
Allocations made:

  start group, max_linear_groups   before               after
  0, 0                             8 x 1024             8 x 1024
  8, 0                             7 x 1024, 4 x 256    8 x 1024
  0, 4                             6 x 1024, 2 x 512,   8 x 1024
                                   4 x 256

Fixes: a3ce570a5d6a ("ext4: implement linear-like traversal across order xarrays")
Signed-off-by: Muhammad Umer <mumer.mobi@gmail.com>
---
 fs/ext4/mballoc.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index a15285224..37825743f 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1097,7 +1097,6 @@ static int ext4_mb_scan_groups_best_avail(struct ext4_allocation_context *ac,
 
 	start = group;
 	end = ext4_get_allocation_groups_count(ac);
-wrap_around:
 	for (i = order; i >= min_order; i--) {
 		int frag_order;
 		/*
@@ -1120,15 +1119,20 @@ static int ext4_mb_scan_groups_best_avail(struct ext4_allocation_context *ac,
 		frag_order = mb_avg_fragment_size_order(ac->ac_sb,
 							ac->ac_g_ex.fe_len);
 
+		/*
+		 * A lower order means a smaller allocation, so search all
+		 * groups at this order before trimming the goal further.
+		 */
 		ret = ext4_mb_scan_groups_avg_frag_order_range(ac, frag_order,
 							       start, end);
 		if (ret || ac->ac_status != AC_STATUS_CONTINUE)
 			return ret;
-	}
-	if (start) {
-		end = start;
-		start = 0;
-		goto wrap_around;
+		if (start) {
+			ret = ext4_mb_scan_groups_avg_frag_order_range(ac,
+							frag_order, 0, start);
+			if (ret || ac->ac_status != AC_STATUS_CONTINUE)
+				return ret;
+		}
 	}
 
 	/* Reset goal length to original goal length before falling into CR_GOAL_LEN_SLOW */
-- 
2.53.0


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

Thread overview: 6+ 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 ` Muhammad Umer [this message]
2026-11-24 12:26   ` [PATCH 1/2] ext4: scan all groups before trimming the goal " Jan Kara
2026-11-22 18:56 ` [PATCH 2/2] ext4: fix off-by-one in CR_BEST_AVAIL_LEN min_order Muhammad Umer
2026-11-24 12:28   ` Jan Kara
2026-11-22 19:01 ` [PATCH 0/2] ext4: fix goal trimming in CR_BEST_AVAIL_LEN 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-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.