Repository navigation
perf(fast_io): write small batches positionally instead of through io_uring - #7610
Merged
Merged
Conversation
…_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
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.
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.
The defect
submit_write_batchpushes a batch of write SQEs, blocks insubmit_and_waituntil 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 inflight 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 SQEconstruction, 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_enterround trip that buys nothing.The doc comment on
IoUringWriterclaimed "sq_entriesconcurrent writes persubmit_and_waitcall". That is true within a batch, but the batch is drainedbefore 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=0andfiles=10000. Load average was falling across the run (1.64 -> 1.08), so thefast arms are not flattered by a quieting host.
OC_RSYNC_DISABLE_IOURING=1io_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_CHUNKSgoes towrite_all_positional, whichkeeps the ring path's contract byte for byte: same offsets, same short-write
resubmission, same
WriteZeroon a zero-length accept, andEINTRretriedrather than surfaced (a completed
IORING_OP_WRITEcarries the byte count, notthe signal). Batches at or above the threshold keep the ring, since no
measurement says they are worse there.
submit_write_batchnow takes&Filerather than a baretypes::Fdso it canreach
FileExt::write_at. The SQE fd is derived inside from the same handle, soregistered-file behaviour is unchanged and no
unsafeis 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
md5sumover every file compared source vs destination - identical(
9a00464040860872dd272a575bcb9a7dboth sides). A file count alone would nothave caught corruption on a write-path change.
MIN_RING_BATCH_CHUNKSback to1reddenssmall_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_atstill issues a single blocking SQE. It is the sameshape, 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.