Skip to contentSkip to conversation

Patch "xfs: don't skip free extents in later batches of a whole-AG FITRIM" has been added to the 6.18-stable tree

PATCH Sasha Levin 1 participant 1 message Nov 10 XFS filesystem

lore
Share & tools
lore

Sasha Levin

author Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

xfs: don't skip free extents in later batches of a whole-AG FITRIM

to the 6.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
xfs-don-t-skip-free-extents-in-later-batches-of-a-wh.patch
and it can be found in the queue-6.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

commit 3d6528182f89f799a7ef2acc95fc7c1bf20a7835

Author: Daejun Park <[email protected]>
Date:   Mon Oct 26 10:54:05 2026 +0900

xfs: don't skip free extents in later batches of a whole-AG FITRIM

[ Upstream commit 595e67d7261673d03c96950ffbb2e545c00376ed ]

A whole-device FITRIM walks every AG but the last by length, in batches. xfs_trim_gather_extents() saves the record to restart from in tcur->start. But tcur->start is also the start of the range to trim. Later batches therefore never discard the free extents below that block.

Save the restart record in a new restart_bno field.

Fixes b0ffe661fab4 ("xfs: fix performance problems when fstrimming a subset of a fragmented AG")
fs/xfs/xfs_discard.c +14 -4
index 6917de8321915..b866329c7a28d 100644
@@ -166,6 +166,8 @@ struct xfs_trim_cur {
 	xfs_agblock_t	end;
 	xfs_extlen_t	minlen;
 	bool		by_bno;
+	/* restart point (with count) for the by-length walk */
+	xfs_agblock_t	restart_bno;
 };
 
 static int
@@ -209,14 +211,15 @@ 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->start == 0) {
+	} 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 */
 		cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
-		error = xfs_alloc_lookup_le(cur, tcur->start, tcur->count, &i);
+		error = xfs_alloc_lookup_le(cur, tcur->restart_bno,
+					    tcur->count, &i);
 	}
 	if (error)
 		goto out_del_cursor;
@@ -246,9 +249,15 @@ xfs_trim_gather_extents(
 		if (--batch <= 0) {
 			/*
 			 * Update the cursor to point at this extent so we
-			 * restart the next batch from this extent.
+			 * restart the next batch from this extent. The
+			 * by-length walk does not visit extents in block
+			 * order, so it must keep the start of the range and
+			 * restart from restart_bno instead.
 			 */
-			tcur->start = fbno;
+			if (tcur->by_bno)
+				tcur->start = fbno;
+			else
+				tcur->restart_bno = fbno;
 			tcur->count = flen;
 			break;
 		}
@@ -351,6 +360,7 @@ xfs_trim_perag_extents(
 		.start		= start,
 		.end		= end,
 		.minlen		= minlen,
+		.restart_bno	= NULLAGBLOCK,
 	};
 	int			error = 0;