Skip to content

Commit b06e10c

Browse files
tavianatorsamuel-williams-shopify
authored andcommitted
Try setting up io_uring with IORING_SETUP_SUBMIT_ALL
This decreases the likelihood of a short submit.
1 parent cc3b9ee commit b06e10c

1 file changed

Lines changed: 24 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

0 commit comments

Comments
 (0)