Skip to contentSkip to conversation

FAILED: patch "[PATCH] xfs: don't skip free extents of the longest length in a whole-AG FITRIM" failed to apply to 6.6-stable tree

PATCH New Sasha Levin 1 participant 2 messages Nov 10 – Nov 12

Subsystems (2)
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Thanks,
Sasha

------------------ original commit in Linus's tree ------------------

From 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99 Mon Sep 17 00:00:00 2001
From: Daejun Park <[email protected]>
Date: Mon, 26 Oct 2026 10:54:06 +0900
Subject: [PATCH] xfs: don't skip free extents of the longest length in a
whole-AG FITRIM

Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the by-length walk of an AG in FITRIM starts with xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup lands on the longest free extent with the lowest block number. The other free extents of that length sort after it and are never discarded.

Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.

---
 fs/xfs/xfs_discard.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xfs/xfs_discard.c +5 -5
index 8120f136af931..cdf660344c281 100644
@@ -200,12 +200,12 @@ xfs_trim_gather_extents(
 		error = xfs_alloc_lookup_le(cur, tcur->start, 0, &i);
 		if (!error && !i)
 			error = xfs_alloc_lookup_ge(cur, tcur->start, 0, &i);
-	} else if (tcur->restart_bno == NULLAGBLOCK) {
-		/* first time through a by-len starts with max length */
-		cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
-		error = xfs_alloc_lookup_ge(cur, 0, tcur->count, &i);
 	} else {
-		/* nth time through a by-len starts where we left off */
+		/*
+		 * A by-len walk starts at the last record of the longest
+		 * length (restart_bno is NULLAGBLOCK until the first batch
+		 * ends) and then where the previous batch stopped.
+		 */
 		cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
 		error = xfs_alloc_lookup_le(cur, tcur->restart_bno,
 					    tcur->count, &i);
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/1 xfs: don't skip free extents of the longest length in a whole-AG FITRIM

From: Daejun Park <[email protected]>

[ Upstream commit 5745f4f10a1a16aa5bb020acc38afa33f2d5ff99 ]

Since commit a66d636385d6 ("xfs: fix fstrim offset calculations"), the by-length walk of an AG in FITRIM starts with xfs_alloc_lookup_ge(cur, 0, pagf_longest) and walks down. The lookup lands on the longest free extent with the lowest block number. The other free extents of that length sort after it and are never discarded.

Start every by-length batch with xfs_alloc_lookup_le() at restart_bno.

Fixes a66d636385d6 ("xfs: fix fstrim offset calculations")
[ sashal: adapted trim cursor fields restart_bno and count to ar_startblock and ar_blockcount. ]
---
 fs/xfs/xfs_discard.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/xfs/xfs_discard.c +4 -5
index d5787991bb5b4..80d4a39e69008 100644
@@ -175,12 +175,11 @@ xfs_trim_gather_extents(
 	cur = xfs_allocbt_init_cursor(mp, NULL, agbp, pag, XFS_BTNUM_CNT);
 
 	/*
-	 * Look up the extent length requested in the AGF and start with it.
+	 * A by-len walk starts at the last record of the longest
+	 * length (ar_startblock is NULLAGBLOCK until the first batch
+	 * ends) and then where the previous batch stopped.
 	 */
-	if (tcur->ar_startblock == NULLAGBLOCK)
-		error = xfs_alloc_lookup_ge(cur, 0, tcur->ar_blockcount, &i);
-	else
-		error = xfs_alloc_lookup_le(cur, tcur->ar_startblock,
+	error = xfs_alloc_lookup_le(cur, tcur->ar_startblock,
 				tcur->ar_blockcount, &i);
 	if (error)
 		goto out_del_cursor;
Signature · 1 line
2.53.0