Skip to content

feat(fast_io): lease per-thread BGID slice from BGE-4 pool (IUR-3.e) - #4811

Merged
oferchen merged 3 commits into
masterfrom
feat/iur-3e-bgid-per-thread-lease
May 23, 2026
Merged

oferchen merged 3 commits into
masterfrom
feat/iur-3e-bgid-per-thread-lease

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add BgidLease RAII handle that batch-allocates BGIDs from the BGE-4 central pool (BgidAllocator) on construction and returns them on Drop.
  • Add BgidAllocator::allocate_batch / deallocate_batch so the central Mutex<Vec<u16>> is acquired once per slice instead of once per id.
  • Each per-thread io_uring ring leases a slice (default 16) on first use via the thread-local with_thread_lease entry point; subsequent allocations on the same thread are lock-free until the lease drains.
  • Disjoint-slice guarantee under concurrent leases (the central lock serializes counter advances and free-list drains).
  • Non-Linux stub mirrors the new signatures so cross-platform callers do not need cfg gating.

Test plan

  • Unit: cached lease pops each id once before draining
  • Unit: refill restores cache to batch_size; no-op at full capacity
  • Unit: batch_size == 0 is rejected with InvalidInput
  • Unit: Drop returns cached ids to the central pool (snapshot remaining)
  • Unit: two concurrent threads obtain disjoint slices and both return on Drop
  • Unit: with_thread_lease reuses per-thread state across consecutive calls
  • Unit: re-entrant with_thread_lease rejected as WouldBlock

@github-actions github-actions Bot added the enhancement New feature or request label May 23, 2026
@oferchen
oferchen force-pushed the feat/iur-3e-bgid-per-thread-lease branch 7 times, most recently from 7a664f8 to 51969e3 Compare May 23, 2026 20:53
oferchen added 3 commits May 23, 2026 23:55
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
oferchen force-pushed the feat/iur-3e-bgid-per-thread-lease branch from 51969e3 to 2ae59b5 Compare May 23, 2026 20:55
@oferchen
oferchen merged commit 81613d2 into master May 23, 2026
58 checks passed
@oferchen
oferchen deleted the feat/iur-3e-bgid-per-thread-lease branch May 28, 2026 03:37
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.
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