Skip to contentSkip to conversation

xfs: free xfs_busy_extents structure when no RT extents are queued

PATCH Applied Christoph Hellwig 3 participants 4 messages Nov 4, 2025 – Nov 6, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: free xfs_busy_extents structure when no RT extents are queued

kmemleak occasionally reports leaking xfs_busy_extents structure from xfs_scrub calls after running xfs/528 (but attributed to following tests), which seems to be caused by not freeing the xfs_busy_extents structure when tr.queued is 0 and xfs_trim_rtgroup_extents breaks out of the main loop. Free the structure in this case.

Fixes a3315d11305f ("xfs: use rtgroup busy extent list for FITRIM")
---
 fs/xfs/xfs_discard.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +3 -1
index ee49f20875af..6917de832191 100644
@@ -726,8 +726,10 @@ xfs_trim_rtgroup_extents(
 			break;
 		}
 
-		if (!tr.queued)
+		if (!tr.queued) {
+			kfree(tr.extents);
 			break;
+		}
 
 		/*
 		 * We hand the extent list to the discard function here so the
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Christoph Hellwig

kmemleak occasionally reports leaking xfs_busy_extents structure from xfs_scrub calls after running xfs/528 (but attributed to following tests), which seems to be caused by not freeing the xfs_busy_extents structure when tr.queued is 0 and xfs_trim_rtgroup_extents breaks out of the main loop. Free the structure in this case.

Fixes a3315d11305f ("xfs: use rtgroup busy extent list for FITRIM")

Yep, this fixes a memory leak. I wonder if you could combine the two into:

	if (error || !tr.queued) {
		kfree(tr.extents);
		break;
	}

But I don't care passionately either way.

--D

Quoted 24 lines
---
 fs/xfs/xfs_discard.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +3 -1
index ee49f20875af..6917de832191 100644
@@ -726,8 +726,10 @@ xfs_trim_rtgroup_extents(
 			break;
 		}
 
-		if (!tr.queued)
+		if (!tr.queued) {
+			kfree(tr.extents);
 			break;
+		}
 
 		/*
 		 * We hand the extent list to the discard function here so the
Signature · 1 line
2.47.3
#2 lore raw
Quoted 10 lines · Darrick J. Wong

Yep, this fixes a memory leak. I wonder if you could combine the two into:

	if (error || !tr.queued) {
		kfree(tr.extents);
		break;
	}

But I don't care passionately either way.

I'd rather keep the fix minimal for now, but yes, otherwise that would work as well.

maintainer Applied
#3 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

kmemleak occasionally reports leaking xfs_busy_extents structure from xfs_scrub calls after running xfs/528 (but attributed to following tests), which seems to be caused by not freeing the xfs_busy_extents structure when tr.queued is 0 and xfs_trim_rtgroup_extents breaks out of the main loop. Free the structure in this case.

[...]

Applied to for-next, thanks!

[1/1] xfs: free xfs_busy_extents structure when no RT extents are queued

      commit: d8a823c6f04ef03e3bd7249d2e796da903e7238d

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>