Skip to content

Commit

Permalink
reactor: io_uring: enable some optimization flags
Browse files Browse the repository at this point in the history
Enable some optimization flags in an attempt to improve performance
with io_uring:

IORING_SETUP_COOP_TASKRUN - prevents a completion from interrupting the
reactor if it is running. Requires that the reactor issue an io_uring_enter
system call in a timely fashion, but thanks to the task quota timer, we do.

IORING_SETUP_TASKRUN_FLAG - sets up a flag that notifies the reactor
that the kernel has pending completions that it did not process. This
allows the reactor to issue an io_uring_enter even if it has no pending
submission queue entries or completion queue entries (e.g. it indicates
a third queue, in the kernel, is not empty).

IORING_SETUP_SINGLE_ISSUER - elides some locking by guaranteeing that only
a single thread plays with the ring; this happens to be true for us.

IORING_SETUP_DEFER_TASKRUN - batches up completion processing in an
attempt to get some more performance.

This flags bump up the dependencies to Linux 6.1 and liburing 2.2. This
seems worthwhile as right now io-uring lags behind linux-aio (which processes
completions from interrupt context and therefore doesn't need all these
optimizations). However, I don't know how to specify the liburing
version requirement.

After this exercise, io_uring is still slower than linux-aio.
  • Loading branch information
avikivity committed Feb 9, 2024
1 parent d438167 commit 5c03ccc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/reactor_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1213,13 +1213,21 @@ try_create_uring(unsigned queue_len, bool throw_on_error) {
IORING_OP_SEND,
IORING_OP_RECV,
};
auto required_flags =
IORING_SETUP_COOP_TASKRUN // linux 5.19; required for performance
| IORING_SETUP_TASKRUN_FLAG // linux 5.19; avoids a syscall if no event is ready
| IORING_SETUP_SINGLE_ISSUER // linux 6.0; helps with performance
| IORING_SETUP_DEFER_TASKRUN // linux 6.1; avoids context switches
;
auto maybe_throw = [&] (auto exception) {
if (throw_on_error) {
throw exception;
}
};

auto params = ::io_uring_params{};
auto params = ::io_uring_params{
.flags = required_flags,
};
::io_uring ring;
auto err = ::io_uring_queue_init_params(queue_len, &ring, &params);
if (err != 0) {
Expand Down

0 comments on commit 5c03ccc

Please sign in to comment.