Skip to content

Commit d3d7298

Browse files
isilenceaxboe
authored andcommitted
io_uring: optimise out unlikely link queue
__io_queue_sqe() tries to issue as much requests of a link as it can, and uses io_put_req_find_next() to extract a next one, targeting inline completed requests. As now __io_queue_sqe() is always used together with struct io_comp_state, it leaves next propagation only a small window and only for async reqs, that doesn't justify its existence. Remove it, make __io_queue_sqe() to issue only a head request. It simplifies the code and will allow other optimisations. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent bd75904 commit d3d7298

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

fs/io_uring.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6563,26 +6563,20 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
65636563

65646564
static void __io_queue_sqe(struct io_kiocb *req)
65656565
{
6566-
struct io_kiocb *linked_timeout;
6566+
struct io_kiocb *linked_timeout = io_prep_linked_timeout(req);
65676567
const struct cred *old_creds = NULL;
65686568
int ret;
65696569

6570-
again:
6571-
linked_timeout = io_prep_linked_timeout(req);
6572-
65736570
if ((req->flags & REQ_F_WORK_INITIALIZED) &&
65746571
(req->work.flags & IO_WQ_WORK_CREDS) &&
6575-
req->work.identity->creds != current_cred()) {
6576-
if (old_creds)
6577-
revert_creds(old_creds);
6578-
if (old_creds == req->work.identity->creds)
6579-
old_creds = NULL; /* restored original creds */
6580-
else
6581-
old_creds = override_creds(req->work.identity->creds);
6582-
}
6572+
req->work.identity->creds != current_cred())
6573+
old_creds = override_creds(req->work.identity->creds);
65836574

65846575
ret = io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_COMPLETE_DEFER);
65856576

6577+
if (old_creds)
6578+
revert_creds(old_creds);
6579+
65866580
/*
65876581
* We async punt it if the file wasn't marked NOWAIT, or if the file
65886582
* doesn't support non-blocking read/write attempts
@@ -6595,41 +6589,25 @@ static void __io_queue_sqe(struct io_kiocb *req)
65956589
*/
65966590
io_queue_async_work(req);
65976591
}
6598-
6599-
if (linked_timeout)
6600-
io_queue_linked_timeout(linked_timeout);
66016592
} else if (likely(!ret)) {
66026593
/* drop submission reference */
66036594
if (req->flags & REQ_F_COMPLETE_INLINE) {
66046595
struct io_ring_ctx *ctx = req->ctx;
66056596
struct io_comp_state *cs = &ctx->submit_state.comp;
66066597

66076598
cs->reqs[cs->nr++] = req;
6608-
if (cs->nr == IO_COMPL_BATCH)
6599+
if (cs->nr == ARRAY_SIZE(cs->reqs))
66096600
io_submit_flush_completions(cs, ctx);
6610-
req = NULL;
66116601
} else {
6612-
req = io_put_req_find_next(req);
6613-
}
6614-
6615-
if (linked_timeout)
6616-
io_queue_linked_timeout(linked_timeout);
6617-
6618-
if (req) {
6619-
if (!(req->flags & REQ_F_FORCE_ASYNC))
6620-
goto again;
6621-
io_queue_async_work(req);
6602+
io_put_req(req);
66226603
}
66236604
} else {
6624-
/* un-prep timeout, so it'll be killed as any other linked */
6625-
req->flags &= ~REQ_F_LINK_TIMEOUT;
66266605
req_set_fail_links(req);
66276606
io_put_req(req);
66286607
io_req_complete(req, ret);
66296608
}
6630-
6631-
if (old_creds)
6632-
revert_creds(old_creds);
6609+
if (linked_timeout)
6610+
io_queue_linked_timeout(linked_timeout);
66336611
}
66346612

66356613
static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)

0 commit comments

Comments
 (0)