Repository navigation
feat(fast_io): lease per-thread BGID slice from BGE-4 pool (IUR-3.e) - #4811
Merged
Merged
Conversation
oferchen
force-pushed
the
feat/iur-3e-bgid-per-thread-lease
branch
7 times, most recently
from
May 23, 2026 20:53
7a664f8 to
51969e3
Compare
Add a BgidLease RAII handle that batch-allocates BGIDs from the BGE-4 central pool on construction and returns them on Drop. Each per-thread io_uring ring leases a slice (default 16) on first use, so the central Mutex<Vec<u16>> is hit once per slice instead of once per allocation. Disjoint-slice guarantee: BgidAllocator::allocate_batch advances the monotonic counter and drains the free-list under the central lock, so concurrent leases observe disjoint id ranges. The thread-local entry point with_thread_lease keeps one lease per OS thread; the lease's Drop runs on thread exit and returns every cached id via deallocate_batch in a single lock acquisition. Unit tests cover: cache pop until empty, refill restores to batch_size, zero batch_size rejected, Drop returns cached ids, two concurrent threads receive disjoint slices, with_thread_lease reuse + re-entrant rejection. Non-Linux stub mirrors the new allocate_batch / deallocate_batch signatures so cross-platform callers do not need cfg gating.
allocate_batch surfaces the error via io::Error::from at call sites, so the unqualified BgidAllocError import is unused and -D warnings rejects it. Doc comment still cites BgidAllocError by path.
expect_err requires Debug on the Ok variant; derive it so the zero_batch_size_rejected test compiles under -D warnings.
oferchen
force-pushed
the
feat/iur-3e-bgid-per-thread-lease
branch
from
May 23, 2026 20:55
51969e3 to
2ae59b5
Compare
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…4811) * feat(fast_io): lease per-thread BGID slice from BGE-4 pool (IUR-3.e) Add a BgidLease RAII handle that batch-allocates BGIDs from the BGE-4 central pool on construction and returns them on Drop. Each per-thread io_uring ring leases a slice (default 16) on first use, so the central Mutex<Vec<u16>> is hit once per slice instead of once per allocation. Disjoint-slice guarantee: BgidAllocator::allocate_batch advances the monotonic counter and drains the free-list under the central lock, so concurrent leases observe disjoint id ranges. The thread-local entry point with_thread_lease keeps one lease per OS thread; the lease's Drop runs on thread exit and returns every cached id via deallocate_batch in a single lock acquisition. Unit tests cover: cache pop until empty, refill restores to batch_size, zero batch_size rejected, Drop returns cached ids, two concurrent threads receive disjoint slices, with_thread_lease reuse + re-entrant rejection. Non-Linux stub mirrors the new allocate_batch / deallocate_batch signatures so cross-platform callers do not need cfg gating. * fix(fast_io): drop unused BgidAllocError import in bgid_lease allocate_batch surfaces the error via io::Error::from at call sites, so the unqualified BgidAllocError import is unused and -D warnings rejects it. Doc comment still cites BgidAllocError by path. * fix(fast_io): derive Debug for BgidLease expect_err requires Debug on the Ok variant; derive it so the zero_batch_size_rejected test compiles under -D warnings.
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
BgidLeaseRAII handle that batch-allocates BGIDs from the BGE-4 central pool (BgidAllocator) on construction and returns them onDrop.BgidAllocator::allocate_batch/deallocate_batchso the centralMutex<Vec<u16>>is acquired once per slice instead of once per id.with_thread_leaseentry point; subsequent allocations on the same thread are lock-free until the lease drains.Test plan
batch_size == 0is rejected withInvalidInputwith_thread_leasereuses per-thread state across consecutive callswith_thread_leaserejected asWouldBlock