* [patch v1 0/2] Misc refactorings in XFS @ 2026-02-10 12:26 nirjhar 2026-02-10 12:26 ` [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar 2026-02-10 12:26 ` [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar 0 siblings, 2 replies; 7+ messages in thread From: nirjhar @ 2026-02-10 12:26 UTC (permalink / raw) To: linux-xfs; +Cc: ritesh.list, ojaswin, djwong, hch, cem, 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 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/cover.1770128479.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] 7+ messages in thread
* [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation 2026-02-10 12:26 [patch v1 0/2] Misc refactorings in XFS nirjhar @ 2026-02-10 12:26 ` nirjhar 2026-02-10 15:44 ` Christoph Hellwig 2026-02-10 12:26 ` [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar 1 sibling, 1 reply; 7+ messages in thread From: nirjhar @ 2026-02-10 12:26 UTC (permalink / raw) To: linux-xfs; +Cc: ritesh.list, ojaswin, djwong, hch, cem, 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> 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..f7b56d486468 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] 7+ messages in thread
* Re: [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation 2026-02-10 12:26 ` [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar @ 2026-02-10 15:44 ` Christoph Hellwig 2026-02-10 15:48 ` Nirjhar Roy 0 siblings, 1 reply; 7+ messages in thread From: Christoph Hellwig @ 2026-02-10 15:44 UTC (permalink / raw) To: nirjhar Cc: linux-xfs, ritesh.list, ojaswin, djwong, hch, cem, nirjhar.roy.lists On Tue, Feb 10, 2026 at 05:56:34PM +0530, nirjhar@linux.ibm.com wrote: > 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> > 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..f7b56d486468 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); The formatting here doesn't really match the functions above and below.. Otherwise looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation 2026-02-10 15:44 ` Christoph Hellwig @ 2026-02-10 15:48 ` Nirjhar Roy 0 siblings, 0 replies; 7+ messages in thread From: Nirjhar Roy @ 2026-02-10 15:48 UTC (permalink / raw) To: Christoph Hellwig Cc: linux-xfs, ritesh.list, ojaswin, djwong, cem, nirjhar.roy.lists On 2/10/26 21:14, Christoph Hellwig wrote: > On Tue, Feb 10, 2026 at 05:56:34PM +0530, nirjhar@linux.ibm.com wrote: >> 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> >> 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..f7b56d486468 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); > 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 > > Otherwise looks good: > > Reviewed-by: Christoph Hellwig <hch@lst.de> -- Nirjhar Roy Linux Kernel Developer IBM, Bangalore ^ permalink raw reply [flat|nested] 7+ messages in thread
* [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() 2026-02-10 12:26 [patch v1 0/2] Misc refactorings in XFS nirjhar 2026-02-10 12:26 ` [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar @ 2026-02-10 12:26 ` nirjhar 2026-02-10 15:46 ` Christoph Hellwig 1 sibling, 1 reply; 7+ messages in thread From: nirjhar @ 2026-02-10 12:26 UTC (permalink / raw) To: linux-xfs; +Cc: ritesh.list, ojaswin, djwong, hch, cem, 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. 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] 7+ messages in thread
* Re: [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() 2026-02-10 12:26 ` [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar @ 2026-02-10 15:46 ` Christoph Hellwig 2026-02-10 15:50 ` Nirjhar Roy 0 siblings, 1 reply; 7+ messages in thread From: Christoph Hellwig @ 2026-02-10 15:46 UTC (permalink / raw) To: nirjhar Cc: linux-xfs, ritesh.list, ojaswin, djwong, hch, cem, nirjhar.roy.lists On Tue, Feb 10, 2026 at 05:56:35PM +0530, nirjhar@linux.ibm.com wrote: > 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. Doesn't really save much, but I guess we should be consistent: Reviewed-by: Christoph Hellwig <hch@lst.de> Nit: your commit message could be condensed a bit by using up all 73 characters. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() 2026-02-10 15:46 ` Christoph Hellwig @ 2026-02-10 15:50 ` Nirjhar Roy 0 siblings, 0 replies; 7+ messages in thread From: Nirjhar Roy @ 2026-02-10 15:50 UTC (permalink / raw) To: Christoph Hellwig Cc: linux-xfs, ritesh.list, ojaswin, djwong, cem, nirjhar.roy.lists On 2/10/26 21:16, Christoph Hellwig wrote: > On Tue, Feb 10, 2026 at 05:56:35PM +0530, nirjhar@linux.ibm.com wrote: >> 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. > Doesn't really save much, but I guess we should be consistent: > > Reviewed-by: Christoph Hellwig <hch@lst.de> > > Nit: your commit message could be condensed a bit by using up all 73 > characters. I will fix this. Thank you. --NR > -- Nirjhar Roy Linux Kernel Developer IBM, Bangalore ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-10 15:51 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-02-10 12:26 [patch v1 0/2] Misc refactorings in XFS nirjhar 2026-02-10 12:26 ` [patch v1 1/2] xfs: Refactoring the nagcount and delta calculation nirjhar 2026-02-10 15:44 ` Christoph Hellwig 2026-02-10 15:48 ` Nirjhar Roy 2026-02-10 12:26 ` [patch v1 2/2] xfs: Replace &rtg->rtg_group with rtg_group() nirjhar 2026-02-10 15:46 ` Christoph Hellwig 2026-02-10 15:50 ` Nirjhar Roy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox