Skip to content

feat(uring): bound admission and harden read-driver progress - #16

Merged
houseme merged 22 commits into
mainfrom
houseme/uring-driver-hardening
Sep 22, 2026
Merged

houseme merged 22 commits into
mainfrom
houseme/uring-driver-hardening

Conversation

@houseme

@houseme houseme commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #15; advances steps 2, 3 and 4.1 of rustfs/backlog#2647.

  • Add optional logical-size and driver-wide in-flight read-buffer limits, with aligned allocation accounting and count/byte waiter closure.
  • Recover empty-SQ completion work; preserve O_DIRECT short-read error integrity and suppress repeated overflow warnings.
  • Bound intake, allocation and CQ work per turn; harden eventfd retries and avoid explicitly canceled continuations/orphan result copies.
  • Add opt-in capacity-aware positioned-read routing and bounded buffered batches sharing eager notifications per final owner.
  • Fix benchmark process-group cleanup after a wrapper exits before its child; reconcile contracts, changelog and acceptance status.

Follow-up verification and examples

Three additional commits (6927bb0, f135f1d, bfc2a5d) add explicit same-binary calibration, an example-only bounded ordered reader, and native CLI/CI gates. No production driver code, dependencies or defaults change in this follow-up.

  • Calibration checks each middle leg independently, retains the existing gates and never reports candidate attribution for control runs. 20 Python tests pass.
  • Ordered-prefetch state machine: 11 portable tests and independent review pass, including actual Tokio semaphore reservation order, out-of-order/EOF/error handling and cancellation-safe next calls. The example is not a production/S3/bitrot API.
  • Native CLI gate verifies bytes, EOF, drain and exact invalid-input errors; panic/timeout cannot count as successful rejection.
  • Current-main application dependency, fallback, budgets and direct-cache prerequisites are documented separately.

Shutdown API follow-up

Implementation/documentation head a942ac1 adds request_shutdown, advisory is_finished, and default-off tokio-runtime / eager shutdown_async (c7bb321, tests be66d8e). Every shutdown request closes count/byte admission before returning. The adapter transfers driver ownership at method call time, not first poll; dropping its returned future detaches waiting during normal runtime operation. Runtime teardown can still synchronously drop rejected work; no hard cleanup deadline or early kernel-buffer release is promised.

Two independent implementation/test/document reviews passed after correcting the zero-length admission wording. Local Linux-target default lib-only/all-target checks, all-feature Clippy, both feature-state warning-denying rustdoc, fmt and diff checks pass. The normal/build dependency graph confirms default Tokio sync-only support. Those local checks are compilation evidence. Subsequently, CI #55 at a942ac1 passed all three jobs: 127 native all-feature tests, mandatory O_DIRECT, ordered-prefetch and both benchmark smokes, Docker restricted/unrestricted legs, lint and 20 Python tests. Earlier documentation-only head 1dfd81b also passed CI #56. The PR remains draft and unmerged. See shutdown contract.

Shared whole-driver read quota follow-up

Head b09b966 adds SharedReadBudget and probe_and_start_with_shared_budget (source 3931124, public tests 7e94f36). Each driver reserves its explicit local byte quota before startup; temporary shortage returns WouldBlock, not an unsupported-environment classification. A shared receipt follows eager/deferred reads through Msg/Pending and leak retention, so one driver cannot refund capacity still owned by kernel-visible resources. Closing one driver leaves its peers' admission open. Idle drivers also retain their whole quota: this is not dynamic per-read borrowing, retained-result accounting, fallback coverage, or an RSS cap.

Two independent non-author reviews passed for code, seven private and nine public tests, and the reservation contract. Local Linux-target default/all-feature checks, all-feature Clippy, both rustdoc feature states with warnings denied, fmt/diff and the default sync-only dependency graph pass. The initial RED was missing-API compilation, not a behavioral test run. CI #57 at b09b966 passed all three jobs: 143 native all-feature tests plus one compiled no-run doc example, mandatory O_DIRECT, ordered-prefetch and both benchmark smokes, lint, and Docker restricted/unrestricted legs. All 16 shared-budget tests executed, including whole-quota leak retention and greater-than-u32 reservations. Follow-up e1992ce only records this evidence; its workflow remains separate. Later-shard startup rollback remains statically reviewed RAII behavior, not a new targeted fault-injection result. No RustFS dependency source or production application wiring is changed.

Safety and review

Published read buffers, FDs and permits remain owned until the terminal read CQE; cancel CQEs never release read resources. Bounded-drain leaks remain charged. Default routing stays round-robin; streams and without_cancel_on_drop retain their contracts. Byte limits are not a whole-process RSS or retained-result bound.

Independent component and integrated reviews covered ownership, cross-shard closure, admission, cancellation, final-owner routing, notification/unwind liveness, faults, test validity and documentation. The count-waiter closure gap and orphan-child cleanup issue found during review were fixed and regression-tested.

Validation

Code revision 7e2f1aa (the following commit only updates documentation/rustdoc comments):

  • Unrestricted Linux: 104 all-feature tests and 90 default-feature tests passed, no skips, mandatory positive O_DIRECT marker.
  • Native all-feature Clippy, fmt, 10 Python ABBA gate tests and instrumented eight-strategy benchmark correctness smoke passed.
  • Linux-target default/all-feature Clippy and warning-denying rustdoc passed locally.
  • Final diff/format checks passed.

Real-kernel overflow/direct tests are distinguished in the docs from simulated syscall-return and metadata-error seams. This is not proof of hung-syscall recovery or advanced taskrun modes.

Performance / remaining gates

No performance improvement is claimed. Three-round same-binary A/A calibration was rejected: round 3 p99 drift was 6.35%, above the unchanged 5% gate. Candidate and diagnostics-overhead comparisons were not started. The control used the foundation baseline, not the hardening candidate. No thresholds were relaxed.

Previous head bfc2a5d CI #54 passed: lint, 115 native all-feature tests, mandatory O_DIRECT marker, the new ordered-prefetch contract smoke, both benchmark smoke modes, and Docker restricted/unrestricted legs. Dedicated-host follow-up execution was refused by the active-worker/build guard; source artifacts were staged on its data disk without stopping the existing job. No performance rerun occurred. The PR remains draft with performance acceptance outstanding. Application probe offload, driver-thread budgets, logical chunks and exact FD invalidation are implemented in separate RustFS draft PRs #8072/#8074/#8075/#8076, with full checks/merge still outstanding. Application physical-byte/result/io-wq budgets, owned buffers/direct cache enablement, production streaming and advanced ring modes remain unimplemented/evidence-gated. The new ordered-reader example only establishes a tested consumer contract. See optimization status. This PR does not close the roadmap issue.

houseme and others added 22 commits September 23, 2026 01:03
Terminate the owned process group even when its leader was already reaped. Cover surviving descendants with FIFO EOF and preserve failures when the group no longer exists.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
…rors

Advance kernel overflow/task work even without new SQEs and retry remaining submission work after reaping. Return metadata errors rather than reporting an unconfirmed O_DIRECT tail as EOF.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Add opt-in shared byte admission with aligned allocation accounting, cancellation-safe permit ownership, and shutdown wakeup coverage.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Retry interrupted eventfd transfers and retain bounded wake diagnostics. Stop positioned continuation only after a read CQE confirms safe reclamation, preserving stream and no-cancel semantics.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Register shard count semaphores in shared admission state, synchronize registration with terminal close, and invoke semaphore wakeups outside the registry lock. Cover count-stage closure, late/concurrent registration, and partial FIFO byte cancellation.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Alternate bounded message, allocation, and completion batches while remembering pending local work after eventfd drains. Continue partial submissions only after positive progress to retain idle efficiency and avoid zero-progress retry spins.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Try actual count permits across healthy shards for positioned reads, retain round-robin by default and for streams, and keep the final owner fixed for waits and cancellation. Preserve shared-byte closure and account diagnostics only to the final shard.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Exercise a real pending pipe read with count-stage and byte-stage waiters under the dropped-CQE fault seam. Assert bounded bailout, retained Pending ownership, no waiter submission, and errors for all stranded handles.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
…rnings

Extract submit-result classification for deterministic progress, reset, shutdown and ownership checks without injecting real kernel failures. Warn only on changed nonzero CQ overflow counters and explicitly handle counter wrap.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
…ions

Reuse normal read validation, ownership and admission while emitting one eager wakeup per final owning shard. Deferred admissions and cancellation retain individual notifications. Add deterministic eventfd tests and native byte-exact/cancellation coverage.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Record native default and all-feature regression results and the rejected A/A calibration without attributing performance benefits. Keep later application and memory-pooling work explicitly pending.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Require identical artifacts and feature-off rows for opt-in A/A calibration. Gate each middle leg against the endpoint mean without candidate attribution while preserving comparison defaults.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Keep ordered prefetch example-local with bounded logical slots and bytes, cancellation-safe next polling, all-slot admission progress and ordered EOF/error termination. Add deterministic semaphore-race coverage and a read-only Linux byte oracle without production API changes or performance claims.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
…uisites

