Skip to contentSkip to conversation

xfs: improve the xg_active_ref check in xfs_group_free

PATCH Applied Christoph Hellwig 3 participants 4 messages Jul 16, 2025 – Jul 17, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: improve the xg_active_ref check in xfs_group_free

Split up the XFS_IS_CORRUPT statement so that it immediately shows if the reference counter overflowed or underflowed.

I ran into this quite a bit when developing the zoned allocator, and had to reapply the patch for some work recently. We might as well just apply it upstream given that freeing group is far removed from performance critical code.

---
 fs/xfs/libxfs/xfs_group.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_group.c +2 -1
index 20ad7c309489..792f76d2e2a0 100644
@@ -172,7 +172,8 @@ xfs_group_free(
 
 	/* drop the mount's active reference */
 	xfs_group_rele(xg);
-	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) != 0);
+	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) > 0);
+	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) < 0);
 	kfree_rcu_mightsleep(xg);
 }
 
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Christoph Hellwig

Split up the XFS_IS_CORRUPT statement so that it immediately shows if the reference counter overflowed or underflowed.

Should we be using refcount_t for xg_active_ref to detect over/underflows, then?

Quoted 6 lines

I ran into this quite a bit when developing the zoned allocator, and had to reapply the patch for some work recently. We might as well just apply it upstream given that freeing group is far removed from performance critical code.

Looks fine though,

--D

Quoted 22 lines
---
 fs/xfs/libxfs/xfs_group.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_group.c +2 -1
index 20ad7c309489..792f76d2e2a0 100644
@@ -172,7 +172,8 @@ xfs_group_free(
 
 	/* drop the mount's active reference */
 	xfs_group_rele(xg);
-	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) != 0);
+	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) > 0);
+	XFS_IS_CORRUPT(mp, atomic_read(&xg->xg_active_ref) < 0);
 	kfree_rcu_mightsleep(xg);
 }
 
Signature · 1 line
2.47.2
#2 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 2 lines · Christoph Hellwig

Split up the XFS_IS_CORRUPT statement so that it immediately shows if the reference counter overflowed or underflowed.

Should we be using refcount_t for xg_active_ref to detect over/underflows, then?

In theory yes. In practice refcount_t still has a lot of performance overhead, so using it in something used a lot in the fast path might not be a good idea.

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

Split up the XFS_IS_CORRUPT statement so that it immediately shows if the reference counter overflowed or underflowed.

I ran into this quite a bit when developing the zoned allocator, and had to reapply the patch for some work recently. We might as well just apply it upstream given that freeing group is far removed from performance critical code.

[...]

Applied to for-next, thanks!

[1/1] xfs: improve the xg_active_ref check in xfs_group_free

      commit: a10f18bc67785b947396ddd0529b3df7df3d5d6f

Best regards,

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