[RFC v1 1/4] xfs: Re-introduce xg_active_wq field in struct xfs_group

Nirjhar Roy (IBM)
2026-02-19T06:05:39Z

From: "Nirjhar Roy (IBM)" <nirjhar.roy.lists@gmail.com>

pag_active_wq was removed in
commit 9943b4573290
("xfs: remove the unused pag_active_wq field in struct xfs_perag")
because it was not waited upon. Re-introducing this in struct xfs_group.
This patch also replaces atomic_dec() in xfs_group_rele() with

if (atomic_dec_and_test(&xg->xg_active_ref))
wake_up(&xg->xg_active_wq);

The reason for this change is that the online shrink code will wait
for all the active references to come down to zero before actually
starting the shrink process (only if the number of rtextents that
we are trying to remove is worth 1 or more rtgroups).

Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
fs/xfs/libxfs/xfs_group.c | 4 +++-
fs/xfs/libxfs/xfs_group.h | 2 ++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_group.c b/fs/xfs/libxfs/xfs_group.c
index 792f76d2e2a0..51ef9dd9d1ed 100644
--- a/fs/xfs/libxfs/xfs_group.c
+++ b/fs/xfs/libxfs/xfs_group.c
@@ -147,7 +147,8 @@ xfs_group_rele(
struct xfs_group *xg)
{
trace_xfs_group_rele(xg, _RET_IP_);
- atomic_dec(&xg->xg_active_ref);
+ if (atomic_dec_and_test(&xg->xg_active_ref))
+ wake_up(&xg->xg_active_wq);
}

void
@@ -202,6 +203,7 @@ xfs_group_insert(
xfs_defer_drain_init(&xg->xg_intents_drain);

/* Active ref owned by mount indicates group is online. */
+ init_waitqueue_head(&xg->xg_active_wq);
atomic_set(&xg->xg_active_ref, 1);

error = xa_insert(&mp->m_groups[type].xa, index, xg, GFP_KERNEL);
diff --git a/fs/xfs/libxfs/xfs_group.h b/fs/xfs/libxfs/xfs_group.h
index 4ae638f1c2c5..692cb9266457 100644
--- a/fs/xfs/libxfs/xfs_group.h
+++ b/fs/xfs/libxfs/xfs_group.h
@@ -11,6 +11,8 @@ struct xfs_group {
enum xfs_group_type xg_type;
atomic_t xg_ref; /* passive reference count */
atomic_t xg_active_ref; /* active reference count */
+ /* woken up when xg_active_ref falls to zero */
+ wait_queue_head_t xg_active_wq;

/* Precalculated geometry info */
uint32_t xg_block_count; /* max usable gbno */
--
2.43.5