public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Misc refactorings in XFS
@ 2026-02-11 13:55 nirjhar
  2026-02-11 13:55 ` [PATCH v2 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: nirjhar @ 2026-02-11 13:55 UTC (permalink / raw)
  To: djwong, hch, cem; +Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists

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

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/cover.1770128479.git.nirjhar.roy.lists@gmail.com/
[v1] https://lore.kernel.org/all/cover.1770725429.git.nirjhar.roy.lists@gmail.com/

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(-)

-- 
2.43.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] xfs: Refactoring the nagcount and delta calculation
  2026-02-11 13:55 [PATCH v2 0/2] Misc refactorings in XFS nirjhar
@ 2026-02-11 13:55 ` nirjhar
  2026-02-11 13:55 ` [PATCH v2 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar
  2026-02-16 16:42 ` [PATCH v2 0/2] Misc refactorings in XFS Carlos Maiolino
  2 siblings, 0 replies; 5+ messages in thread
From: nirjhar @ 2026-02-11 13:55 UTC (permalink / raw)
  To: djwong, hch, cem; +Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists

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

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

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
 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(-)

diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index e6ba914f6d06..f2b35d59d51e 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -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
  */
diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h
index 1f24cfa27321..3cd4790768ff 100644
--- a/fs/xfs/libxfs/xfs_ag.h
+++ b/fs/xfs/libxfs/xfs_ag.h
@@ -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);
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 0ada73569394..8353e2f186f6 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -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
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] xfs: Replace &rtg->rtg_group with rtg_group()
  2026-02-11 13:55 [PATCH v2 0/2] Misc refactorings in XFS nirjhar
  2026-02-11 13:55 ` [PATCH v2 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar
@ 2026-02-11 13:55 ` nirjhar
  2026-02-16 16:42 ` [PATCH v2 0/2] Misc refactorings in XFS Carlos Maiolino
  2 siblings, 0 replies; 5+ messages in thread
From: nirjhar @ 2026-02-11 13:55 UTC (permalink / raw)
  To: djwong, hch, cem; +Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists

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

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

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
---
 fs/xfs/xfs_zone_alloc.c |  6 +++---
 fs/xfs/xfs_zone_gc.c    | 10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/xfs_zone_alloc.c b/fs/xfs/xfs_zone_alloc.c
index bbcf21704ea0..4c514c423448 100644
--- a/fs/xfs/xfs_zone_alloc.c
+++ b/fs/xfs/xfs_zone_alloc.c
@@ -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 */
diff --git a/fs/xfs/xfs_zone_gc.c b/fs/xfs/xfs_zone_gc.c
index 3c52cc1497d4..5f5cc3e0e068 100644
--- a/fs/xfs/xfs_zone_gc.c
+++ b/fs/xfs/xfs_zone_gc.c
@@ -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;
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Misc refactorings in XFS
  2026-02-11 13:55 [PATCH v2 0/2] Misc refactorings in XFS nirjhar
  2026-02-11 13:55 ` [PATCH v2 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar
  2026-02-11 13:55 ` [PATCH v2 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar
@ 2026-02-16 16:42 ` Carlos Maiolino
  2026-02-16 16:44   ` Nirjhar Roy (IBM)
  2 siblings, 1 reply; 5+ messages in thread
From: Carlos Maiolino @ 2026-02-16 16:42 UTC (permalink / raw)
  To: djwong, hch, nirjhar; +Cc: linux-xfs, ritesh.list, ojaswin, nirjhar.roy.lists

On Wed, 11 Feb 2026 19:25:12 +0530, nirjhar@linux.ibm.com 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,
-- 
Carlos Maiolino <cem@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Misc refactorings in XFS
  2026-02-16 16:42 ` [PATCH v2 0/2] Misc refactorings in XFS Carlos Maiolino
@ 2026-02-16 16:44   ` Nirjhar Roy (IBM)
  0 siblings, 0 replies; 5+ messages in thread
From: Nirjhar Roy (IBM) @ 2026-02-16 16:44 UTC (permalink / raw)
  To: Carlos Maiolino, djwong, hch, nirjhar; +Cc: linux-xfs, ritesh.list, ojaswin


On 2/16/26 22:12, Carlos Maiolino wrote:
> On Wed, 11 Feb 2026 19:25:12 +0530, nirjhar@linux.ibm.com 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

Thank you.

--NR

>
> Best regards,

-- 
Nirjhar Roy
Linux Kernel Developer
IBM, Bangalore


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-16 16:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-11 13:55 [PATCH v2 0/2] Misc refactorings in XFS nirjhar
2026-02-11 13:55 ` [PATCH v2 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar
2026-02-11 13:55 ` [PATCH v2 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar
2026-02-16 16:42 ` [PATCH v2 0/2] Misc refactorings in XFS Carlos Maiolino
2026-02-16 16:44   ` Nirjhar Roy (IBM)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox