* Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 13:22 ` [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs Brian Foster
@ 2026-08-14 13:57 ` Brian Foster
2026-08-14 14:15 ` [External] : " Mark Tinguely
2026-08-14 23:57 ` Darrick J. Wong
2026-08-17 22:55 ` Dave Chinner
2 siblings, 1 reply; 15+ messages in thread
From: Brian Foster @ 2026-08-14 13:57 UTC (permalink / raw)
To: linux-xfs; +Cc: Matt Fleming
On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> Matt Fleming reports a filesystem shutdown due to inobt block
> allocation failure during sparse chunk allocation. Inode creation
> can involve multiple allocations in a transaction: the initial chunk
> allocation and inode btree blocks via inobt record insertion. This
> is expected to be safe by using the minleft parameter on the chunk
> allocation to guarantee the selected AG has blocks available for
> a followup inobt insertion.
>
> The sequence that leads to this failure is that the alloc and inode
> btrees are all full (require a full split on next insertion) and the
> AG has just enough free space to satisfy a sparse chunk allocation
> with minleft set (i.e. 7 blocks in this example). The chunk
> allocation splits a free extent, triggers full allocbt splits, and
> consumes 4 free blocks for the chunk and 4 AGFL blocks for the
> btrees.
>
> Next, the inobt record insertion triggers an inobt split. The AG has
> enough free blocks, but the allocbt splits caused by the chunk
> allocation have increased the min AGFL requirement for the AG due to
> btree level increases. The AGFL requirement as calculated by
> xfs_alloc_fix_freelist() is:
>
> free + AGFL - res - minfree - minleft = avail
>
> This evaluates to the following on initial chunk allocation:
>
> 2514 + 8 - 2505 - 8 - 2 = 7
>
> ... and then after the chunk allocation but before the inobt block
> allocation:
>
> 2510 + 4 - 2505 - 12 - 0 = -3
>
> This causes the inobt alloc to fail despite minleft being set in the
> first allocation. The error path cancels the dirty transaction and
> shuts down the fs.
>
> The problem here is that while minleft ensures free blocks are
> available for the inobt insert, it is not sufficient to cover the
> increase of the AGFL min free requirement. To address this, create a
> variant of the AGFL min free calculation for minleft allocations
> that incorporates an additional allocbt level increase.
>
> We do not add the additional blocks directly to min_free because
> this would lead to spurious AGFL block allocations and frees in the
> common case (i.e. no btree splits). Instead, add the surplus block
> requirement to the minleft value used to select the AG. This ensures
> the AG has enough blocks for the caller's minleft value plus the
> worst case increase in the AGFL. In the example above, the initial
> calculation now evaluates to 3 blocks available instead of 7 and the
> sparse inode allocation fails gracefully with -ENOSPC.
>
> Reported-by: Matt Fleming <matt@readmodwrite.com>
> Assisted-by: LLM
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
> fs/xfs/libxfs/xfs_alloc.h | 2 ++
> fs/xfs/libxfs/xfs_bmap.c | 2 +-
> 3 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index dbb85fb6314b..74c5b587c87b 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
> return __xfs_alloc_min_freelist(mp, pag, 0);
> }
>
> +/*
> + * Return the minimum freelist requirement considering a potential allocbt split
> + * from the current allocation. Use this when computing longest free extent for
> + * allocations with minleft set to ensure that the available extent length
> + * accounts for the subsequent allocation's increased AGFL requirement.
> + */
> +unsigned int
> +xfs_alloc_min_freelist_minleft(
> + struct xfs_mount *mp,
> + struct xfs_perag *pag)
> +{
> + return __xfs_alloc_min_freelist(mp, pag, 1);
> +}
> +
> /*
> * Check if the operation we are fixing up the freelist for should go ahead or
> * not. If we are freeing blocks, we always allow it, otherwise the allocation
> @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
> xfs_extlen_t reservation; /* blocks that are still reserved */
> int available;
> xfs_extlen_t agflcount;
> + xfs_extlen_t minleft;
>
> if (flags & XFS_ALLOC_FLAG_FREEING)
> return true;
> @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
> * Do we have enough free space remaining for the allocation? Don't
> * account extra agfl blocks because we are about to defer free them,
> * making them unavailable until the current transaction commits.
> + *
> + * If minleft is set, this allocation might cause an allocbt split that
> + * increases the AGFL minimum for the next allocation in the
> + * transaction. Reserve that space from the available block count
> + * (without prematurely growing the AGFL) to prevent the subsequent
> + * allocation from failing due to an increased min_free requirement.
> */
> + minleft = args->minleft;
> + if (minleft) {
> + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
> + min_free;
> + }
> +
> agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free);
> available = (int)(pag->pagf_freeblks + agflcount -
> - reservation - min_free - args->minleft);
> + reservation - min_free - minleft);
> if (available < (int)max(args->total, alloc_len))
> return false;
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
> index 50ef79a1ed41..026b61a63994 100644
> --- a/fs/xfs/libxfs/xfs_alloc.h
> +++ b/fs/xfs/libxfs/xfs_alloc.h
> @@ -73,6 +73,8 @@ xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
> xfs_extlen_t need, xfs_extlen_t reserved);
> unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
> struct xfs_perag *pag);
> +unsigned int xfs_alloc_min_freelist_minleft(struct xfs_mount *mp,
> + struct xfs_perag *pag);
> int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
> int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index d64defeda645..f396df864cf4 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -3160,7 +3160,7 @@ xfs_bmap_longest_free_extent(
> }
>
I intended to add a comment here but lost track. I.e., something like:
/*
* Use the minleft freelist helper because minleft can be set for bmbt
* allocs. If we don't factor it in here, the alloc can be sized
* incorrectly and fail.
*/
I'll wait for any further feedback before reposting.
Brian
> longest = xfs_alloc_longest_free_extent(pag,
> - xfs_alloc_min_freelist(pag_mount(pag), pag),
> + xfs_alloc_min_freelist_minleft(pag_mount(pag), pag),
> xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE));
> if (*blen < longest)
> *blen = longest;
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [External] : Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 13:57 ` Brian Foster
@ 2026-08-14 14:15 ` Mark Tinguely
2026-08-14 14:47 ` Brian Foster
0 siblings, 1 reply; 15+ messages in thread
From: Mark Tinguely @ 2026-08-14 14:15 UTC (permalink / raw)
To: Brian Foster, linux-xfs; +Cc: Matt Fleming
On 8/14/26 8:57 AM, Brian Foster wrote:
> On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
>> Matt Fleming reports a filesystem shutdown due to inobt block
>> allocation failure during sparse chunk allocation. Inode creation
>> can involve multiple allocations in a transaction: the initial chunk
>> allocation and inode btree blocks via inobt record insertion. This
>> is expected to be safe by using the minleft parameter on the chunk
>> allocation to guarantee the selected AG has blocks available for
>> a followup inobt insertion.
>>
>> The sequence that leads to this failure is that the alloc and inode
>> btrees are all full (require a full split on next insertion) and the
>> AG has just enough free space to satisfy a sparse chunk allocation
>> with minleft set (i.e. 7 blocks in this example). The chunk
>> allocation splits a free extent, triggers full allocbt splits, and
>> consumes 4 free blocks for the chunk and 4 AGFL blocks for the
>> btrees.
>>
>> Next, the inobt record insertion triggers an inobt split. The AG has
>> enough free blocks, but the allocbt splits caused by the chunk
>> allocation have increased the min AGFL requirement for the AG due to
>> btree level increases. The AGFL requirement as calculated by
>> xfs_alloc_fix_freelist() is:
>>
>> free + AGFL - res - minfree - minleft = avail
>>
>> This evaluates to the following on initial chunk allocation:
>>
>> 2514 + 8 - 2505 - 8 - 2 = 7
>>
>> ... and then after the chunk allocation but before the inobt block
>> allocation:
>>
>> 2510 + 4 - 2505 - 12 - 0 = -3
>>
>> This causes the inobt alloc to fail despite minleft being set in the
>> first allocation. The error path cancels the dirty transaction and
>> shuts down the fs.
>>
>> The problem here is that while minleft ensures free blocks are
>> available for the inobt insert, it is not sufficient to cover the
>> increase of the AGFL min free requirement. To address this, create a
>> variant of the AGFL min free calculation for minleft allocations
>> that incorporates an additional allocbt level increase.
>>
>> We do not add the additional blocks directly to min_free because
>> this would lead to spurious AGFL block allocations and frees in the
>> common case (i.e. no btree splits). Instead, add the surplus block
>> requirement to the minleft value used to select the AG. This ensures
>> the AG has enough blocks for the caller's minleft value plus the
>> worst case increase in the AGFL. In the example above, the initial
>> calculation now evaluates to 3 blocks available instead of 7 and the
>> sparse inode allocation fails gracefully with -ENOSPC.
>>
>> Reported-by: Matt Fleming <matt@readmodwrite.com>
>> Assisted-by: LLM
>> Signed-off-by: Brian Foster <bfoster@redhat.com>
>> ---
>> fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
>> fs/xfs/libxfs/xfs_alloc.h | 2 ++
>> fs/xfs/libxfs/xfs_bmap.c | 2 +-
>> 3 files changed, 31 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
>> index dbb85fb6314b..74c5b587c87b 100644
>> --- a/fs/xfs/libxfs/xfs_alloc.c
>> +++ b/fs/xfs/libxfs/xfs_alloc.c
>> @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
>> return __xfs_alloc_min_freelist(mp, pag, 0);
>> }
>>
>> +/*
>> + * Return the minimum freelist requirement considering a potential allocbt split
>> + * from the current allocation. Use this when computing longest free extent for
>> + * allocations with minleft set to ensure that the available extent length
>> + * accounts for the subsequent allocation's increased AGFL requirement.
>> + */
>> +unsigned int
>> +xfs_alloc_min_freelist_minleft(
>> + struct xfs_mount *mp,
>> + struct xfs_perag *pag)
>> +{
>> + return __xfs_alloc_min_freelist(mp, pag, 1);
>> +}
>> +
>> /*
>> * Check if the operation we are fixing up the freelist for should go ahead or
>> * not. If we are freeing blocks, we always allow it, otherwise the allocation
>> @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
>> xfs_extlen_t reservation; /* blocks that are still reserved */
>> int available;
>> xfs_extlen_t agflcount;
>> + xfs_extlen_t minleft;
>>
>> if (flags & XFS_ALLOC_FLAG_FREEING)
>> return true;
>> @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
>> * Do we have enough free space remaining for the allocation? Don't
>> * account extra agfl blocks because we are about to defer free them,
>> * making them unavailable until the current transaction commits.
>> + *
>> + * If minleft is set, this allocation might cause an allocbt split that
>> + * increases the AGFL minimum for the next allocation in the
>> + * transaction. Reserve that space from the available block count
>> + * (without prematurely growing the AGFL) to prevent the subsequent
>> + * allocation from failing due to an increased min_free requirement.
>> */
>> + minleft = args->minleft;
>> + if (minleft) {
>> + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
>> + min_free;
>> + }
>> +
>> agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free);
>> available = (int)(pag->pagf_freeblks + agflcount -
>> - reservation - min_free - args->minleft);
>> + reservation - min_free - minleft);
>> if (available < (int)max(args->total, alloc_len))
>> return false;
>>
>> diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
>> index 50ef79a1ed41..026b61a63994 100644
>> --- a/fs/xfs/libxfs/xfs_alloc.h
>> +++ b/fs/xfs/libxfs/xfs_alloc.h
>> @@ -73,6 +73,8 @@ xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
>> xfs_extlen_t need, xfs_extlen_t reserved);
>> unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
>> struct xfs_perag *pag);
>> +unsigned int xfs_alloc_min_freelist_minleft(struct xfs_mount *mp,
>> + struct xfs_perag *pag);
>> int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
>> struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
>> int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
>> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
>> index d64defeda645..f396df864cf4 100644
>> --- a/fs/xfs/libxfs/xfs_bmap.c
>> +++ b/fs/xfs/libxfs/xfs_bmap.c
>> @@ -3160,7 +3160,7 @@ xfs_bmap_longest_free_extent(
>> }
>>
>
> I intended to add a comment here but lost track. I.e., something like:
>
> /*
> * Use the minleft freelist helper because minleft can be set for bmbt
> * allocs. If we don't factor it in here, the alloc can be sized
> * incorrectly and fail.
> */
>
> I'll wait for any further feedback before reposting.
>
> Brian
>
>> longest = xfs_alloc_longest_free_extent(pag,
>> - xfs_alloc_min_freelist(pag_mount(pag), pag),
>> + xfs_alloc_min_freelist_minleft(pag_mount(pag), pag),
>> xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE));
>> if (*blen < longest)
>> *blen = longest;
>> --
>> 2.55.0
>>
>>
thank you for the comment clarification.
I was confused by that change.
Could you CC stable. We saw a version of this problem in Linux 5.15
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [External] : Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 14:15 ` [External] : " Mark Tinguely
@ 2026-08-14 14:47 ` Brian Foster
2026-08-14 15:18 ` Mark Tinguely
0 siblings, 1 reply; 15+ messages in thread
From: Brian Foster @ 2026-08-14 14:47 UTC (permalink / raw)
To: Mark Tinguely; +Cc: linux-xfs, Matt Fleming
On Fri, Aug 14, 2026 at 09:15:15AM -0500, Mark Tinguely wrote:
> On 8/14/26 8:57 AM, Brian Foster wrote:
> > On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> > > Matt Fleming reports a filesystem shutdown due to inobt block
> > > allocation failure during sparse chunk allocation. Inode creation
> > > can involve multiple allocations in a transaction: the initial chunk
> > > allocation and inode btree blocks via inobt record insertion. This
> > > is expected to be safe by using the minleft parameter on the chunk
> > > allocation to guarantee the selected AG has blocks available for
> > > a followup inobt insertion.
> > >
> > > The sequence that leads to this failure is that the alloc and inode
> > > btrees are all full (require a full split on next insertion) and the
> > > AG has just enough free space to satisfy a sparse chunk allocation
> > > with minleft set (i.e. 7 blocks in this example). The chunk
> > > allocation splits a free extent, triggers full allocbt splits, and
> > > consumes 4 free blocks for the chunk and 4 AGFL blocks for the
> > > btrees.
> > >
> > > Next, the inobt record insertion triggers an inobt split. The AG has
> > > enough free blocks, but the allocbt splits caused by the chunk
> > > allocation have increased the min AGFL requirement for the AG due to
> > > btree level increases. The AGFL requirement as calculated by
> > > xfs_alloc_fix_freelist() is:
> > >
> > > free + AGFL - res - minfree - minleft = avail
> > >
> > > This evaluates to the following on initial chunk allocation:
> > >
> > > 2514 + 8 - 2505 - 8 - 2 = 7
> > >
> > > ... and then after the chunk allocation but before the inobt block
> > > allocation:
> > >
> > > 2510 + 4 - 2505 - 12 - 0 = -3
> > >
> > > This causes the inobt alloc to fail despite minleft being set in the
> > > first allocation. The error path cancels the dirty transaction and
> > > shuts down the fs.
> > >
> > > The problem here is that while minleft ensures free blocks are
> > > available for the inobt insert, it is not sufficient to cover the
> > > increase of the AGFL min free requirement. To address this, create a
> > > variant of the AGFL min free calculation for minleft allocations
> > > that incorporates an additional allocbt level increase.
> > >
> > > We do not add the additional blocks directly to min_free because
> > > this would lead to spurious AGFL block allocations and frees in the
> > > common case (i.e. no btree splits). Instead, add the surplus block
> > > requirement to the minleft value used to select the AG. This ensures
> > > the AG has enough blocks for the caller's minleft value plus the
> > > worst case increase in the AGFL. In the example above, the initial
> > > calculation now evaluates to 3 blocks available instead of 7 and the
> > > sparse inode allocation fails gracefully with -ENOSPC.
> > >
> > > Reported-by: Matt Fleming <matt@readmodwrite.com>
> > > Assisted-by: LLM
> > > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > > ---
> > > fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
> > > fs/xfs/libxfs/xfs_alloc.h | 2 ++
> > > fs/xfs/libxfs/xfs_bmap.c | 2 +-
> > > 3 files changed, 31 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> > > index dbb85fb6314b..74c5b587c87b 100644
> > > --- a/fs/xfs/libxfs/xfs_alloc.c
> > > +++ b/fs/xfs/libxfs/xfs_alloc.c
> > > @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
> > > return __xfs_alloc_min_freelist(mp, pag, 0);
> > > }
> > > +/*
> > > + * Return the minimum freelist requirement considering a potential allocbt split
> > > + * from the current allocation. Use this when computing longest free extent for
> > > + * allocations with minleft set to ensure that the available extent length
> > > + * accounts for the subsequent allocation's increased AGFL requirement.
> > > + */
> > > +unsigned int
> > > +xfs_alloc_min_freelist_minleft(
> > > + struct xfs_mount *mp,
> > > + struct xfs_perag *pag)
> > > +{
> > > + return __xfs_alloc_min_freelist(mp, pag, 1);
> > > +}
> > > +
> > > /*
> > > * Check if the operation we are fixing up the freelist for should go ahead or
> > > * not. If we are freeing blocks, we always allow it, otherwise the allocation
> > > @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
> > > xfs_extlen_t reservation; /* blocks that are still reserved */
> > > int available;
> > > xfs_extlen_t agflcount;
> > > + xfs_extlen_t minleft;
> > > if (flags & XFS_ALLOC_FLAG_FREEING)
> > > return true;
> > > @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
> > > * Do we have enough free space remaining for the allocation? Don't
> > > * account extra agfl blocks because we are about to defer free them,
> > > * making them unavailable until the current transaction commits.
> > > + *
> > > + * If minleft is set, this allocation might cause an allocbt split that
> > > + * increases the AGFL minimum for the next allocation in the
> > > + * transaction. Reserve that space from the available block count
> > > + * (without prematurely growing the AGFL) to prevent the subsequent
> > > + * allocation from failing due to an increased min_free requirement.
> > > */
> > > + minleft = args->minleft;
> > > + if (minleft) {
> > > + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
> > > + min_free;
> > > + }
> > > +
> > > agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free);
> > > available = (int)(pag->pagf_freeblks + agflcount -
> > > - reservation - min_free - args->minleft);
> > > + reservation - min_free - minleft);
> > > if (available < (int)max(args->total, alloc_len))
> > > return false;
> > > diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
> > > index 50ef79a1ed41..026b61a63994 100644
> > > --- a/fs/xfs/libxfs/xfs_alloc.h
> > > +++ b/fs/xfs/libxfs/xfs_alloc.h
> > > @@ -73,6 +73,8 @@ xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
> > > xfs_extlen_t need, xfs_extlen_t reserved);
> > > unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
> > > struct xfs_perag *pag);
> > > +unsigned int xfs_alloc_min_freelist_minleft(struct xfs_mount *mp,
> > > + struct xfs_perag *pag);
> > > int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> > > struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
> > > int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> > > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > > index d64defeda645..f396df864cf4 100644
> > > --- a/fs/xfs/libxfs/xfs_bmap.c
> > > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > > @@ -3160,7 +3160,7 @@ xfs_bmap_longest_free_extent(
> > > }
> >
> > I intended to add a comment here but lost track. I.e., something like:
> >
> > /*
> > * Use the minleft freelist helper because minleft can be set for bmbt
> > * allocs. If we don't factor it in here, the alloc can be sized
> > * incorrectly and fail.
> > */
> >
> > I'll wait for any further feedback before reposting.
> >
> > Brian
> >
> > > longest = xfs_alloc_longest_free_extent(pag,
> > > - xfs_alloc_min_freelist(pag_mount(pag), pag),
> > > + xfs_alloc_min_freelist_minleft(pag_mount(pag), pag),
> > > xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE));
> > > if (*blen < longest)
> > > *blen = longest;
> > > --
> > > 2.55.0
> > >
> > >
>
>
> thank you for the comment clarification.
> I was confused by that change.
>
> Could you CC stable. We saw a version of this problem in Linux 5.15
>
Sure, though I'm not sure how far back this will apply cleanly.
Curious.. was the instance you saw also an inobt alloc failure leading
to dirty trans cancel and shutdown, or something different but similar?
Brian
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [External] : Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 14:47 ` Brian Foster
@ 2026-08-14 15:18 ` Mark Tinguely
2026-08-14 16:24 ` Brian Foster
0 siblings, 1 reply; 15+ messages in thread
From: Mark Tinguely @ 2026-08-14 15:18 UTC (permalink / raw)
To: Brian Foster; +Cc: linux-xfs, Matt Fleming
On 8/14/26 9:47 AM, Brian Foster wrote:
> On Fri, Aug 14, 2026 at 09: 15: 15AM -0500, Mark Tinguely wrote: > On 8/14/26 8: 57 AM, Brian Foster wrote: > > On Fri, Aug 14, 2026 at 09: 22: 39AM -0400, Brian Foster wrote: > > > Matt Fleming reports a filesystem shutdown due
>
>
> On Fri, Aug 14, 2026 at 09:15:15AM -0500, Mark Tinguely wrote:
>> On 8/14/26 8:57 AM, Brian Foster wrote:
>> > On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
>> > > Matt Fleming reports a filesystem shutdown due to inobt block
>> > > allocation failure during sparse chunk allocation. Inode creation
(deleted text)
>>
>>
>> thank you for the comment clarification.
>> I was confused by that change.
>>
>> Could you CC stable. We saw a version of this problem in Linux 5.15
>>
>
> Sure, though I'm not sure how far back this will apply cleanly.
>
> Curious.. was the instance you saw also an inobt alloc failure leading
> to dirty trans cancel and shutdown, or something different but similar?
>
> Brian
>
yes the v5.15 problem was a similar sparse inode chunk / inode btree insert failure.
I admit that I did not have the numbers to realize why the inode btree insert failed.
although this is a fundamental allocation flaw, the sparse inode chunk allocation
seems to be the just right/wrong conditions to trigger it.
Fixes: 5419040fc0f3a xfs: introduce inode record hole mask for sparse inode chunks ??
thanks for the fix
Mark Tinguely
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [External] : Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 15:18 ` Mark Tinguely
@ 2026-08-14 16:24 ` Brian Foster
0 siblings, 0 replies; 15+ messages in thread
From: Brian Foster @ 2026-08-14 16:24 UTC (permalink / raw)
To: Mark Tinguely; +Cc: linux-xfs, Matt Fleming
On Fri, Aug 14, 2026 at 10:18:15AM -0500, Mark Tinguely wrote:
> On 8/14/26 9:47 AM, Brian Foster wrote:
> > On Fri, Aug 14, 2026 at 09: 15: 15AM -0500, Mark Tinguely wrote: > On 8/14/26 8: 57 AM, Brian Foster wrote: > > On Fri, Aug 14, 2026 at 09: 22: 39AM -0400, Brian Foster wrote: > > > Matt Fleming reports a filesystem shutdown due
> >
> >
> > On Fri, Aug 14, 2026 at 09:15:15AM -0500, Mark Tinguely wrote:
> > > On 8/14/26 8:57 AM, Brian Foster wrote:
> > > > On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> > > > > Matt Fleming reports a filesystem shutdown due to inobt block
> > > > > allocation failure during sparse chunk allocation. Inode creation
>
>
> (deleted text)
>
> > >
> > >
> > > thank you for the comment clarification.
> > > I was confused by that change.
> > >
> > > Could you CC stable. We saw a version of this problem in Linux 5.15
> > >
> >
> > Sure, though I'm not sure how far back this will apply cleanly.
> >
> > Curious.. was the instance you saw also an inobt alloc failure leading
> > to dirty trans cancel and shutdown, or something different but similar?
> >
> > Brian
> >
>
> yes the v5.15 problem was a similar sparse inode chunk / inode btree insert failure.
> I admit that I did not have the numbers to realize why the inode btree insert failed.
>
Ok.
> although this is a fundamental allocation flaw, the sparse inode chunk allocation
> seems to be the just right/wrong conditions to trigger it.
>
I think that's probably right, but I had the Fixes: tag on v1 and
dropped it here just because I think it's kind of a tenuous connection
now. Re: the discussion on v1, presumably we could have the same thing
happen with bmap allocs and just not see the shutdown because those
allocs are usually more flexible and can fall back to different AGs.
Regardless, wrt stable I think it would be reasonable to target back to
the release that enabled sparse inodes (v4.2) since that's how this is
reproduced in practice, so it probably doesn't make much difference
either way.
Brian
> Fixes: 5419040fc0f3a xfs: introduce inode record hole mask for sparse inode chunks ??
>
> thanks for the fix
>
> Mark Tinguely
>
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 13:22 ` [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs Brian Foster
2026-08-14 13:57 ` Brian Foster
@ 2026-08-14 23:57 ` Darrick J. Wong
2026-08-17 13:13 ` Brian Foster
2026-08-17 22:55 ` Dave Chinner
2 siblings, 1 reply; 15+ messages in thread
From: Darrick J. Wong @ 2026-08-14 23:57 UTC (permalink / raw)
To: Brian Foster; +Cc: linux-xfs, Matt Fleming
On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> Matt Fleming reports a filesystem shutdown due to inobt block
> allocation failure during sparse chunk allocation. Inode creation
> can involve multiple allocations in a transaction: the initial chunk
> allocation and inode btree blocks via inobt record insertion. This
> is expected to be safe by using the minleft parameter on the chunk
> allocation to guarantee the selected AG has blocks available for
> a followup inobt insertion.
>
> The sequence that leads to this failure is that the alloc and inode
> btrees are all full (require a full split on next insertion) and the
> AG has just enough free space to satisfy a sparse chunk allocation
> with minleft set (i.e. 7 blocks in this example). The chunk
> allocation splits a free extent, triggers full allocbt splits, and
> consumes 4 free blocks for the chunk and 4 AGFL blocks for the
> btrees.
>
> Next, the inobt record insertion triggers an inobt split. The AG has
> enough free blocks, but the allocbt splits caused by the chunk
> allocation have increased the min AGFL requirement for the AG due to
> btree level increases. The AGFL requirement as calculated by
> xfs_alloc_fix_freelist() is:
>
> free + AGFL - res - minfree - minleft = avail
>
> This evaluates to the following on initial chunk allocation:
>
> 2514 + 8 - 2505 - 8 - 2 = 7
>
> ... and then after the chunk allocation but before the inobt block
> allocation:
>
> 2510 + 4 - 2505 - 12 - 0 = -3
>
> This causes the inobt alloc to fail despite minleft being set in the
> first allocation. The error path cancels the dirty transaction and
> shuts down the fs.
>
> The problem here is that while minleft ensures free blocks are
> available for the inobt insert, it is not sufficient to cover the
> increase of the AGFL min free requirement. To address this, create a
> variant of the AGFL min free calculation for minleft allocations
> that incorporates an additional allocbt level increase.
>
> We do not add the additional blocks directly to min_free because
> this would lead to spurious AGFL block allocations and frees in the
> common case (i.e. no btree splits). Instead, add the surplus block
> requirement to the minleft value used to select the AG. This ensures
> the AG has enough blocks for the caller's minleft value plus the
> worst case increase in the AGFL. In the example above, the initial
> calculation now evaluates to 3 blocks available instead of 7 and the
> sparse inode allocation fails gracefully with -ENOSPC.
Hrmm. So if I'm understanding this correctly, you're adding to minleft
(if one has been set) enough space to handle an AGFL expansion resulting
from the free space / rmap btrees expanding in height? And you're
effectively saying that we'd rather fail creation and writes with ENOSPC
a little earlier to handle that, than risk a shutdown?
--D
> Reported-by: Matt Fleming <matt@readmodwrite.com>
> Assisted-by: LLM
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
> fs/xfs/libxfs/xfs_alloc.h | 2 ++
> fs/xfs/libxfs/xfs_bmap.c | 2 +-
> 3 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index dbb85fb6314b..74c5b587c87b 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
> return __xfs_alloc_min_freelist(mp, pag, 0);
> }
>
> +/*
> + * Return the minimum freelist requirement considering a potential allocbt split
> + * from the current allocation. Use this when computing longest free extent for
> + * allocations with minleft set to ensure that the available extent length
> + * accounts for the subsequent allocation's increased AGFL requirement.
> + */
> +unsigned int
> +xfs_alloc_min_freelist_minleft(
> + struct xfs_mount *mp,
> + struct xfs_perag *pag)
> +{
> + return __xfs_alloc_min_freelist(mp, pag, 1);
> +}
> +
> /*
> * Check if the operation we are fixing up the freelist for should go ahead or
> * not. If we are freeing blocks, we always allow it, otherwise the allocation
> @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
> xfs_extlen_t reservation; /* blocks that are still reserved */
> int available;
> xfs_extlen_t agflcount;
> + xfs_extlen_t minleft;
>
> if (flags & XFS_ALLOC_FLAG_FREEING)
> return true;
> @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
> * Do we have enough free space remaining for the allocation? Don't
> * account extra agfl blocks because we are about to defer free them,
> * making them unavailable until the current transaction commits.
> + *
> + * If minleft is set, this allocation might cause an allocbt split that
> + * increases the AGFL minimum for the next allocation in the
> + * transaction. Reserve that space from the available block count
> + * (without prematurely growing the AGFL) to prevent the subsequent
> + * allocation from failing due to an increased min_free requirement.
> */
> + minleft = args->minleft;
> + if (minleft) {
> + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
> + min_free;
> + }
> +
> agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free);
> available = (int)(pag->pagf_freeblks + agflcount -
> - reservation - min_free - args->minleft);
> + reservation - min_free - minleft);
> if (available < (int)max(args->total, alloc_len))
> return false;
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
> index 50ef79a1ed41..026b61a63994 100644
> --- a/fs/xfs/libxfs/xfs_alloc.h
> +++ b/fs/xfs/libxfs/xfs_alloc.h
> @@ -73,6 +73,8 @@ xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
> xfs_extlen_t need, xfs_extlen_t reserved);
> unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
> struct xfs_perag *pag);
> +unsigned int xfs_alloc_min_freelist_minleft(struct xfs_mount *mp,
> + struct xfs_perag *pag);
> int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
> int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index d64defeda645..f396df864cf4 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -3160,7 +3160,7 @@ xfs_bmap_longest_free_extent(
> }
>
> longest = xfs_alloc_longest_free_extent(pag,
> - xfs_alloc_min_freelist(pag_mount(pag), pag),
> + xfs_alloc_min_freelist_minleft(pag_mount(pag), pag),
> xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE));
> if (*blen < longest)
> *blen = longest;
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 23:57 ` Darrick J. Wong
@ 2026-08-17 13:13 ` Brian Foster
0 siblings, 0 replies; 15+ messages in thread
From: Brian Foster @ 2026-08-17 13:13 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs, Matt Fleming
On Fri, Aug 14, 2026 at 04:57:48PM -0700, Darrick J. Wong wrote:
> On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> > Matt Fleming reports a filesystem shutdown due to inobt block
> > allocation failure during sparse chunk allocation. Inode creation
> > can involve multiple allocations in a transaction: the initial chunk
> > allocation and inode btree blocks via inobt record insertion. This
> > is expected to be safe by using the minleft parameter on the chunk
> > allocation to guarantee the selected AG has blocks available for
> > a followup inobt insertion.
> >
> > The sequence that leads to this failure is that the alloc and inode
> > btrees are all full (require a full split on next insertion) and the
> > AG has just enough free space to satisfy a sparse chunk allocation
> > with minleft set (i.e. 7 blocks in this example). The chunk
> > allocation splits a free extent, triggers full allocbt splits, and
> > consumes 4 free blocks for the chunk and 4 AGFL blocks for the
> > btrees.
> >
> > Next, the inobt record insertion triggers an inobt split. The AG has
> > enough free blocks, but the allocbt splits caused by the chunk
> > allocation have increased the min AGFL requirement for the AG due to
> > btree level increases. The AGFL requirement as calculated by
> > xfs_alloc_fix_freelist() is:
> >
> > free + AGFL - res - minfree - minleft = avail
> >
> > This evaluates to the following on initial chunk allocation:
> >
> > 2514 + 8 - 2505 - 8 - 2 = 7
> >
> > ... and then after the chunk allocation but before the inobt block
> > allocation:
> >
> > 2510 + 4 - 2505 - 12 - 0 = -3
> >
> > This causes the inobt alloc to fail despite minleft being set in the
> > first allocation. The error path cancels the dirty transaction and
> > shuts down the fs.
> >
> > The problem here is that while minleft ensures free blocks are
> > available for the inobt insert, it is not sufficient to cover the
> > increase of the AGFL min free requirement. To address this, create a
> > variant of the AGFL min free calculation for minleft allocations
> > that incorporates an additional allocbt level increase.
> >
> > We do not add the additional blocks directly to min_free because
> > this would lead to spurious AGFL block allocations and frees in the
> > common case (i.e. no btree splits). Instead, add the surplus block
> > requirement to the minleft value used to select the AG. This ensures
> > the AG has enough blocks for the caller's minleft value plus the
> > worst case increase in the AGFL. In the example above, the initial
> > calculation now evaluates to 3 blocks available instead of 7 and the
> > sparse inode allocation fails gracefully with -ENOSPC.
>
> Hrmm. So if I'm understanding this correctly, you're adding to minleft
> (if one has been set) enough space to handle an AGFL expansion resulting
> from the free space / rmap btrees expanding in height? And you're
> effectively saying that we'd rather fail creation and writes with ENOSPC
> a little earlier to handle that, than risk a shutdown?
>
Yep, pretty much. minleft != 0 is a signal for multiple allocs. The
caller obviously sets the value based on its own needs. The first alloc
fixes up the AGFL and evaluates minleft and whatnot based on that, but
if that alloc splits the trees, the caller's minleft alone doesn't allow
the AG to meet minimum available space requirements for the second alloc
because the split(s) cause the space requirements to increase. Hence,
the allocator has to make sure the caller's multiple-allocation sequence
is safe from the start.
FWIW I feel like we should eventually be able to evolve this into
something a little more elegant, but I haven't quite thought of what
that is and it's kind of a corner case that so far only seems to affect
the sparse inode use case, so a targeted/backportable fix seems
reasonable (IMO).
Brian
> --D
>
> > Reported-by: Matt Fleming <matt@readmodwrite.com>
> > Assisted-by: LLM
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > ---
> > fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
> > fs/xfs/libxfs/xfs_alloc.h | 2 ++
> > fs/xfs/libxfs/xfs_bmap.c | 2 +-
> > 3 files changed, 31 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> > index dbb85fb6314b..74c5b587c87b 100644
> > --- a/fs/xfs/libxfs/xfs_alloc.c
> > +++ b/fs/xfs/libxfs/xfs_alloc.c
> > @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
> > return __xfs_alloc_min_freelist(mp, pag, 0);
> > }
> >
> > +/*
> > + * Return the minimum freelist requirement considering a potential allocbt split
> > + * from the current allocation. Use this when computing longest free extent for
> > + * allocations with minleft set to ensure that the available extent length
> > + * accounts for the subsequent allocation's increased AGFL requirement.
> > + */
> > +unsigned int
> > +xfs_alloc_min_freelist_minleft(
> > + struct xfs_mount *mp,
> > + struct xfs_perag *pag)
> > +{
> > + return __xfs_alloc_min_freelist(mp, pag, 1);
> > +}
> > +
> > /*
> > * Check if the operation we are fixing up the freelist for should go ahead or
> > * not. If we are freeing blocks, we always allow it, otherwise the allocation
> > @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
> > xfs_extlen_t reservation; /* blocks that are still reserved */
> > int available;
> > xfs_extlen_t agflcount;
> > + xfs_extlen_t minleft;
> >
> > if (flags & XFS_ALLOC_FLAG_FREEING)
> > return true;
> > @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
> > * Do we have enough free space remaining for the allocation? Don't
> > * account extra agfl blocks because we are about to defer free them,
> > * making them unavailable until the current transaction commits.
> > + *
> > + * If minleft is set, this allocation might cause an allocbt split that
> > + * increases the AGFL minimum for the next allocation in the
> > + * transaction. Reserve that space from the available block count
> > + * (without prematurely growing the AGFL) to prevent the subsequent
> > + * allocation from failing due to an increased min_free requirement.
> > */
> > + minleft = args->minleft;
> > + if (minleft) {
> > + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
> > + min_free;
> > + }
> > +
> > agflcount = min_t(xfs_extlen_t, pag->pagf_flcount, min_free);
> > available = (int)(pag->pagf_freeblks + agflcount -
> > - reservation - min_free - args->minleft);
> > + reservation - min_free - minleft);
> > if (available < (int)max(args->total, alloc_len))
> > return false;
> >
> > diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
> > index 50ef79a1ed41..026b61a63994 100644
> > --- a/fs/xfs/libxfs/xfs_alloc.h
> > +++ b/fs/xfs/libxfs/xfs_alloc.h
> > @@ -73,6 +73,8 @@ xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
> > xfs_extlen_t need, xfs_extlen_t reserved);
> > unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
> > struct xfs_perag *pag);
> > +unsigned int xfs_alloc_min_freelist_minleft(struct xfs_mount *mp,
> > + struct xfs_perag *pag);
> > int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> > struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
> > int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
> > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> > index d64defeda645..f396df864cf4 100644
> > --- a/fs/xfs/libxfs/xfs_bmap.c
> > +++ b/fs/xfs/libxfs/xfs_bmap.c
> > @@ -3160,7 +3160,7 @@ xfs_bmap_longest_free_extent(
> > }
> >
> > longest = xfs_alloc_longest_free_extent(pag,
> > - xfs_alloc_min_freelist(pag_mount(pag), pag),
> > + xfs_alloc_min_freelist_minleft(pag_mount(pag), pag),
> > xfs_ag_resv_needed(pag, XFS_AG_RESV_NONE));
> > if (*blen < longest)
> > *blen = longest;
> > --
> > 2.55.0
> >
> >
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs
2026-08-14 13:22 ` [PATCH v2 3/3] xfs: incorporate increased AGFL min requirement for minleft allocs Brian Foster
2026-08-14 13:57 ` Brian Foster
2026-08-14 23:57 ` Darrick J. Wong
@ 2026-08-17 22:55 ` Dave Chinner
2 siblings, 0 replies; 15+ messages in thread
From: Dave Chinner @ 2026-08-17 22:55 UTC (permalink / raw)
To: Brian Foster; +Cc: linux-xfs, Matt Fleming
On Fri, Aug 14, 2026 at 09:22:39AM -0400, Brian Foster wrote:
> Matt Fleming reports a filesystem shutdown due to inobt block
> allocation failure during sparse chunk allocation. Inode creation
> can involve multiple allocations in a transaction: the initial chunk
> allocation and inode btree blocks via inobt record insertion. This
> is expected to be safe by using the minleft parameter on the chunk
> allocation to guarantee the selected AG has blocks available for
> a followup inobt insertion.
>
> The sequence that leads to this failure is that the alloc and inode
> btrees are all full (require a full split on next insertion) and the
> AG has just enough free space to satisfy a sparse chunk allocation
> with minleft set (i.e. 7 blocks in this example). The chunk
> allocation splits a free extent, triggers full allocbt splits, and
> consumes 4 free blocks for the chunk and 4 AGFL blocks for the
> btrees.
>
> Next, the inobt record insertion triggers an inobt split. The AG has
> enough free blocks, but the allocbt splits caused by the chunk
> allocation have increased the min AGFL requirement for the AG due to
> btree level increases. The AGFL requirement as calculated by
> xfs_alloc_fix_freelist() is:
>
> free + AGFL - res - minfree - minleft = avail
>
> This evaluates to the following on initial chunk allocation:
>
> 2514 + 8 - 2505 - 8 - 2 = 7
>
> ... and then after the chunk allocation but before the inobt block
> allocation:
>
> 2510 + 4 - 2505 - 12 - 0 = -3
>
> This causes the inobt alloc to fail despite minleft being set in the
> first allocation. The error path cancels the dirty transaction and
> shuts down the fs.
>
> The problem here is that while minleft ensures free blocks are
> available for the inobt insert, it is not sufficient to cover the
> increase of the AGFL min free requirement. To address this, create a
> variant of the AGFL min free calculation for minleft allocations
> that incorporates an additional allocbt level increase.
>
> We do not add the additional blocks directly to min_free because
> this would lead to spurious AGFL block allocations and frees in the
> common case (i.e. no btree splits). Instead, add the surplus block
> requirement to the minleft value used to select the AG. This ensures
> the AG has enough blocks for the caller's minleft value plus the
> worst case increase in the AGFL. In the example above, the initial
> calculation now evaluates to 3 blocks available instead of 7 and the
> sparse inode allocation fails gracefully with -ENOSPC.
>
> Reported-by: Matt Fleming <matt@readmodwrite.com>
> Assisted-by: LLM
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
> fs/xfs/libxfs/xfs_alloc.c | 29 ++++++++++++++++++++++++++++-
> fs/xfs/libxfs/xfs_alloc.h | 2 ++
> fs/xfs/libxfs/xfs_bmap.c | 2 +-
> 3 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index dbb85fb6314b..74c5b587c87b 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -2500,6 +2500,20 @@ xfs_alloc_min_freelist(
> return __xfs_alloc_min_freelist(mp, pag, 0);
> }
>
> +/*
> + * Return the minimum freelist requirement considering a potential allocbt split
> + * from the current allocation. Use this when computing longest free extent for
> + * allocations with minleft set to ensure that the available extent length
> + * accounts for the subsequent allocation's increased AGFL requirement.
> + */
> +unsigned int
> +xfs_alloc_min_freelist_minleft(
> + struct xfs_mount *mp,
> + struct xfs_perag *pag)
> +{
> + return __xfs_alloc_min_freelist(mp, pag, 1);
> +}
> +
> /*
> * Check if the operation we are fixing up the freelist for should go ahead or
> * not. If we are freeing blocks, we always allow it, otherwise the allocation
> @@ -2517,6 +2531,7 @@ xfs_alloc_space_available(
> xfs_extlen_t reservation; /* blocks that are still reserved */
> int available;
> xfs_extlen_t agflcount;
> + xfs_extlen_t minleft;
>
> if (flags & XFS_ALLOC_FLAG_FREEING)
> return true;
> @@ -2533,10 +2548,22 @@ xfs_alloc_space_available(
> * Do we have enough free space remaining for the allocation? Don't
> * account extra agfl blocks because we are about to defer free them,
> * making them unavailable until the current transaction commits.
> + *
> + * If minleft is set, this allocation might cause an allocbt split that
> + * increases the AGFL minimum for the next allocation in the
> + * transaction. Reserve that space from the available block count
> + * (without prematurely growing the AGFL) to prevent the subsequent
> + * allocation from failing due to an increased min_free requirement.
> */
> + minleft = args->minleft;
> + if (minleft) {
> + minleft += xfs_alloc_min_freelist_minleft(args->mp, pag) -
> + min_free;
> + }
This seems fragile to me. It is based on the assumption that
min_free is calculated from xfs_alloc_min_freelist() by the caller,
and then this calculates the difference between what the caller should
have calculated and what is actually needed.
Where this mod is placed also results in the longest available
extent check not taking into account this modified min_free
requirement, whereas the check in xfs_bmap_longest_free_extent() is
modified to take this modified minleft value into account. i.e. the
checks w.r.t. minleft and longest extents are no longer consistent
across the layers.
I'm also concerned that this results in the
xfs_alloc_space_available() caller using different values of "need"
and "minleft" to what the actual space availablity calculation is
using; that feels like a future landmine to me.
i.e. the xfs_alloc_space_available() caller already knows is minleft
is set, so if it were to use xfs_alloc_min_freelist_minleft(), then
there would not need to be this "correction" in this code and all
the values would be consistent.
Unless I'm missing something subtle, I think that the callers should
not need to know it should call xfs_alloc_min_freelist_minleft() or
xfs_alloc_min_freelist() as it feels like exposing internal AGFL
space/btree accounting requirements into an external API. All the
caller needs to signal is whether this is the first of a chain of
allocations or not (i.e. args->minleft != 0), and the internal alloc
code should handle it from there.
Hence I suspect it would be much cleaner just to add a 'bool
multialloc' parameter to xfs_alloc_min_freelist() and have all
callers set it appropriately. That would avoid the need for the
wrapper functions and keep this AGFL reservation wart
completely internal to the AGFL reservation calculation....
Thoughts?
-Dave.
--
Dave Chinner
dgc@kernel.org
^ permalink raw reply [flat|nested] 15+ messages in thread