From e453f369ecf4db4913ef6916603037f2d7141035 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 31 Aug 2022 14:14:29 -0600 Subject: [PATCH] engines/io_uring: set single issuer and defer taskrun If available, set these two flags as well. SINGLE_ISSUER tells the kernel that it can expect that it's just a single task issuing requests, and DEFER_TASKRUN tells the kernel that we're fine with deferring task_work runs until we reap events. Signed-off-by: Jens Axboe --- engines/io_uring.c | 11 +++++++++++ os/linux/io_uring.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/engines/io_uring.c b/engines/io_uring.c index a51468f5..d0fc61dc 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -815,9 +815,20 @@ static int fio_ioring_queue_init(struct thread_data *td) */ p.flags |= IORING_SETUP_COOP_TASKRUN; + /* + * io_uring is always a single issuer, and we can defer task_work + * runs until we reap events. + */ + p.flags |= IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN; + retry: ret = syscall(__NR_io_uring_setup, depth, &p); if (ret < 0) { + if (errno == EINVAL && p.flags & IORING_SETUP_DEFER_TASKRUN) { + p.flags &= ~IORING_SETUP_DEFER_TASKRUN; + p.flags &= ~IORING_SETUP_SINGLE_ISSUER; + goto retry; + } if (errno == EINVAL && p.flags & IORING_SETUP_COOP_TASKRUN) { p.flags &= ~IORING_SETUP_COOP_TASKRUN; goto retry; diff --git a/os/linux/io_uring.h b/os/linux/io_uring.h index 929997f8..6604e736 100644 --- a/os/linux/io_uring.h +++ b/os/linux/io_uring.h @@ -131,6 +131,18 @@ enum { #define IORING_SETUP_SQE128 (1U << 10) /* SQEs are 128 byte */ #define IORING_SETUP_CQE32 (1U << 11) /* CQEs are 32 byte */ +/* + * Only one task is allowed to submit requests + */ +#define IORING_SETUP_SINGLE_ISSUER (1U << 12) + +/* + * Defer running task work to get events. + * Rather than running bits of task work whenever the task transitions + * try to do it just before it is needed. + */ +#define IORING_SETUP_DEFER_TASKRUN (1U << 13) + enum { IORING_OP_NOP, IORING_OP_READV, -- 2.25.1