Repository navigation
feat(fast_io): merge reader+writer onto shared io_uring (#1874) - #3553
Merged
Merged
Conversation
Adds `SharedRing`, a single io_uring instance that services both a reader fd and a writer fd in the same session. Submits `IORING_OP_READ` against the registered reader fd and uses `IORING_OP_POLL_ADD` (POLLOUT) on the writer fd so a slow consumer never blocks the shared CQ; the follow-up `IORING_OP_SEND` is then queued only when the kernel signals readiness. Completions are demuxed in arrival order via a 64-bit `user_data` tag (`OpTag` in the high 8 bits, op_id in the low 56), mirroring the io_loop+select() pattern in upstream rsync io.c:perform_io. The new module is wired through the live `io_uring` module and the non-Linux `io_uring_stub.rs` so callers can name the types unconditionally; `SharedRing::try_new` returns `None` on kernels < 5.6, when seccomp blocks the syscall, when the io_uring feature is off, or when the kernel does not report `IORING_OP_POLL_ADD` in its probe set, leaving the existing per-channel ring path and the standard buffered I/O path as the documented fallbacks. The audit at docs/audits/shared-iouring-session-instance.md is updated to mark step 4 of the rollout as shipped. Tests in crates/fast_io/tests/io_uring_shared_ring.rs cover tag round-trip on every platform, end-to-end read + poll-write + send concurrency on a single ring under Linux (skipped at runtime when io_uring is unavailable), interleaved demux of four reads with two polls, and confirmation that the per-channel `socket_writer_from_fd` fallback continues to function while the shared ring is in use.
Fixes fmt+clippy CI failure from the prior commit on this PR. No code behavior changes, formatting only.
`revents` is i16 and `libc::POLLOUT` is `c_short` (i16) on Linux, so the cast to i32 produced a `BitAnd<i16>` mismatch. Both sides are already i16; remove the cast.
…1874) clippy::useless_vec was triggered by `vec![false; N]` for fixed-size local trackers in `many_interleaved_ops_demux_independently`. Switch to `[false; N]` arrays so the test compiles under -D warnings.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
* feat(fast_io): merge reader+writer onto shared io_uring (#1874) Adds `SharedRing`, a single io_uring instance that services both a reader fd and a writer fd in the same session. Submits `IORING_OP_READ` against the registered reader fd and uses `IORING_OP_POLL_ADD` (POLLOUT) on the writer fd so a slow consumer never blocks the shared CQ; the follow-up `IORING_OP_SEND` is then queued only when the kernel signals readiness. Completions are demuxed in arrival order via a 64-bit `user_data` tag (`OpTag` in the high 8 bits, op_id in the low 56), mirroring the io_loop+select() pattern in upstream rsync io.c:perform_io. The new module is wired through the live `io_uring` module and the non-Linux `io_uring_stub.rs` so callers can name the types unconditionally; `SharedRing::try_new` returns `None` on kernels < 5.6, when seccomp blocks the syscall, when the io_uring feature is off, or when the kernel does not report `IORING_OP_POLL_ADD` in its probe set, leaving the existing per-channel ring path and the standard buffered I/O path as the documented fallbacks. The audit at docs/audits/shared-iouring-session-instance.md is updated to mark step 4 of the rollout as shipped. Tests in crates/fast_io/tests/io_uring_shared_ring.rs cover tag round-trip on every platform, end-to-end read + poll-write + send concurrency on a single ring under Linux (skipped at runtime when io_uring is unavailable), interleaved demux of four reads with two polls, and confirmation that the per-channel `socket_writer_from_fd` fallback continues to function while the shared ring is in use. * style(fast_io): apply cargo fmt to io_uring_shared_ring tests (#1874) Fixes fmt+clippy CI failure from the prior commit on this PR. No code behavior changes, formatting only. * fix(fast_io): drop unnecessary i32 cast in POLLOUT bitand (#1874) `revents` is i16 and `libc::POLLOUT` is `c_short` (i16) on Linux, so the cast to i32 produced a `BitAnd<i16>` mismatch. Both sides are already i16; remove the cast. * fix(fast_io): use array literal instead of vec! in test seen-tracker (#1874) clippy::useless_vec was triggered by `vec![false; N]` for fixed-size local trackers in `many_interleaved_ops_demux_independently`. Switch to `[false; N]` arrays so the test compiles under -D warnings.
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.
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
… (#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
… (#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.
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
Implements issue #1874: merge the per-channel reader and writer io_uring rings onto a single ring per session, using
IORING_OP_POLL_ADD(POLLOUT) for write-readiness so a slow consumer never blocks the shared CQ.Architecture
One
io_uringinstance perSharedRing, hosting both fds in its fixed-file table:IORING_OP_READagainst the registered reader fd (the registered-buffer fast path is reserved for higher-level batched submitters that own the buffer pool).IORING_OP_POLL_ADD(POLLOUT) on the writer fd, then queuesIORING_OP_SENDonce readiness fires.user_datatag, no per-op state lookups required:OpTagcarriesRead,Write,Send,PollWrite.reap()decodes each CQE into aSharedCompletionand returns the demuxed batch in arrival order. Mirrorsio.c:io_loop/io.c:perform_ioin upstream rsync, where one event loop drives both directions viaselect(2).Fallback chain
SharedRing::try_newreturnsNonewhenis_io_uring_available()is false (kernel < 5.6, seccomp block,io_uringfeature off) or when the kernel probe does not reportIORING_OP_POLL_ADD. Caller falls back to the existing per-channelIoUringReader/IoUringSocketWriterrings, then to standard buffered I/O.register_filesfails, both fds drop to raw-fd opcodes (matchingIoUringReader/IoUringSocketWriter); when buffer registration fails the registered-buffer pool is simply absent, so reads/writes use the unregistered opcodes.io_uring_stub.rsexposes the same public types (OpTag,SharedCompletion,SharedRing,SharedRingConfig) with all constructors returningNone/Unsupported, so cross-platform call sites compile withoutcfggates.Files
crates/fast_io/src/io_uring/shared_ring.rs(new):SharedRing,OpTag,SharedCompletion,SharedRingConfig. Hard-codesIORING_OP_POLL_ADD = 6for the probe call (the io-uring crate v0.7 does not expose aCODEconstant onopcode::PollAdd). Drop order keeps the kernel ring fd ahead ofRegisteredBufferGroup.crates/fast_io/src/io_uring/mod.rs,crates/fast_io/src/lib.rs: re-export the new types.crates/fast_io/src/io_uring_stub.rs: matching stubs for non-Linux / feature-off builds.crates/fast_io/tests/io_uring_shared_ring.rs(new): tag round-trip on every platform; Linux-only end-to-end read + poll-write + send on a single ring; four reads + two polls interleaved demux; per-channelsocket_writer_from_fdfallback continuity. All Linux tests skip at runtime whenis_io_uring_available()returnsfalse.docs/audits/shared-iouring-session-instance.md: marks step 4 of the rollout as shipped, pointing to the new files.Test plan
cargo nextest run -p fast_io --all-features -E 'test(ring) or test(io_uring)'(Linux CI)cargo nextest run -p fast_io -E 'test(op_tag)'(cross-platform CI for the tag arithmetic)cargo clippy --workspace --all-targets --all-features -- -D warnings