Misc refactorings in XFS
cover Misc refactorings in XFS
From: "Nirjhar Roy (IBM)" <[email protected]>
This patchset contains 2 refactorings. Details are in the patches. Please note that the RB for patch 1 was given in [1]. There is a thread in lore where this series was partially sent[2] - please ignore that.
[1] https://lore.kernel.org/all/20250729202428.GE2672049@frogsfrogsfrogs/
[2] 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
PATCH 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
@@ -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
@@ -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
@@ -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
PATCH 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
@@ -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
@@ -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
Re: [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation
In reply to [email protected]Quoted 58 lines · On Tue, Feb 10, 2026 at 05:56:34PM +0530, [email protected] wrote:
From: "Nirjhar Roy (IBM)" <[email protected]>
Introduce
xfs_growfs_compute_delta()to calculate the nagcount and delta blocks and refactor the code fromxfs_growfs_data_private(). No functional changes.Reviewed-by "Darrick J. Wong" <[email protected]>Signed-off-by Nirjhar Roy (IBM) <[email protected]>--- 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@@ -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 +0
-0
fs/xfs/libxfs/xfs_ag.h struct aghdr_init_data { · line 336
Quoted 6 lines
fs/xfs/libxfs/xfs_ag.h +3
-0@@ -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);
The formatting here doesn't really match the functions above and below..
Otherwise looks good:
Re: [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group()
In reply to [email protected]Quoted 5 lines · On Tue, Feb 10, 2026 at 05:56:35PM +0530, [email protected] wrote:
From: "Nirjhar Roy (IBM)" <[email protected]>
Use the already existing
rtg_group()wrapper instead of directly accessing the structxfs_groupmember in structxfs_rtgroup.
Doesn't really save much, but I guess we should be consistent:
Nit: your commit message could be condensed a bit by using up all 73 characters.
Re: [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation
In reply to Christoph HellwigQuoted 58 lines · Christoph Hellwig
Quoted 57 lines · On Tue, Feb 10, 2026 at 05:56:34PM +0530, [email protected] wrote:
From: "Nirjhar Roy (IBM)" <[email protected]>
Introduce
xfs_growfs_compute_delta()to calculate the nagcount and delta blocks and refactor the code fromxfs_growfs_data_private(). No functional changes.Reviewed-by "Darrick J. Wong" <[email protected]>Signed-off-by Nirjhar Roy (IBM) <[email protected]>--- 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@@ -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 +0
-0
Quoted 8 lines
fs/xfs/libxfs/xfs_ag.h struct aghdr_init_data { · line 336
Quoted 7 lines
fs/xfs/libxfs/xfs_ag.h +3
-0@@ -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);The formatting here doesn't really match the functions above and below..
Yes, right. I will fix this. Thank you for pointing this out.
--NR
Quoted 4 lines
Otherwise looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore
Re: [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group()
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Quoted 5 lines · On Tue, Feb 10, 2026 at 05:56:35PM +0530, [email protected] wrote:
From: "Nirjhar Roy (IBM)" <[email protected]>
Use the already existing
rtg_group()wrapper instead of directly accessing the structxfs_groupmember in structxfs_rtgroup.
Quoted 6 lines
Doesn't really save much, but I guess we should be consistent:
Reviewed-by Christoph Hellwig <[email protected]>Nit: your commit message could be condensed a bit by using up all 73 characters.
I will fix this. Thank you.
--NR
Quoted 1 line
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore