Skip to contentSkip to conversation

Misc refactorings in XFS

PATCH Applied [email protected] 3 participants 5 messages Feb 11 – Feb 16 XFS filesystem

lore
Share & tools
lore
#0 lore raw

v2 cover Misc refactorings in XFS

From: "Nirjhar Roy (IBM)" <[email protected]>

This patchset contains 2 refactorings. Details are in the patches. Please note that Darrick's RB in patch 1 was given in [1]. There is a thread in lore where this series was partially sent[2] - please ignore that.

[v1] -> v2
1. Added RB from Christoph.
2. Fixed some styling/formatting issues in patch 1 and commit message of patch 2.

[1] https://lore.kernel.org/all/20250729202428.GE2672049@frogsfrogsfrogs/
[2] https://lore.kernel.org/all/[email protected]/
[v1] https://lore.kernel.org/all/[email protected]/

Nirjhar Roy (IBM) (2):
xfs: Refactoring the nagcount and delta calculation
xfs: Replace &rtg->rtg_group with rtg_group()

 fs/xfs/libxfs/xfs_ag.c  | 28 ++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_ag.h  |  3 +++
 fs/xfs/xfs_fsops.c      | 17 ++---------------
 fs/xfs/xfs_zone_alloc.c |  6 +++---
 fs/xfs/xfs_zone_gc.c    | 10 +++++-----
 5 files changed, 41 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.5
#1 lore raw

PATCH v2 1/2 xfs: Refactoring the nagcount and delta calculation

From: "Nirjhar Roy (IBM)" <[email protected]>

Introduce xfs_growfs_compute_delta() to calculate the nagcount and delta blocks and refactor the code from xfs_growfs_data_private(). No functional changes.

---
 fs/xfs/libxfs/xfs_ag.c | 28 ++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_ag.h |  3 +++
 fs/xfs/xfs_fsops.c     | 17 ++---------------
 3 files changed, 33 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_ag.c +28 -0
index e6ba914f6d06..f2b35d59d51e 100644
@@ -872,6 +872,34 @@ xfs_ag_shrink_space(
 	return err2;
 }
 
+void
+xfs_growfs_compute_deltas(
+	struct xfs_mount	*mp,
+	xfs_rfsblock_t		nb,
+	int64_t			*deltap,
+	xfs_agnumber_t		*nagcountp)
+{
+	xfs_rfsblock_t	nb_div, nb_mod;
+	int64_t		delta;
+	xfs_agnumber_t	nagcount;
+
+	nb_div = nb;
+	nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
+	if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
+		nb_div++;
+	else if (nb_mod)
+		nb = nb_div * mp->m_sb.sb_agblocks;
+
+	if (nb_div > XFS_MAX_AGNUMBER + 1) {
+		nb_div = XFS_MAX_AGNUMBER + 1;
+		nb = nb_div * mp->m_sb.sb_agblocks;
+	}
+	nagcount = nb_div;
+	delta = nb - mp->m_sb.sb_dblocks;
+	*deltap = delta;
+	*nagcountp = nagcount;
+}
+
 /*
  * Extent the AG indicated by the @id by the length passed in
  */
fs/xfs/libxfs/xfs_ag.h +3 -0
index 1f24cfa27321..3cd4790768ff 100644
@@ -331,6 +331,9 @@ struct aghdr_init_data {
 int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
 int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
 			xfs_extlen_t delta);
+void
+xfs_growfs_compute_deltas(struct xfs_mount *mp, xfs_rfsblock_t nb,
+			int64_t *deltap, xfs_agnumber_t *nagcountp);
 int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
 			xfs_extlen_t len);
 int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
fs/xfs/xfs_fsops.c +2 -15
index 0ada73569394..8353e2f186f6 100644
@@ -92,18 +92,17 @@ xfs_growfs_data_private(
 	struct xfs_growfs_data	*in)		/* growfs data input struct */
 {
 	xfs_agnumber_t		oagcount = mp->m_sb.sb_agcount;
+	xfs_rfsblock_t		nb = in->newblocks;
 	struct xfs_buf		*bp;
 	int			error;
 	xfs_agnumber_t		nagcount;
 	xfs_agnumber_t		nagimax = 0;
-	xfs_rfsblock_t		nb, nb_div, nb_mod;
 	int64_t			delta;
 	bool			lastag_extended = false;
 	struct xfs_trans	*tp;
 	struct aghdr_init_data	id = {};
 	struct xfs_perag	*last_pag;
 
-	nb = in->newblocks;
 	error = xfs_sb_validate_fsb_count(&mp->m_sb, nb);
 	if (error)
 		return error;
@@ -122,20 +121,8 @@ xfs_growfs_data_private(
 			mp->m_sb.sb_rextsize);
 	if (error)
 		return error;
+	xfs_growfs_compute_deltas(mp, nb, &delta, &nagcount);
 
-	nb_div = nb;
-	nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks);
-	if (nb_mod && nb_mod >= XFS_MIN_AG_BLOCKS)
-		nb_div++;
-	else if (nb_mod)
-		nb = nb_div * mp->m_sb.sb_agblocks;
-
-	if (nb_div > XFS_MAX_AGNUMBER + 1) {
-		nb_div = XFS_MAX_AGNUMBER + 1;
-		nb = nb_div * mp->m_sb.sb_agblocks;
-	}
-	nagcount = nb_div;
-	delta = nb - mp->m_sb.sb_dblocks;
 	/*
 	 * Reject filesystems with a single AG because they are not
 	 * supported, and reject a shrink operation that would cause a
Signature · 1 line
2.43.5
#2 lore raw

PATCH v2 2/2 xfs: Replace &rtg->rtg_group with rtg_group()

In reply to [email protected]

From: "Nirjhar Roy (IBM)" <[email protected]>

Use the already existing rtg_group() wrapper instead of directly accessing the struct xfs_group member in struct xfs_rtgroup.

---
 fs/xfs/xfs_zone_alloc.c |  6 +++---
 fs/xfs/xfs_zone_gc.c    | 10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)
fs/xfs/xfs_zone_alloc.c +3 -3
index bbcf21704ea0..4c514c423448 100644
@@ -78,7 +78,7 @@ xfs_zone_account_reclaimable(
 	struct xfs_rtgroup	*rtg,
 	uint32_t		freed)
 {
-	struct xfs_group	*xg = &rtg->rtg_group;
+	struct xfs_group	*xg = rtg_group(rtg);
 	struct xfs_mount	*mp = rtg_mount(rtg);
 	struct xfs_zone_info	*zi = mp->m_zone_info;
 	uint32_t		used = rtg_rmap(rtg)->i_used_blocks;
@@ -772,7 +772,7 @@ xfs_zone_alloc_blocks(
 
 	trace_xfs_zone_alloc_blocks(oz, allocated, count_fsb);
 
-	*sector = xfs_gbno_to_daddr(&rtg->rtg_group, 0);
+	*sector = xfs_gbno_to_daddr(rtg_group(rtg), 0);
 	*is_seq = bdev_zone_is_seq(mp->m_rtdev_targp->bt_bdev, *sector);
 	if (!*is_seq)
 		*sector += XFS_FSB_TO_BB(mp, allocated);
@@ -1033,7 +1033,7 @@ xfs_init_zone(
 	if (write_pointer == 0) {
 		/* zone is empty */
 		atomic_inc(&zi->zi_nr_free_zones);
-		xfs_group_set_mark(&rtg->rtg_group, XFS_RTG_FREE);
+		xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
 		iz->available += rtg_blocks(rtg);
 	} else if (write_pointer < rtg_blocks(rtg)) {
 		/* zone is open */
fs/xfs/xfs_zone_gc.c +5 -5
index 3c52cc1497d4..5f5cc3e0e068 100644
@@ -655,7 +655,7 @@ xfs_zone_gc_alloc_blocks(
 	if (!*count_fsb)
 		return NULL;
 
-	*daddr = xfs_gbno_to_daddr(&oz->oz_rtg->rtg_group, 0);
+	*daddr = xfs_gbno_to_daddr(rtg_group(oz->oz_rtg), 0);
 	*is_seq = bdev_zone_is_seq(mp->m_rtdev_targp->bt_bdev, *daddr);
 	if (!*is_seq)
 		*daddr += XFS_FSB_TO_BB(mp, oz->oz_allocated);
@@ -705,7 +705,7 @@ xfs_zone_gc_start_chunk(
 	chunk->data = data;
 	chunk->oz = oz;
 	chunk->victim_rtg = iter->victim_rtg;
-	atomic_inc(&chunk->victim_rtg->rtg_group.xg_active_ref);
+	atomic_inc(&rtg_group(chunk->victim_rtg)->xg_active_ref);
 	atomic_inc(&chunk->victim_rtg->rtg_gccount);
 
 	bio->bi_iter.bi_sector = xfs_rtb_to_daddr(mp, chunk->old_startblock);
@@ -792,7 +792,7 @@ xfs_zone_gc_split_write(
 	atomic_inc(&chunk->oz->oz_ref);
 
 	split_chunk->victim_rtg = chunk->victim_rtg;
-	atomic_inc(&chunk->victim_rtg->rtg_group.xg_active_ref);
+	atomic_inc(&rtg_group(chunk->victim_rtg)->xg_active_ref);
 	atomic_inc(&chunk->victim_rtg->rtg_gccount);
 
 	chunk->offset += split_len;
@@ -895,7 +895,7 @@ xfs_zone_gc_finish_reset(
 		goto out;
 	}
 
-	xfs_group_set_mark(&rtg->rtg_group, XFS_RTG_FREE);
+	xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
 	atomic_inc(&zi->zi_nr_free_zones);
 
 	xfs_zoned_add_available(mp, rtg_blocks(rtg));
@@ -914,7 +914,7 @@ xfs_zone_gc_prepare_reset(
 	trace_xfs_zone_reset(rtg);
 
 	ASSERT(rtg_rmap(rtg)->i_used_blocks == 0);
-	bio->bi_iter.bi_sector = xfs_gbno_to_daddr(&rtg->rtg_group, 0);
+	bio->bi_iter.bi_sector = xfs_gbno_to_daddr(rtg_group(rtg), 0);
 	if (!bdev_zone_is_seq(bio->bi_bdev, bio->bi_iter.bi_sector)) {
 		if (!bdev_max_discard_sectors(bio->bi_bdev))
 			return false;
Signature · 1 line
2.43.5
maintainer Applied
#3 lore raw
In reply to [email protected]
Quoted 11 lines · On Wed, 11 Feb 2026 19:25:12 +0530, [email protected] wrote:

This patchset contains 2 refactorings. Details are in the patches. Please note that Darrick's RB in patch 1 was given in [1]. There is a thread in lore where this series was partially sent[2] - please ignore that.

[v1] -> v2
1. Added RB from Christoph.
2. Fixed some styling/formatting issues in patch 1 and commit message of patch 2.

[...]

Applied to for-next, thanks!

[1/2] xfs: Refactoring the nagcount and delta calculation

      commit: c656834e964d0ec4e6599baa448510330c62e01e
[2/2] xfs: Replace &rtg->rtg_group with rtg_group()
      commit: f0d0d93e22e52a56121a3d7875ea7b577a217d62

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>
#4 lore raw
Quoted 11 lines · Carlos Maiolino
Quoted 10 lines · On Wed, 11 Feb 2026 19:25:12 +0530, [email protected] wrote:

This patchset contains 2 refactorings. Details are in the patches. Please note that Darrick's RB in patch 1 was given in [1]. There is a thread in lore where this series was partially sent[2] - please ignore that.

[v1] -> v2
1. Added RB from Christoph.
2. Fixed some styling/formatting issues in patch 1 and commit message of patch 2.

Quoted 7 lines
Quoted 1 line

[...]

Applied to for-next, thanks!

[1/2] xfs: Refactoring the nagcount and delta calculation

       commit: c656834e964d0ec4e6599baa448510330c62e01e
[2/2] xfs: Replace &rtg->rtg_group with rtg_group()
       commit: f0d0d93e22e52a56121a3d7875ea7b577a217d62

Thank you.

--NR

Quoted 2 lines

Best regards,

Signature · 3 lines
Nirjhar Roy
Linux Kernel Developer
IBM, Bangalore