Repository navigation
io_uring: replace getSqe with hybrid deferred-submission model - #409
Conversation
When the submission queue is full, instead of polling recursively (which could deadlock if rearmWaker also needs an SQE), completions are now queued in a pending list and retried after io_uring_enter2 empties the SQ. rearmWaker is called before drainPending so the waker always gets the first available SQE slot. If the waker couldn't be armed, the blocking timeout is capped to 10ms to avoid stalling indefinitely. EINTR completions also go through the pending list so the waker retains priority. Adds a test that submits 6x the queue size of pipe_close operations in a single Group to exercise the deferred pending list.
|
Warning Review limit reached
More reviews will be available in 17 minutes and 14 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe io_uring backend defers SQE allocation failures into a new Changesio_uring SQE Deferral Strategy
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/ev/backends/io_uring.zig (2)
717-730:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftDon't drop cancel requests when the SQ is saturated.
If
get_sqe()fails here, a.runningop that is already in the kernel never gets another cancel attempt. Therequestedbit only gets consumed indrainPending()for deferred submissions, so an in-flight request can now ignore cancellation until it completes on its own. Please either queue failed cancels for retry frompoll()or reserve an SQE for cancel/waker traffic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ev/backends/io_uring.zig` around lines 717 - 730, When get_sqe() fails in the .running cancel path, do not drop the cancel: either enqueue the cancel for retry and have poll() attempt it again (add a pending_cancel queue entry containing the target user_data and ensure drainPending() or poll() will re-attempt submission), or implement a reserved SQE/waker slot used solely for cancel/USER_DATA_CANCEL traffic so cancel submissions never fail due to SQ saturation; update the .running cancel branch to push failed cancels into the pending structure and adjust drainPending()/poll() to consume and retry those pending cancels until submitted.
757-765:⚠️ Potential issue | 🟠 Major | ⚡ Quick winCap the fallback timeout instead of overwriting shorter deadlines.
When
waker_needs_rearmis true, this turns any shorter timeout into 10 ms, includingtimeout == 0. That makes a nonblocking poll sleep and can delay timer processing. Usemin(timeout, 10ms)here.🛠️ Proposed fix
- const effective_timeout = if (self.waker_needs_rearm) - Duration.fromMilliseconds(10) - else - timeout; + const fallback_timeout = Duration.fromMilliseconds(10); + const effective_timeout = if (self.waker_needs_rearm and timeout.value > fallback_timeout.value) + fallback_timeout + else + timeout;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ev/backends/io_uring.zig` around lines 757 - 765, The current logic unconditionally replaces timeout with 10ms when self.waker_needs_rearm, which turns shorter deadlines (including timeout == 0) into a blocking 10ms sleep; change the calculation of effective_timeout in io_uring.zig so it caps the timeout to 10ms instead of overwriting it — compute effective_timeout = if (self.waker_needs_rearm) min(timeout, Duration.fromMilliseconds(10)) else timeout, referencing the existing symbols effective_timeout, self.waker_needs_rearm, Duration.fromMilliseconds, and timeout and ensuring non-blocking polls (timeout == 0) remain zero.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/ev/backends/io_uring.zig`:
- Around line 717-730: When get_sqe() fails in the .running cancel path, do not
drop the cancel: either enqueue the cancel for retry and have poll() attempt it
again (add a pending_cancel queue entry containing the target user_data and
ensure drainPending() or poll() will re-attempt submission), or implement a
reserved SQE/waker slot used solely for cancel/USER_DATA_CANCEL traffic so
cancel submissions never fail due to SQ saturation; update the .running cancel
branch to push failed cancels into the pending structure and adjust
drainPending()/poll() to consume and retry those pending cancels until
submitted.
- Around line 757-765: The current logic unconditionally replaces timeout with
10ms when self.waker_needs_rearm, which turns shorter deadlines (including
timeout == 0) into a blocking 10ms sleep; change the calculation of
effective_timeout in io_uring.zig so it caps the timeout to 10ms instead of
overwriting it — compute effective_timeout = if (self.waker_needs_rearm)
min(timeout, Duration.fromMilliseconds(10)) else timeout, referencing the
existing symbols effective_timeout, self.waker_needs_rearm,
Duration.fromMilliseconds, and timeout and ensuring non-blocking polls (timeout
== 0) remain zero.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6279510c-3199-4bf9-8531-4fc4bab99698
📒 Files selected for processing (1)
src/ev/backends/io_uring.zig
Summary
pendinglist and retried afterio_uring_enter2empties the SQ, replacing the old approach of polling recursively (which could deadlock whenrearmWakeralso needed an SQE)rearmWakerruns beforedrainPendingso the waker always claims the first available SQE slot after the ring drainspendingrather than resubmitted directly, preserving waker priorityTest plan
./check.shpasses (442/446, 4 pre-existing failures in file stat/setLength and childWait)group: large batch exceeding queue size exercises deferred pending listsubmits 96pipe_closeops (6× queue size of 16) in a singleGroupand confirms all complete successfullyFixes #354