public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [XFS] Question: can xfs_agfl_free_finish_item exhaust AGFL during bnobt/cntbt split?
@ 2026-04-12 16:32 Jinliang Zheng
  2026-04-13  0:14 ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Jinliang Zheng @ 2026-04-12 16:32 UTC (permalink / raw)
  To: djwong, linux-xfs; +Cc: alexjlzheng

Hi,

I have a question about the deferred AGFL block freeing path and whether it is
safe from AGFL exhaustion during bnobt/cntbt btree splits.

When `xfs_agfl_free_finish_item` runs, it calls:

    xfs_agfl_free_finish_item
      -> xfs_free_agfl_block
           -> xfs_free_ag_extent   (fs/xfs/libxfs/xfs_alloc.c)

`xfs_free_ag_extent` directly manipulates bnobt and cntbt, and inserting a new
free extent record can trigger a btree split. A split will try to allocate a
block from the AGFL via `xfs_allocbt_alloc_block` -> `xfs_alloc_get_freelist`.
If the AGFL is empty at that point, `xfs_alloc_get_freelist` returns
NULLAGBLOCK and the split fails.

The normal extent-freeing path (`__xfs_free_extent`) guards against this by
calling `xfs_free_extent_fix_freelist` first, which invokes
`xfs_alloc_fix_freelist(..., XFS_ALLOC_FLAG_FREEING)` to ensure the AGFL holds
at least `xfs_alloc_min_freelist(mp, pag)` blocks before touching the btrees.

However, `xfs_agfl_free_finish_item` does not call fix_freelist at all.

The deferred AGFL frees are created by `xfs_alloc_fix_freelist` during its
shrink phase: blocks are removed from the AGFL immediately (pagf_flcount is
decremented synchronously by `xfs_alloc_get_freelist`), and their actual return
to the free space btrees is deferred via `xfs_defer_agfl_block`. After the
shrink loop, the AGFL sits at exactly `need` blocks.

But before `xfs_agfl_free_finish_item` executes, `xfs_defer_finish_noroll`
rolls the transaction. Other deferred operations that execute in between—for
example, regular extent frees (`XFS_DEFER_OPS_TYPE_FREE`) that themselves call
fix_freelist and may re-shrink the AGFL, or rmapbt operations—could consume
AGFL blocks and leave the count below `need` by the time our deferred AGFL free
runs.

So my question is: is there a guarantee that the AGFL will have enough blocks
to service any btree split needed by `xfs_free_ag_extent` inside
`xfs_agfl_free_finish_item`? If so, what mechanism provides that guarantee?
I don't see a fix_freelist call or any equivalent reservation in that code path.

Thanks,
Jinliang Zheng

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

end of thread, other threads:[~2026-04-13 22:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-12 16:32 [XFS] Question: can xfs_agfl_free_finish_item exhaust AGFL during bnobt/cntbt split? Jinliang Zheng
2026-04-13  0:14 ` Dave Chinner
2026-04-13  2:48   ` Jinliang Zheng
2026-04-13 22:19     ` Dave Chinner

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