Skip to content

Commit 8a79656

Browse files
anarazelaxboe
authored andcommitted
io_uring: Use io_schedule* in cqring wait
I observed poor performance of io_uring compared to synchronous IO. That turns out to be caused by deeper CPU idle states entered with io_uring, due to io_uring using plain schedule(), whereas synchronous IO uses io_schedule(). The losses due to this are substantial. On my cascade lake workstation, t/io_uring from the fio repository e.g. yields regressions between 20% and 40% with the following command: ./t/io_uring -r 5 -X0 -d 1 -s 1 -c 1 -p 0 -S$use_sync -R 0 /mnt/t2/fio/write.0.0 This is repeatable with different filesystems, using raw block devices and using different block devices. Use io_schedule_prepare() / io_schedule_finish() in io_cqring_wait_schedule() to address the difference. After that using io_uring is on par or surpassing synchronous IO (using registered files etc makes it reliably win, but arguably is a less fair comparison). There are other calls to schedule() in io_uring/, but none immediately jump out to be similarly situated, so I did not touch them. Similarly, it's possible that mutex_lock_io() should be used, but it's not clear if there are cases where that matters. Cc: stable@vger.kernel.org # 5.10+ Cc: Pavel Begunkov <asml.silence@gmail.com> Cc: io-uring@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Andres Freund <andres@anarazel.de> Link: https://lore.kernel.org/r/20230707162007.194068-1-andres@anarazel.de [axboe: minor style fixup] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent dfbe556 commit 8a79656

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

io_uring/io_uring.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,8 @@ int io_run_task_work_sig(struct io_ring_ctx *ctx)
24892489
static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24902490
struct io_wait_queue *iowq)
24912491
{
2492+
int token, ret;
2493+
24922494
if (unlikely(READ_ONCE(ctx->check_cq)))
24932495
return 1;
24942496
if (unlikely(!llist_empty(&ctx->work_llist)))
@@ -2499,11 +2501,20 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
24992501
return -EINTR;
25002502
if (unlikely(io_should_wake(iowq)))
25012503
return 0;
2504+
2505+
/*
2506+
* Use io_schedule_prepare/finish, so cpufreq can take into account
2507+
* that the task is waiting for IO - turns out to be important for low
2508+
* QD IO.
2509+
*/
2510+
token = io_schedule_prepare();
2511+
ret = 0;
25022512
if (iowq->timeout == KTIME_MAX)
25032513
schedule();
25042514
else if (!schedule_hrtimeout(&iowq->timeout, HRTIMER_MODE_ABS))
2505-
return -ETIME;
2506-
return 0;
2515+
ret = -ETIME;
2516+
io_schedule_finish(token);
2517+
return ret;
25072518
}
25082519

25092520
/*

0 commit comments

Comments
 (0)