io_uring: optimise ltimeout for inline execution
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 1 Dec 2023 00:38:53 +0000 (00:38 +0000)
committerJens Axboe <axboe@kernel.dk>
Tue, 12 Dec 2023 14:42:52 +0000 (07:42 -0700)
At one point in time we had an optimisation that would not spin up a
linked timeout timer when the master request successfully completes
inline (during the first nowait execution attempt). We somehow lost it,
so this patch restores it back.

Note, that it's fine using io_arm_ltimeout() after the io_issue_sqe()
completes the request because of delayed completion, but that that adds
unwanted overhead.

Reported-by: Christian Mazakas <christian.mazakas@gmail.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/8bf69c2a4beec14c565c85c86edb871ca8b8bcc8.1701390926.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c

index 828d0975c270d190ac017e2306fca76a34c02d4d..0c269652ad2629563f7da16f35957d54a13f0316 100644 (file)
@@ -1902,14 +1902,15 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
                return 0;
        }
 
-       if (ret != IOU_ISSUE_SKIP_COMPLETE)
-               return ret;
-
-       /* If the op doesn't have a file, we're not polling for it */
-       if ((req->ctx->flags & IORING_SETUP_IOPOLL) && def->iopoll_queue)
-               io_iopoll_req_issued(req, issue_flags);
+       if (ret == IOU_ISSUE_SKIP_COMPLETE) {
+               ret = 0;
+               io_arm_ltimeout(req);
 
-       return 0;
+               /* If the op doesn't have a file, we're not polling for it */
+               if ((req->ctx->flags & IORING_SETUP_IOPOLL) && def->iopoll_queue)
+                       io_iopoll_req_issued(req, issue_flags);
+       }
+       return ret;
 }
 
 int io_poll_issue(struct io_kiocb *req, struct io_tw_state *ts)
@@ -2080,9 +2081,7 @@ static inline void io_queue_sqe(struct io_kiocb *req)
         * We async punt it if the file wasn't marked NOWAIT, or if the file
         * doesn't support non-blocking read/write attempts
         */
-       if (likely(!ret))
-               io_arm_ltimeout(req);
-       else
+       if (unlikely(ret))
                io_queue_async(req, ret);
 }