Repository navigation
feat(fast_io): io_uring session ring pool (#1937) - #4275
Merged
Merged
Conversation
Introduces SessionRingPool, a small fleet of long-lived io_uring rings
that consumers lease for one submit/reap cycle, amortising
io_uring_setup(2) and IORING_REGISTER_* costs across daemon sessions.
The primitive lives in crates/fast_io/src/io_uring/session_pool.rs on
Linux with a stub in io_uring_stub.rs for other targets. Selection is
round-robin via a single relaxed AtomicUsize; per-ring contention falls
on individual std::sync::Mutex slots. Drop releases every ring
deterministically, including any SQPOLL kthread.
Existing shared_ring.rs consumers stay on the single-mutex pattern.
Migrations land one consumer at a time in follow-ups per the design
plan in docs/design/iouring-session-ring-pool-impl.md.
API surface:
- SessionRingPool::{new,try_new,acquire,acquire_slot,ring_count,config}
- SessionPoolConfig with from_io_uring_config / with_ring_count helpers
- RingLease: RAII handle dereferencing to &mut IoUring
2 tasks
oferchen
added a commit
that referenced
this pull request
May 17, 2026
… (#4285) Audits whether prerequisites for #1876 have landed and proposes splitting the work into reviewable subtasks (#1876-a through e). - #1874 (shared ring + POLL_ADD) shipped via PR #3553. - #1937 (session ring pool) shipped via PR #4275. - #1935 (hybrid tokio listener) shipped via PR #4278. - No io_uring task carries id #1875; the original dependency note most plausibly meant the session-pool and listener work above. Missing surface enumerated: pooled-ring constructors on the socket adapters, daemon plumbing for SessionRingPool, sync and async worker swaps, IORING_OP_LINK_TIMEOUT integration, and async-cancel discipline. Trigger conditions (kernel >= 5.6, io_uring feature, opt-in flag) and a five-step implementation plan included.
5 of 6 tasks
oferchen
added a commit
that referenced
this pull request
May 17, 2026
Scaffold the `IORING_OP_ASYNC_CANCEL` primitive now that the async daemon listener (#4278), session ring pool (#4275), and per-thread rings (#4288) have landed code paths that keep SQEs in-flight across abort decision points. Until now, every io_uring helper followed `submit + wait + drain` and never needed cancellation; the deferred design at `docs/design/iouring-async-cancel.md` documented the trigger condition this commit fulfils. - New module `crates/fast_io/src/io_uring/cancel.rs` (Linux + `io_uring` feature gated): - `cancel_by_user_data(&mut IoUring, u64) -> io::Result<CancelOutcome>` submits a single `IORING_OP_ASYNC_CANCEL` SQE matched against the target SQE's `user_data` tag and reports the kernel's terminal outcome. - `cancel_all_by_fd(&mut IoUring, RawFd) -> io::Result<usize>` uses `IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_ALL` (kernel 5.19+) to cancel every in-flight SQE that touches the given fd. - `enum CancelOutcome { Cancelled, NotFound, AlreadyComplete }` maps the three race outcomes (`0`, `-ENOENT`, `-EALREADY`) to typed variants so callers route into the correct buffer reclaim path. - Added `OpTag::Cancel` so cancel CQEs are demuxable from target CQEs sharing the same CQ; updated `SharedRing::reap` to flag a Cancel CQE as an InvalidData misuse rather than silently drop it. - Added cross-platform UAPI constants `IORING_OP_ASYNC_CANCEL`, `ASYNC_CANCEL_MIN_KERNEL`, `ASYNC_CANCEL_FD_MIN_KERNEL` in `io_uring_common`, mirrored in the non-Linux stub. - Stub module in `io_uring_stub.rs` returns `Unsupported` so cross-platform callers compile without `cfg` branching. - Re-exported the primitive from the `io_uring` module and `CancelOutcome` from the crate root. - Unit coverage: - `cancel_by_user_data_cancels_inflight_poll` submits a PollAdd on an empty pipe, cancels it, asserts `CancelOutcome::Cancelled`. - `cancel_by_user_data_reports_not_found_for_unknown_tag` asserts `-ENOENT` is folded into `NotFound`, not surfaced as an error. - `cancel_all_by_fd_cancels_inflight_polls` cancels two PollAdds bulk-by-fd (skips cleanly on kernels < 5.19). - `CancelOutcome::from_cqe_result` decode parity for each variant plus error surface for other errnos. - Stub mirrors assert `Unsupported` and constant parity.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Introduces SessionRingPool, a small fleet of long-lived io_uring rings
that consumers lease for one submit/reap cycle, amortising
io_uring_setup(2) and IORING_REGISTER_* costs across daemon sessions.
The primitive lives in crates/fast_io/src/io_uring/session_pool.rs on
Linux with a stub in io_uring_stub.rs for other targets. Selection is
round-robin via a single relaxed AtomicUsize; per-ring contention falls
on individual std::sync::Mutex slots. Drop releases every ring
deterministically, including any SQPOLL kthread.
Existing shared_ring.rs consumers stay on the single-mutex pattern.
Migrations land one consumer at a time in follow-ups per the design
plan in docs/design/iouring-session-ring-pool-impl.md.
API surface:
- SessionRingPool::{new,try_new,acquire,acquire_slot,ring_count,config}
- SessionPoolConfig with from_io_uring_config / with_ring_count helpers
- RingLease: RAII handle dereferencing to &mut IoUring
oferchen
added a commit
that referenced
this pull request
May 18, 2026
… (#4285) Audits whether prerequisites for #1876 have landed and proposes splitting the work into reviewable subtasks (#1876-a through e). - #1874 (shared ring + POLL_ADD) shipped via PR #3553. - #1937 (session ring pool) shipped via PR #4275. - #1935 (hybrid tokio listener) shipped via PR #4278. - No io_uring task carries id #1875; the original dependency note most plausibly meant the session-pool and listener work above. Missing surface enumerated: pooled-ring constructors on the socket adapters, daemon plumbing for SessionRingPool, sync and async worker swaps, IORING_OP_LINK_TIMEOUT integration, and async-cancel discipline. Trigger conditions (kernel >= 5.6, io_uring feature, opt-in flag) and a five-step implementation plan included.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Scaffold the `IORING_OP_ASYNC_CANCEL` primitive now that the async daemon listener (#4278), session ring pool (#4275), and per-thread rings (#4288) have landed code paths that keep SQEs in-flight across abort decision points. Until now, every io_uring helper followed `submit + wait + drain` and never needed cancellation; the deferred design at `docs/design/iouring-async-cancel.md` documented the trigger condition this commit fulfils. - New module `crates/fast_io/src/io_uring/cancel.rs` (Linux + `io_uring` feature gated): - `cancel_by_user_data(&mut IoUring, u64) -> io::Result<CancelOutcome>` submits a single `IORING_OP_ASYNC_CANCEL` SQE matched against the target SQE's `user_data` tag and reports the kernel's terminal outcome. - `cancel_all_by_fd(&mut IoUring, RawFd) -> io::Result<usize>` uses `IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_ALL` (kernel 5.19+) to cancel every in-flight SQE that touches the given fd. - `enum CancelOutcome { Cancelled, NotFound, AlreadyComplete }` maps the three race outcomes (`0`, `-ENOENT`, `-EALREADY`) to typed variants so callers route into the correct buffer reclaim path. - Added `OpTag::Cancel` so cancel CQEs are demuxable from target CQEs sharing the same CQ; updated `SharedRing::reap` to flag a Cancel CQE as an InvalidData misuse rather than silently drop it. - Added cross-platform UAPI constants `IORING_OP_ASYNC_CANCEL`, `ASYNC_CANCEL_MIN_KERNEL`, `ASYNC_CANCEL_FD_MIN_KERNEL` in `io_uring_common`, mirrored in the non-Linux stub. - Stub module in `io_uring_stub.rs` returns `Unsupported` so cross-platform callers compile without `cfg` branching. - Re-exported the primitive from the `io_uring` module and `CancelOutcome` from the crate root. - Unit coverage: - `cancel_by_user_data_cancels_inflight_poll` submits a PollAdd on an empty pipe, cancels it, asserts `CancelOutcome::Cancelled`. - `cancel_by_user_data_reports_not_found_for_unknown_tag` asserts `-ENOENT` is folded into `NotFound`, not surfaced as an error. - `cancel_all_by_fd_cancels_inflight_polls` cancels two PollAdds bulk-by-fd (skips cleanly on kernels < 5.19). - `CancelOutcome::from_cqe_result` decode parity for each variant plus error surface for other errnos. - Stub mirrors assert `Unsupported` and constant parity.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Introduces SessionRingPool, a small fleet of long-lived io_uring rings
that consumers lease for one submit/reap cycle, amortising
io_uring_setup(2) and IORING_REGISTER_* costs across daemon sessions.
The primitive lives in crates/fast_io/src/io_uring/session_pool.rs on
Linux with a stub in io_uring_stub.rs for other targets. Selection is
round-robin via a single relaxed AtomicUsize; per-ring contention falls
on individual std::sync::Mutex slots. Drop releases every ring
deterministically, including any SQPOLL kthread.
Existing shared_ring.rs consumers stay on the single-mutex pattern.
Migrations land one consumer at a time in follow-ups per the design
plan in docs/design/iouring-session-ring-pool-impl.md.
API surface:
- SessionRingPool::{new,try_new,acquire,acquire_slot,ring_count,config}
- SessionPoolConfig with from_io_uring_config / with_ring_count helpers
- RingLease: RAII handle dereferencing to &mut IoUring
oferchen
added a commit
that referenced
this pull request
May 18, 2026
… (#4285) Audits whether prerequisites for #1876 have landed and proposes splitting the work into reviewable subtasks (#1876-a through e). - #1874 (shared ring + POLL_ADD) shipped via PR #3553. - #1937 (session ring pool) shipped via PR #4275. - #1935 (hybrid tokio listener) shipped via PR #4278. - No io_uring task carries id #1875; the original dependency note most plausibly meant the session-pool and listener work above. Missing surface enumerated: pooled-ring constructors on the socket adapters, daemon plumbing for SessionRingPool, sync and async worker swaps, IORING_OP_LINK_TIMEOUT integration, and async-cancel discipline. Trigger conditions (kernel >= 5.6, io_uring feature, opt-in flag) and a five-step implementation plan included.
oferchen
added a commit
that referenced
this pull request
May 18, 2026
Scaffold the `IORING_OP_ASYNC_CANCEL` primitive now that the async daemon listener (#4278), session ring pool (#4275), and per-thread rings (#4288) have landed code paths that keep SQEs in-flight across abort decision points. Until now, every io_uring helper followed `submit + wait + drain` and never needed cancellation; the deferred design at `docs/design/iouring-async-cancel.md` documented the trigger condition this commit fulfils. - New module `crates/fast_io/src/io_uring/cancel.rs` (Linux + `io_uring` feature gated): - `cancel_by_user_data(&mut IoUring, u64) -> io::Result<CancelOutcome>` submits a single `IORING_OP_ASYNC_CANCEL` SQE matched against the target SQE's `user_data` tag and reports the kernel's terminal outcome. - `cancel_all_by_fd(&mut IoUring, RawFd) -> io::Result<usize>` uses `IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_ALL` (kernel 5.19+) to cancel every in-flight SQE that touches the given fd. - `enum CancelOutcome { Cancelled, NotFound, AlreadyComplete }` maps the three race outcomes (`0`, `-ENOENT`, `-EALREADY`) to typed variants so callers route into the correct buffer reclaim path. - Added `OpTag::Cancel` so cancel CQEs are demuxable from target CQEs sharing the same CQ; updated `SharedRing::reap` to flag a Cancel CQE as an InvalidData misuse rather than silently drop it. - Added cross-platform UAPI constants `IORING_OP_ASYNC_CANCEL`, `ASYNC_CANCEL_MIN_KERNEL`, `ASYNC_CANCEL_FD_MIN_KERNEL` in `io_uring_common`, mirrored in the non-Linux stub. - Stub module in `io_uring_stub.rs` returns `Unsupported` so cross-platform callers compile without `cfg` branching. - Re-exported the primitive from the `io_uring` module and `CancelOutcome` from the crate root. - Unit coverage: - `cancel_by_user_data_cancels_inflight_poll` submits a PollAdd on an empty pipe, cancels it, asserts `CancelOutcome::Cancelled`. - `cancel_by_user_data_reports_not_found_for_unknown_tag` asserts `-ENOENT` is folded into `NotFound`, not surfaced as an error. - `cancel_all_by_fd_cancels_inflight_polls` cancels two PollAdds bulk-by-fd (skips cleanly on kernels < 5.19). - `CancelOutcome::from_cqe_result` decode parity for each variant plus error surface for other errnos. - Stub mirrors assert `Unsupported` and constant parity.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Introduces SessionRingPool, a small fleet of long-lived io_uring rings
that consumers lease for one submit/reap cycle, amortising
io_uring_setup(2) and IORING_REGISTER_* costs across daemon sessions.
The primitive lives in crates/fast_io/src/io_uring/session_pool.rs on
Linux with a stub in io_uring_stub.rs for other targets. Selection is
round-robin via a single relaxed AtomicUsize; per-ring contention falls
on individual std::sync::Mutex slots. Drop releases every ring
deterministically, including any SQPOLL kthread.
Existing shared_ring.rs consumers stay on the single-mutex pattern.
Migrations land one consumer at a time in follow-ups per the design
plan in docs/design/iouring-session-ring-pool-impl.md.
API surface:
- SessionRingPool::{new,try_new,acquire,acquire_slot,ring_count,config}
- SessionPoolConfig with from_io_uring_config / with_ring_count helpers
- RingLease: RAII handle dereferencing to &mut IoUring
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
… (#4285) Audits whether prerequisites for #1876 have landed and proposes splitting the work into reviewable subtasks (#1876-a through e). - #1874 (shared ring + POLL_ADD) shipped via PR #3553. - #1937 (session ring pool) shipped via PR #4275. - #1935 (hybrid tokio listener) shipped via PR #4278. - No io_uring task carries id #1875; the original dependency note most plausibly meant the session-pool and listener work above. Missing surface enumerated: pooled-ring constructors on the socket adapters, daemon plumbing for SessionRingPool, sync and async worker swaps, IORING_OP_LINK_TIMEOUT integration, and async-cancel discipline. Trigger conditions (kernel >= 5.6, io_uring feature, opt-in flag) and a five-step implementation plan included.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Scaffold the `IORING_OP_ASYNC_CANCEL` primitive now that the async daemon listener (#4278), session ring pool (#4275), and per-thread rings (#4288) have landed code paths that keep SQEs in-flight across abort decision points. Until now, every io_uring helper followed `submit + wait + drain` and never needed cancellation; the deferred design at `docs/design/iouring-async-cancel.md` documented the trigger condition this commit fulfils. - New module `crates/fast_io/src/io_uring/cancel.rs` (Linux + `io_uring` feature gated): - `cancel_by_user_data(&mut IoUring, u64) -> io::Result<CancelOutcome>` submits a single `IORING_OP_ASYNC_CANCEL` SQE matched against the target SQE's `user_data` tag and reports the kernel's terminal outcome. - `cancel_all_by_fd(&mut IoUring, RawFd) -> io::Result<usize>` uses `IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_ALL` (kernel 5.19+) to cancel every in-flight SQE that touches the given fd. - `enum CancelOutcome { Cancelled, NotFound, AlreadyComplete }` maps the three race outcomes (`0`, `-ENOENT`, `-EALREADY`) to typed variants so callers route into the correct buffer reclaim path. - Added `OpTag::Cancel` so cancel CQEs are demuxable from target CQEs sharing the same CQ; updated `SharedRing::reap` to flag a Cancel CQE as an InvalidData misuse rather than silently drop it. - Added cross-platform UAPI constants `IORING_OP_ASYNC_CANCEL`, `ASYNC_CANCEL_MIN_KERNEL`, `ASYNC_CANCEL_FD_MIN_KERNEL` in `io_uring_common`, mirrored in the non-Linux stub. - Stub module in `io_uring_stub.rs` returns `Unsupported` so cross-platform callers compile without `cfg` branching. - Re-exported the primitive from the `io_uring` module and `CancelOutcome` from the crate root. - Unit coverage: - `cancel_by_user_data_cancels_inflight_poll` submits a PollAdd on an empty pipe, cancels it, asserts `CancelOutcome::Cancelled`. - `cancel_by_user_data_reports_not_found_for_unknown_tag` asserts `-ENOENT` is folded into `NotFound`, not surfaced as an error. - `cancel_all_by_fd_cancels_inflight_polls` cancels two PollAdds bulk-by-fd (skips cleanly on kernels < 5.19). - `CancelOutcome::from_cqe_result` decode parity for each variant plus error surface for other errnos. - Stub mirrors assert `Unsupported` and constant parity.
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
SessionRingPoolandSessionPoolConfigtofast_io::io_uringplus a non-Linux stub, giving callers a small fleet of long-lived rings to lease for one submit/reap cycle. The primitive amortisesio_uring_setup(2)andIORING_REGISTER_*costs across bursty daemon connections.AtomicUsize; per-ring contention falls on individualstd::sync::Mutexslots so callers can opt out by leasing a specific slot.Dropreleases every ring (and any SQPOLL kthread) deterministically.shared_ring.rsconsumers stay on the single-mutex pattern. Migrations ofdisk_batch,file_writer,file_reader, andregistered_buffersland one consumer at a time per the design indocs/design/iouring-session-ring-pool-impl.md.Test plan
crates/fast_io/src/io_uring/session_pool.rs::tests: default config, ring-count clamping,try_newfailure surface, four-lease distinct-slot fan-out, 8x64 concurrent acquire with <=25% balance, drop-and-rebuild, out-of-boundsacquire_slot.io_uring_stub.rs.