Skip to content

perf(fast_io): write small batches positionally instead of through io_uring - #7610

Merged
oferchen merged 1 commit into
masterfrom
perf/io-uring-small-write-bypass
Sep 1, 2026
Merged

oferchen merged 1 commit into
masterfrom
perf/io-uring-small-write-bypass

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

The defect

submit_write_batch pushes a batch of write SQEs, blocks in submit_and_wait
until every one has completed, then drains the completion queue before building
the next batch (crates/fast_io/src/io_uring/batching.rs). Nothing is ever in
flight across batches, so the only concurrency io_uring can add is within one
batch - and a batch of a single chunk has none. For such a batch the ring
performs exactly the blocking wait a pwrite(2) would have done, plus SQE
construction, a ring transition, a CQE drain and per-slot bookkeeping.

A receiver pulling many small files hits that case on every file: the whole file
fits the writer's buffer, so each flush is a one-chunk batch and each file costs
one io_uring_enter round trip that buys nothing.

The doc comment on IoUringWriter claimed "sq_entries concurrent writes per
submit_and_wait call". That is true within a batch, but the batch is drained
before the next is built, so it overstated what the layer delivers. Corrected in
the same commit.

Measurement

10,000 files / 313 MB over a loopback rsync:// daemon pull; aarch64, 4 cores,
kernel 7.0.0. Three iterations, arms interleaved, every row rc=0 and
files=10000. Load average was falling across the run (1.64 -> 1.08), so the
fast arms are not flattered by a quieting host.

arm 1 2 3 mean
upstream rsync 3.5.0 1145 937 946 ~941 ms
oc before, io_uring ON 1110 1110 1099 1106 ms
oc after, io_uring ON 443 441 465 450 ms
oc before, OC_RSYNC_DISABLE_IOURING=1 444 451 484 460 ms

io_uring cost 2.47x on this workload. After the change the io_uring-ON arm
sits on the disabled-path floor, and oc is 2.1x faster than upstream.

The change

A batch below MIN_RING_BATCH_CHUNKS goes to write_all_positional, which
keeps the ring path's contract byte for byte: same offsets, same short-write
resubmission, same WriteZero on a zero-length accept, and EINTR retried
rather than surfaced (a completed IORING_OP_WRITE carries the byte count, not
the signal). Batches at or above the threshold keep the ring, since no
measurement says they are worse there.

submit_write_batch now takes &File rather than a bare types::Fd so it can
reach FileExt::write_at. The SQE fd is derived inside from the same handle, so
registered-file behaviour is unchanged and no unsafe is added.

The threshold is measured, not guessed. On this workload the receiver issues
10,600 write batches, and the count reaching the ring falls 10,600 -> 1,600 ->
800 -> 0 as the constant goes 1 -> 2 -> 4 -> 8; wall clock tracks it (~4.8x the
floor at 1, ~1.6x at 2, on the floor at 8). No batch on this workload is 8
chunks or larger, and the doc comment says so explicitly rather than implying
the value is bounded from above by evidence.

Verification

  • Data correctness: full 10,000-file / 313 MB pull through the new path,
    md5sum over every file compared source vs destination - identical
    (9a00464040860872dd272a575bcb9a7d both sides). A file count alone would not
    have caught corruption on a write-path change.
  • Non-vacuity: setting MIN_RING_BATCH_CHUNKS back to 1 reddens
    small_batches_bypass_the_ring_and_large_ones_do_not
    (assertion failed: batch_bypasses_ring(1024, chunk, sq)).
  • cargo fmt --all -- --check - clean.
  • cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings - clean.
  • cargo nextest run --locked -p fast_io --all-features --no-fail-fast - 1168 run, 1168 passed, 1 skipped.

Deliberately unchanged

IoUringWriter::write_at still issues a single blocking SQE. It is the same
shape, but it has no production caller on the io_uring path (only its own
definition and tests), so routing it would be a change without a workload.

…_uring

`submit_write_batch` pushes a batch of write SQEs, blocks in
`submit_and_wait` until every one has completed, then drains the
completion queue before building the next batch. Nothing is ever in
flight across batches, so the only concurrency io_uring can add is
within a single batch -- and a batch of one chunk has none. For such a
batch the ring performs exactly the blocking wait a `pwrite(2)` would
have done, plus SQE construction, a ring transition, a CQE drain and
per-slot bookkeeping.

A receiver pulling many small files hits that case on every file: the
whole file fits the writer's buffer, so each flush is a one-chunk
batch and each file costs one `io_uring_enter` round trip that buys
nothing. Measured on a 10,000-file / 313 MB loopback daemon pull
(aarch64, 4 cores), the receiver issues 10,600 write batches and none
of them reaches 8 chunks.

Route a batch below `MIN_RING_BATCH_CHUNKS` to `write_all_positional`,
which keeps the ring path's contract byte for byte: same offsets, same
short-write resubmission, same `WriteZero` on a zero-length accept.
Batches at or above the threshold keep the ring, since no measurement
says they are worse there.

`submit_write_batch` now takes `&File` rather than a bare `types::Fd`
so it can reach `FileExt::write_at`; the SQE fd is derived inside from
the same handle, so registered-file behaviour is unchanged.
@oferchen
oferchen merged commit 7efdcc6 into master Sep 1, 2026
72 checks passed
@oferchen
oferchen deleted the perf/io-uring-small-write-bypass branch September 1, 2026 21:18
oferchen added a commit that referenced this pull request Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60
most recently merged pull requests, 44 were absent; of the most recent 45,
43 were absent. Nothing from #7574 onward was recorded at all.

Each entry is derived from what the pull request actually landed - the merge
commit and the body - not from its title. Three cases where those differ:

  * #7616 ships far more than the doc-alias correction its body describes:
    the `upstream_version` pin moves to 3.5.0 and `--version` starts naming
    `quic`, `sd-notify`, `vmsplice` and `send_zc`.
  * #7618 also adds the pull-request rustdoc-link job its body says was
    filed separately, which is what closes the master-only-gate recurrence.
  * #7602's squash carries the closed #7597 as its first commit, so the
    directory-obstacle half is recorded under #7602.

#7587 is deliberately not recorded. Its merge commit is empty: the change
had already landed as #7563, which the section already names.

Entries extend the existing Keep a Changelog groups and the bold
sub-groupings. Clusters that are one story carry one entry with several
references: the FERROR_XFER routing and its two-phase drain (#7576, #7581),
the connection-FSM close edge and the accept loop that outlives a session
error (#7579, #7590), the three detaching daemon suites (#7578, #7588,
#7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation
retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615,
#7620).

Only `## [Unreleased]` is touched; every released section, including the
3.4.4 statements that were correct when written, is byte-identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant