Skip to content

Commit f32dfc8

Browse files
anarazelgregkh
authored andcommitted
io_uring: Use io_schedule* in cqring wait
Commit 8a79656 upstream. 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: [email protected] # 5.10+ Cc: Pavel Begunkov <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Andres Freund <[email protected]> Link: https://lore.kernel.org/r/[email protected] [axboe: minor style fixup] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c55b552 commit f32dfc8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

io_uring/io_uring.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
23462346
struct io_wait_queue *iowq,
23472347
ktime_t *timeout)
23482348
{
2349-
int ret;
2349+
int token, ret;
23502350
unsigned long check_cq;
23512351

23522352
/* make sure we run task_work before checking for signals */
@@ -2362,9 +2362,18 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
23622362
if (check_cq & BIT(IO_CHECK_CQ_DROPPED_BIT))
23632363
return -EBADR;
23642364
}
2365+
2366+
/*
2367+
* Use io_schedule_prepare/finish, so cpufreq can take into account
2368+
* that the task is waiting for IO - turns out to be important for low
2369+
* QD IO.
2370+
*/
2371+
token = io_schedule_prepare();
2372+
ret = 1;
23652373
if (!schedule_hrtimeout(timeout, HRTIMER_MODE_ABS))
2366-
return -ETIME;
2367-
return 1;
2374+
ret = -ETIME;
2375+
io_schedule_finish(token);
2376+
return ret;
23682377
}
23692378

23702379
/*

0 commit comments

Comments
 (0)