Skip to content

feat(fast_io): BGID recycling observability (#2296)#4362

Closed
oferchen wants to merge 1 commit into
masterfrom
feat/bgid-free-list-recycling
Closed

feat(fast_io): BGID recycling observability (#2296)#4362
oferchen wants to merge 1 commit into
masterfrom
feat/bgid-free-list-recycling

Conversation

@oferchen
Copy link
Copy Markdown
Owner

Summary

  • Add BGID_REUSED_COUNT and BGID_FRESH_COUNT atomic counters that record whether each BgidAllocator::allocate call was satisfied from the free-list or by minting from NEXT_BGID.
  • Expose BgidAllocator::bgid_reused_count() and BgidAllocator::bgid_freshly_allocated_count() accessors via the existing fast_io re-export so benchmarks and operators can read the recycle ratio without touching the free-list mutex.
  • Mirror both accessors in io_uring_stub/buffer_ring.rs so cross-platform callers compile without cfg-gating.

The free-list-first allocation path itself was already in place (see docs/audits/bgid-lifecycle.md sections 2 and 7, lines 197-203 in buffer_ring.rs); this change adds the observability hooks that BGE-4 calls for so the existing recycling policy is bench-verifiable.

Test plan

  • BgidAllocator allocates 10, deallocates all, allocates 10 again: bgid_reused_count() >= 10, bgid_freshly_allocated_count() == 10.
  • BgidAllocator allocates 100 fresh with no deallocs: bgid_reused_count() == 0, bgid_freshly_allocated_count() == 100.
  • Forced exhaustion does not advance either counter.
  • cargo fmt --all.
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl.

Free-list-first allocation already exists in BgidAllocator::allocate
(see docs/audits/bgid-lifecycle.md sections 2 and 7); this change adds
two atomic counters so callers can verify the recycling policy is in
effect and operators can monitor steady-state churn.

- BGID_REUSED_COUNT: incremented when allocate pops from the free-list.
- BGID_FRESH_COUNT: incremented when allocate mints a new id from
  NEXT_BGID. Exhaustion (BgidExhausted) does not advance either
  counter.
- Public accessors BgidAllocator::bgid_reused_count and
  BgidAllocator::bgid_freshly_allocated_count expose the snapshot
  values via the existing fast_io re-export.
- Stub parity in io_uring_stub/buffer_ring.rs returns 0 for both so
  cross-platform callers compile without cfg-gating.

Tests cover the three policy assertions called out in the BGE-4 spec:
ten alloc/free/alloc cycles count at least ten reuses; 100 fresh
allocations leave reused at 0; failed exhausted allocations leave both
counters untouched.
@github-actions github-actions Bot added the enhancement New feature or request label May 17, 2026
@oferchen
Copy link
Copy Markdown
Owner Author

Superseded: BGID free-list logic is in master via #4355/#4391

@oferchen oferchen closed this May 18, 2026
@oferchen oferchen deleted the feat/bgid-free-list-recycling branch May 19, 2026 15:13
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