Repository navigation
Conversation
With DEFER_TASKRUN a linked close is deferred task work once its cancel completes. io_uring_submit() enters without GETEVENTS, so the ring's exit cancelled the closes prepared by a Wait() that threw and leaked the descriptors. The destructor now enters with GETEVENTS and runs the rest of the deferred work with the same helper as Wait().
With PR 187 only descriptors with operations get the linked close, so the test left two deferred items and passed without the drain in Wait(). With a read on each of 40 handles and a 256-entry queue the cancelled reads and the closes are more than one wait runs; the test fails if Wait() does not drain.
…test a wait with a timeout
…G_SQ_TASKRUN can be stale
This was referenced Nov 16, 2026
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.
Experiment 2 of the TUring write-path series (draft, for measurement; the owner decides).
This is #188 with #191 stacked on it, rebased onto master 85489f0. #188 was closed on 2026-11-06 ("not merging") for these reasons:
R_DISABLED;The owner asked to remeasure it with user/kernel cycles per hop, alone and together with the direct write (experiment 3), and to chase the hangs.
Change (as in #188 + #191)
SINGLE_ISSUER | DEFER_TASKRUN | TASKRUN_FLAG | R_DISABLED.io_uring_enterwith GETEVENTS, whichWait()makes anyway.Wait()and the destructor drain the deferred work whileIORING_SQ_TASKRUNis set.New in this PR:
RunTaskWork()stops whenio_uring_get_events()posted no completion.COOP_TASKRUN | TASKRUN_FLAG(5.19), and then to plain task work. There is no thread binding in either fallback.test_uring_wait_timeout_with_deferred_completion: a wait with a timeout returns 0 at the timeout, and returns 1 early when a write in another thread completes a pending read, whose task work is deferred to the wait.Tests
testsbinary passes excepttest_uring_destroyed_after_failed_wait, which expects SINGLE_ISSUER's EEXIST in another thread.IORING_SETUP_SQ_AFFinstead fails late, after the ring memory is charged. On rpi5 (RLIMIT_MEMLOCK 8 MiB) that runs out of locked memory after ~30 rings while the freed rings wait for their exit work. A real old kernel rejects unknown flags before it allocates anything, so this is not a problem of the fallback.The actor-bench hang
On rpi5, Linux 7.3, the local actor bench (4 nodes, inflight 1024, 10M messages) hung in about 1 of 9 runs: 5 hangs in ~45 runs, Release and RelWithDebInfo. Each hang looked the same:
Wait(), inRunTaskWork()→io_uring_get_events(). The other nodes sleep inio_cqring_wait.sq_flags == IORING_SQ_TASKRUNand an empty CQ.perf staton the spinning process over 1 s: ~3.06Mio_uring_entercalls, 0io_uring:io_uring_local_work_runand 0io_uring:io_uring_task_add. So no deferred work is pending, but the flag is set.ssshows ~16 KB unread on one of its inbound sockets:InboundConnectionwaits inco_await Poller->Yield(), and timers never run becauseWait()never returns. The other nodes wait for its messages.Cause:
IORING_SQ_TASKRUNis a hint.io_req_local_work_add()(Linux 7.3,io_uring/tw.c) sets it after the request is already queued, so the owner thread can run that work, and clear the flag at the start of__io_run_local_work(), before the producer sets it.io_cqring_wait()starts one only when the queue is not empty.while (RunTaskWork()), also in the destructor) treated the flag as exact and spun forever.Fix: a drain step counts only if
io_uring_get_events()moved the CQ tail. Otherwise the drain stops and the nextWait()runs what is left.test_uring_wait_with_stale_taskrun_flagsets the flag by hand, through a second mapping of the ring, while nothing is pending.Wait({0, 0})must return at once. With the oldRunTaskWork()it spins until an alarm clears the flag 3 s later, and the test fails.After the fix: 40 of 40 runs completed, 0 hangs.
A/B (rpi5)
rpi5 (Cortex-A76, Linux 7.3.0-1003-raspi, liburing 2.15, GCC 15.3), Release,
examples/benchontaskset -c 3, run withrun_ab.sh. The configs alternate in each repetition. Values are the median (min-max) of 7 repetitions for single N=1024 and of 5 for N=16 and chain100 (-n 1024 -a 100). Cycles/hop = cycles:u + cycles:k of-w 100000minus-w 100, divided by 25 * 99900 hops. µs/hop = p50 of a run / 100001.Run 1 (head bdc1ebf, before the stale-flag fix, which does not touch the hot path); run 2 with the final head is below.
Run 2: master 85489f0, #214 608f9e8 (deferred task work), #215 51879eb (fixed files), #214 + #215 dbf3d2b, #214 + #213 eebf0d1 (direct write). Same method; heads alternate in each repetition.
Local actor bench (
ping_actors, 4 nodes, inflight 1024, 10M messages, 5 repetitions, timeout 60 s per run), msg/s, median (min-max), no hangs:The actor bench does not tell the heads apart: they are all within each other's spread.
Run 2 for this PR: 0.933 / 0.903 / 0.983 of master, the same as run 1.
Checks
test_uring*22/22.