Repository navigation
feat: reuse io_uring buffer group IDs via free-list - #4019
Merged
Merged
Conversation
Track returned bgids in a process-wide free-list so long-running daemons that cycle through many `BufferRing` instances can reuse identifiers instead of monotonically exhausting the 16-bit namespace. `allocate` drains the free-list before advancing the counter, `deallocate` returns an id (idempotent on duplicates), and `remaining` reflects free-list size so callers can probe headroom. `BufferRing::new_with_allocator` is the new entry point that takes ownership of an allocator-issued bgid; its `Drop` returns the id via `BgidAllocator::deallocate`. Caller-supplied bgids passed to `new` remain caller-owned and are not touched on drop. Refs #2044, follow-up to #4005.
4 tasks
oferchen
added a commit
that referenced
this pull request
May 18, 2026
* feat: reuse io_uring buffer group IDs via free-list Track returned bgids in a process-wide free-list so long-running daemons that cycle through many `BufferRing` instances can reuse identifiers instead of monotonically exhausting the 16-bit namespace. `allocate` drains the free-list before advancing the counter, `deallocate` returns an id (idempotent on duplicates), and `remaining` reflects free-list size so callers can probe headroom. `BufferRing::new_with_allocator` is the new entry point that takes ownership of an allocator-issued bgid; its `Drop` returns the id via `BgidAllocator::deallocate`. Caller-supplied bgids passed to `new` remain caller-owned and are not touched on drop. Refs #2044, follow-up to #4005. * style: apply cargo fmt to bgid free-list
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
* feat: reuse io_uring buffer group IDs via free-list Track returned bgids in a process-wide free-list so long-running daemons that cycle through many `BufferRing` instances can reuse identifiers instead of monotonically exhausting the 16-bit namespace. `allocate` drains the free-list before advancing the counter, `deallocate` returns an id (idempotent on duplicates), and `remaining` reflects free-list size so callers can probe headroom. `BufferRing::new_with_allocator` is the new entry point that takes ownership of an allocator-issued bgid; its `Drop` returns the id via `BgidAllocator::deallocate`. Caller-supplied bgids passed to `new` remain caller-owned and are not touched on drop. Refs #2044, follow-up to #4005. * style: apply cargo fmt to bgid free-list
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
* feat: reuse io_uring buffer group IDs via free-list Track returned bgids in a process-wide free-list so long-running daemons that cycle through many `BufferRing` instances can reuse identifiers instead of monotonically exhausting the 16-bit namespace. `allocate` drains the free-list before advancing the counter, `deallocate` returns an id (idempotent on duplicates), and `remaining` reflects free-list size so callers can probe headroom. `BufferRing::new_with_allocator` is the new entry point that takes ownership of an allocator-issued bgid; its `Drop` returns the id via `BgidAllocator::deallocate`. Caller-supplied bgids passed to `new` remain caller-owned and are not touched on drop. Refs #2044, follow-up to #4005. * style: apply cargo fmt to bgid free-list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BgidAllocatorso deallocated buffer group IDs are reused before the monotonic counter advances. Long-running daemons that cycle through manyBufferRinginstances now stay within the 16-bit bgid namespace.BgidAllocator::deallocate(bgid)(idempotent on duplicate ids) and updatesremaining()to include free-list entries so callers can probe true headroom.BufferRing::new_with_allocator()which takes ownership of an allocator-issued bgid; the ring'sDropreturns the id viaBgidAllocator::deallocate. Caller-supplied bgids passed to the originalnew()remain caller-owned and are not touched on drop, preserving the existing API contract.io_uring_stub(Err(Unsupported)fornew_with_allocator, no-opdeallocate) so cross-platform builds compile withoutcfg-gating.Background: #4005 added the original
BgidAllocatorthat returnsBgidExhaustedonce the u16 namespace is full. This change makes exhaustion recoverable by reclaiming ids on ring drop. Refs #2044, follow-up to #4005.Test plan
bgid_allocator_reuses_freed_ids- allocate, deallocate, allocate returns the same idbgid_allocator_free_list_persists_after_exhaustion- counter at limit, deallocate one id, allocate succeeds with the freed idbgid_allocator_remaining_includes_free_list-remaining()reflects free-list size, idempotent deallocate does not inflate the countbgid_allocator_deallocate_is_idempotent- duplicate deallocate is a no-opbgid_allocator_exhaustion_returns_error- tightened to use a snapshot guard that also clears the free-list, preventing inter-test flakinessbuffer_ring_new_with_allocator_returns_error_on_stub,bgid_allocator_reports_exhausted_on_stub