Skip to content

feat: reuse io_uring buffer group IDs via free-list - #4019

Merged
oferchen merged 2 commits into
masterfrom
feat/bgid-reuse-free-list
May 14, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/bgid-reuse-free-list

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds a process-wide free-list to BgidAllocator so deallocated buffer group IDs are reused before the monotonic counter advances. Long-running daemons that cycle through many BufferRing instances now stay within the 16-bit bgid namespace.
  • Introduces BgidAllocator::deallocate(bgid) (idempotent on duplicate ids) and updates remaining() to include free-list entries so callers can probe true headroom.
  • Adds BufferRing::new_with_allocator() which takes ownership of an allocator-issued bgid; the ring's Drop returns the id via BgidAllocator::deallocate. Caller-supplied bgids passed to the original new() remain caller-owned and are not touched on drop, preserving the existing API contract.
  • Mirrors the new method on the non-Linux io_uring_stub (Err(Unsupported) for new_with_allocator, no-op deallocate) so cross-platform builds compile without cfg-gating.

Background: #4005 added the original BgidAllocator that returns BgidExhausted once 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 id
  • bgid_allocator_free_list_persists_after_exhaustion - counter at limit, deallocate one id, allocate succeeds with the freed id
  • bgid_allocator_remaining_includes_free_list - remaining() reflects free-list size, idempotent deallocate does not inflate the count
  • bgid_allocator_deallocate_is_idempotent - duplicate deallocate is a no-op
  • bgid_allocator_exhaustion_returns_error - tightened to use a snapshot guard that also clears the free-list, preventing inter-test flakiness
  • Stub mirrors: buffer_ring_new_with_allocator_returns_error_on_stub, bgid_allocator_reports_exhausted_on_stub
  • CI required checks: fmt+clippy, nextest (stable), Windows, macOS, Linux musl

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.
@github-actions github-actions Bot added the enhancement New feature or request label May 14, 2026
@oferchen
oferchen merged commit a9052cb into master May 14, 2026
38 of 39 checks passed
@oferchen
oferchen deleted the feat/bgid-reuse-free-list branch May 14, 2026 14:57
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant