Repository navigation
fix(bench): hoist io_uring writer to prevent MEMLOCK exhaustion - #3576
Merged
Merged
Conversation
The io_uring write benchmark allocated a fresh ring inside `b.iter()` via `IoUringWriter::create`, which on CI runners exhausts RLIMIT_MEMLOCK (each ring + registered buffers locks ~512 KB). When the writer bench runs immediately after the reader bench, the kernel has not yet reclaimed the reader's MEMLOCK pages, and the very first writer iteration panics with `ENOMEM` from `io_uring_setup()`. Hoist `IoUringWriter::create` outside `b.iter()` and reuse the ring across iterations via `writer.write_all_batched(data, 0)`. This public method takes an explicit offset and bypasses the internal write cursor, so writing to offset 0 every iteration overwrites the file in place rather than growing it -- so cross-iter reuse is safe. Same pattern as PR #3575 used for the reader. Removes the defensive `sample_size`/`warm_up_time`/`measurement_time` bounds from PR #3575 since they are no longer needed: with one ring per sub-benchmark we are now within RLIMIT_MEMLOCK regardless of iter count. Unblocks the Criterion Benchmarks workflow on the v0.6.1 release.
2 tasks
oferchen
added a commit
that referenced
this pull request
May 5, 2026
The io_uring write benchmark allocated a fresh ring inside `b.iter()` via `IoUringWriter::create`, which on CI runners exhausts RLIMIT_MEMLOCK (each ring + registered buffers locks ~512 KB). When the writer bench runs immediately after the reader bench, the kernel has not yet reclaimed the reader's MEMLOCK pages, and the very first writer iteration panics with `ENOMEM` from `io_uring_setup()`. Hoist `IoUringWriter::create` outside `b.iter()` and reuse the ring across iterations via `writer.write_all_batched(data, 0)`. This public method takes an explicit offset and bypasses the internal write cursor, so writing to offset 0 every iteration overwrites the file in place rather than growing it -- so cross-iter reuse is safe. Same pattern as PR #3575 used for the reader. Removes the defensive `sample_size`/`warm_up_time`/`measurement_time` bounds from PR #3575 since they are no longer needed: with one ring per sub-benchmark we are now within RLIMIT_MEMLOCK regardless of iter count. Unblocks the Criterion Benchmarks workflow on the v0.6.1 release.
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
The io_uring write benchmark allocated a fresh ring inside
b.iter()viaIoUringWriter::create, which on CI runners exhaustsRLIMIT_MEMLOCK(each ring + registered buffers locks ~512 KB). When the writer bench runs immediately after the reader bench, the kernel has not yet reclaimed the reader's MEMLOCK pages, and the very first writer iteration panics withENOMEMfromio_uring_setup():(See run 25279998712 -- failed at the FIRST iter of
io_uring_writes/io_uring/64kbwarm-up, 14ms in.)Fix
Hoist
IoUringWriter::createoutsideb.iter()and reuse the ring across iterations viawriter.write_all_batched(data, 0). This public method takes an explicit offset and bypasses the internal write cursor, so writing to offset 0 every iteration overwrites the file in place rather than growing it -- cross-iter reuse is safe.Same pattern as PR #3575 used for the reader.
Why the defensive bounds from PR #3575 are gone
PR #3575 added
sample_size(10)/warm_up_time(500ms)/measurement_time(2s)because it (correctly) believed cross-iter writer reuse would grow the file unboundedly. That was true only for the bufferedWrite::write_all+flushpath which uses the internalbytes_writtencursor as the next-write offset.write_all_batched(&mut self, data: &[u8], offset: u64)takes an explicit offset and never touchesbytes_written-- so we can reuse the writer across iterations withoffset=0and the file is overwritten in place. This invalidates the "cross-iter reuse would grow the file" concern, so the defensive bounds are no longer needed.Test plan
cargo bench --workspaceon ubuntu-24.04 (will be exercised by theBenchmarkandCriterion Benchmarksworkflows)Criterion Benchmarksagainstv0.6.1viagh workflow run "Criterion Benchmarks" --ref master -f target_tag=v0.6.1criterion_output.txtasset