Skip to content

feat(fast_io): merge reader+writer onto shared io_uring (#1874) - #3553

Merged
oferchen merged 7 commits into
masterfrom
feat/io-uring-shared-ring-1874
May 2, 2026
Merged

oferchen merged 7 commits into
masterfrom
feat/io-uring-shared-ring-1874

Conversation

@oferchen

@oferchen oferchen commented May 2, 2026

Copy link
Copy Markdown
Owner

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_uring instance per SharedRing, hosting both fds in its fixed-file table:

  • Reader path submits IORING_OP_READ against the registered reader fd (the registered-buffer fast path is reserved for higher-level batched submitters that own the buffer pool).
  • Writer path submits IORING_OP_POLL_ADD (POLLOUT) on the writer fd, then queues IORING_OP_SEND once readiness fires.
  • Completions are demuxed by a 64-bit user_data tag, no per-op state lookups required:
 63        56 55             0
 +-----------+----------------+
 |  OpTag    |   op_id (56b)  |
 +-----------+----------------+

OpTag carries Read, Write, Send, PollWrite. reap() decodes each CQE into a SharedCompletion and returns the demuxed batch in arrival order. Mirrors io.c:io_loop / io.c:perform_io in upstream rsync, where one event loop drives both directions via select(2).

Fallback chain

  • SharedRing::try_new returns None when is_io_uring_available() is false (kernel < 5.6, seccomp block, io_uring feature off) or when the kernel probe does not report IORING_OP_POLL_ADD. Caller falls back to the existing per-channel IoUringReader / IoUringSocketWriter rings, then to standard buffered I/O.
  • Per-op fallback: when register_files fails, both fds drop to raw-fd opcodes (matching IoUringReader/IoUringSocketWriter); when buffer registration fails the registered-buffer pool is simply absent, so reads/writes use the unregistered opcodes.
  • Non-Linux: io_uring_stub.rs exposes the same public types (OpTag, SharedCompletion, SharedRing, SharedRingConfig) with all constructors returning None/Unsupported, so cross-platform call sites compile without cfg gates.

Files

  • crates/fast_io/src/io_uring/shared_ring.rs (new): SharedRing, OpTag, SharedCompletion, SharedRingConfig. Hard-codes IORING_OP_POLL_ADD = 6 for the probe call (the io-uring crate v0.7 does not expose a CODE constant on opcode::PollAdd). Drop order keeps the kernel ring fd ahead of RegisteredBufferGroup.
  • 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-channel socket_writer_from_fd fallback continuity. All Linux tests skip at runtime when is_io_uring_available() returns false.
  • 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)
  • CI on macOS / Windows confirms the stub path compiles
  • cargo clippy --workspace --all-targets --all-features -- -D warnings

oferchen added 2 commits May 2, 2026 07:03
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.
@github-actions github-actions Bot added the enhancement New feature or request label May 2, 2026
oferchen added 5 commits May 2, 2026 07:28
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
oferchen merged commit a4aaef1 into master May 2, 2026
43 checks passed
@oferchen
oferchen deleted the feat/io-uring-shared-ring-1874 branch May 2, 2026 13:01
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.
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.
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