Re: [PATCH] io_uring: reduce latency by reissueing the operation

From: Pavel Begunkov
Date: Thu Jun 10 2021 - 05:04:17 EST


On 6/9/21 11:08 PM, Olivier Langlois wrote:
> It is quite frequent that when an operation fails and returns EAGAIN,
> the data becomes available between that failure and the call to
> vfs_poll() done by io_arm_poll_handler().
>
> Detecting the situation and reissuing the operation is much faster
> than going ahead and push the operation to the io-wq.

The poll stuff is not perfect and definitely can be improved,
but there are drawbacks, with this one fairness may suffer
with higher submit batching and make lat worse for all
but one request.

I'll get to it and another poll related email later,
probably next week.

>
> Signed-off-by: Olivier Langlois <olivier@xxxxxxxxxxxxxx>
> ---
> fs/io_uring.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 42380ed563c4..98cf3e323d5e 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -5138,15 +5138,16 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
> return mask;
> }
>
> -static bool io_arm_poll_handler(struct io_kiocb *req)
> +static bool io_arm_poll_handler(struct io_kiocb *req, __poll_t *ret)
> {
> const struct io_op_def *def = &io_op_defs[req->opcode];
> struct io_ring_ctx *ctx = req->ctx;
> struct async_poll *apoll;
> struct io_poll_table ipt;
> - __poll_t mask, ret;
> + __poll_t mask;
> int rw;
>
> + *ret = 0;
> if (!req->file || !file_can_poll(req->file))
> return false;
> if (req->flags & REQ_F_POLLED)
> @@ -5184,9 +5185,9 @@ static bool io_arm_poll_handler(struct io_kiocb *req)
>
> ipt.pt._qproc = io_async_queue_proc;
>
> - ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask,
> + *ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask,
> io_async_wake);
> - if (ret || ipt.error) {
> + if (*ret || ipt.error) {
> io_poll_remove_double(req);
> spin_unlock_irq(&ctx->completion_lock);
> return false;
> @@ -6410,7 +6411,9 @@ static void __io_queue_sqe(struct io_kiocb *req)
> {
> struct io_kiocb *linked_timeout = io_prep_linked_timeout(req);
> int ret;
> + __poll_t poll_ret;
>
> +issue_sqe:
> ret = io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_COMPLETE_DEFER);
>
> /*
> @@ -6430,7 +6433,9 @@ static void __io_queue_sqe(struct io_kiocb *req)
> io_put_req(req);
> }
> } else if (ret == -EAGAIN && !(req->flags & REQ_F_NOWAIT)) {
> - if (!io_arm_poll_handler(req)) {
> + if (!io_arm_poll_handler(req, &poll_ret)) {
> + if (poll_ret)
> + goto issue_sqe;
> /*
> * Queued up for async execution, worker will release
> * submit reference when the iocb is actually submitted.
>

--
Pavel Begunkov