Skip to content

Commit c3f2a34

Browse files
tavianatorcursoragent
authored andcommitted
Try setting up io_uring with IORING_SETUP_SUBMIT_ALL
This decreases the likelihood of a short submit. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 426a88c commit c3f2a34

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

ext/io/event/selector/uring.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,23 @@ VALUE IO_Event_Selector_URing_initialize(VALUE self, VALUE loop) {
283283
#ifdef IORING_SETUP_TASKRUN_FLAG
284284
flags |= IORING_SETUP_TASKRUN_FLAG;
285285
#endif
286+
// IORING_SETUP_SUBMIT_ALL (kernel 5.18+): keep processing the rest of the SQE
287+
// batch even when one fails, reducing the frequency of short submits.
288+
#ifdef IORING_SETUP_SUBMIT_ALL
289+
flags |= IORING_SETUP_SUBMIT_ALL;
290+
#endif
286291

287292
int result = io_uring_queue_init(URING_ENTRIES, &selector->ring, flags);
288293

294+
#ifdef IORING_SETUP_SUBMIT_ALL
295+
if (result == -EINVAL) {
296+
// IORING_SETUP_SUBMIT_ALL was added in Linux 5.18; retry without it.
297+
if (DEBUG) fprintf(stderr, "IO_Event_Selector_URing_initialize: no IORING_SETUP_SUBMIT_ALL\n");
298+
flags &= ~IORING_SETUP_SUBMIT_ALL;
299+
result = io_uring_queue_init(URING_ENTRIES, &selector->ring, flags);
300+
}
301+
#endif
302+
289303
if (result < 0) {
290304
rb_syserr_fail(-result, "IO_Event_Selector_URing_initialize:io_uring_queue_init");
291305
}
@@ -1306,9 +1320,19 @@ static int IO_Event_Selector_URing_supported_p(void) {
13061320
#endif
13071321
#ifdef IORING_SETUP_TASKRUN_FLAG
13081322
flags |= IORING_SETUP_TASKRUN_FLAG;
1323+
#endif
1324+
#ifdef IORING_SETUP_SUBMIT_ALL
1325+
flags |= IORING_SETUP_SUBMIT_ALL;
13091326
#endif
13101327
int result = io_uring_queue_init(32, &ring, flags);
13111328

1329+
#ifdef IORING_SETUP_SUBMIT_ALL
1330+
if (result == -EINVAL) {
1331+
flags &= ~IORING_SETUP_SUBMIT_ALL;
1332+
result = io_uring_queue_init(32, &ring, flags);
1333+
}
1334+
#endif
1335+
13121336
if (result < 0) {
13131337
rb_warn("io_uring_queue_init() was available at compile time but failed at run time: %s\n", strerror(-result));
13141338

releases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Improve `WorkerPool` GC compaction support and add proper write barriers, fixing potential use-after-free under compacting GC.
88
- Keep blocked scheduler fibers alive during GC by registering them as roots in `TestScheduler#block`, preventing premature collection and the resulting use-after-free crash on resume.
99
- Correctly handle short `io_uring_submit()` results in the `URing` selector. `io_uring_submit()` returns the number of SQEs actually accepted by the kernel and can be short (SQE prep errors, `ENOMEM`, transient `EAGAIN`); the old accounting reset `pending = 0` on any success and silently lost track of unsubmitted SQEs.
10+
- Enable `IORING_SETUP_SUBMIT_ALL` (kernel 5.18+) on the `URing` selector so the kernel keeps processing the rest of an SQE batch past individual errors, reducing the frequency of short submits in practice.
1011

1112
## v1.15.1
1213

0 commit comments

Comments
 (0)