Require byte-exact native example execution and precise CLI validation errors. Record current-main application budget, fallback, probe and descriptor-cache integration boundaries separately from the completed driver work.

Co-Authored-By: heihutu <heihutu@gmail.com>
Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Exercise registered admission waiters, repeated shutdown requests, new-read rejection and clean conservation on real Linux pipes. Cover eager async shutdown abandonment and isolate the nonclean thread-exit fault in a child process without global environment mutation.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Close count and byte admission before every shutdown request returns, expose advisory thread completion, and reuse the request path for consuming shutdown and Drop. Add an opt-in tokio-runtime adapter that transfers driver ownership before its returned future is polled, with deterministic private lifecycle tests.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Validate strict quota geometry, refusal classification, independent shutdown, deferred-handle retention and clean recycling. Cover capacity-aware batch ownership and isolate permanent whole-quota retention after a leaked one-byte read in a fault child.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Reserve each explicit local byte limit before probing, reject transient shared shortage without waiting, and retain the whole reservation through deferred admission and accepted reads. Keep local shutdown independent and leaked pending buffers charged, with atomic accounting and deterministic ownership tests.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
@houseme

houseme commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T23:34:25.458524Z e1992ce Manual request
🔒 Security Review ✅ Completed 2026-09-22T23:39:32.496450Z e1992ce Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@houseme

houseme commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex security review

@houseme houseme self-assigned this Sep 22, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: e1992ce108

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The broad driver and API changes remain draft with performance acceptance outstanding, requiring final human review.

Review effort: Lite
Findings: None

What changed in this PR

This pull request hardens the Linux io_uring driver with bounded admission, shutdown and cancellation safety, recovery improvements, shared budgets, routing, batching, and ordered-prefetch validation.

Changes:

  • Adds read limits, shared quotas, shutdown APIs, capacity-aware routing, and batching.
  • Improves completion progress, direct-read integrity, cancellation, eventfd handling, and ownership.
  • Adds tests, documentation, benchmark tooling, examples, and CI coverage.
File Summary
tests/​shutdown.rs Shutdown API and lifecycle tests
tests/​shared_budget.rs Shared read-budget integration tests
tests/​shard_policy.rs Shard policy integration tests
tests/​ordered_prefetch.rs Ordered-prefetch tests
tests/​fault_injection.rs Fault-recovery tests
tests/​cancel.rs Cancellation behavior tests
tests/​admission.rs Admission-limit tests
src/​shard_policy_tests.rs Shard-selection unit tests
src/​lib.rs Public API exports and feature wiring
src/​driver.rs Core driver admission, progress, shutdown, routing, and batching
src/​driver_submit_result_tests.rs Submission-result tests
src/​driver_loop_budget_tests.rs Driver-loop budget tests
src/​driver_fault_recovery_tests.rs Driver fault-recovery tests
src/​diagnostics.rs Final-owner diagnostic sampling
src/​batch_read_tests.rs Batch-read tests
src/​admission_tests.rs Admission unit tests
scripts/​test-ordered-prefetch-cli.sh Ordered-prefetch CLI gate
scripts/​test_bench_abba.py Benchmark behavior tests
scripts/​bench-abba.py Benchmark calibration and cleanup
README.md Public API and behavior documentation
examples/​ordered_prefetch/​reader.rs Ordered-prefetch reader example
examples/​ordered_prefetch/​linux.rs Linux example support
examples/​ordered_prefetch.rs Ordered-prefetch example entry point
docs/​shutdown.md Shutdown contract
docs/​shared-read-budget.md Shared-budget contract
docs/​rustfs-integration.md RustFS integration guidance
docs/​ordered-prefetch.md Ordered-prefetch documentation
docs/​optimization-status.md Optimization and acceptance status
docs/​fault-recovery.md Fault-recovery documentation
docs/​driver-fairness.md Driver fairness documentation
docs/​cancellation-efficiency.md Cancellation-efficiency documentation
docs/​benchmarking.md Benchmarking guidance
docs/​batch-reads.md Batch-read documentation
CHANGELOG.md Release notes
Cargo.toml Optional Tokio runtime feature
.github/​workflows/​ci.yml Ordered-prefetch CI coverage

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@houseme
houseme marked this pull request as ready for review September 22, 2026 23:35
@houseme
houseme merged commit c92fc40 into main Sep 22, 2026
4 checks passed
@houseme
houseme deleted the houseme/uring-driver-hardening branch September 22, 2026 23:36
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e1992ce108

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants