Skip to content

Commit 6ec9afc

Browse files
isilenceaxboe
authored andcommitted
io_uring: remove io_free_req_tw
Request completion is a very hot path in general, but there are 3 places that can be doing it: io_free_batch_list(), io_req_complete_post() and io_free_req_tw(). io_free_req_tw() is used rather marginally and we don't care about it. Killing it can help to clean up and optimise the left two, do that by replacing it with io_req_task_complete(). There are two things to consider: 1) io_free_req() is called when all refs are put, so we need to reinit references. The easiest way to do that is to clear REQ_F_REFCOUNT. 2) We also don't need a cqe from it, so silence it with REQ_F_CQE_SKIP. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/434a2be8f33d474ad888ce1c17fe5ea7bbcb2a55.1687518903.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 247f97a commit 6ec9afc

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

io_uring/io_uring.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,26 +1121,13 @@ static inline void io_dismantle_req(struct io_kiocb *req)
11211121
io_put_file(req->file);
11221122
}
11231123

1124-
static __cold void io_free_req_tw(struct io_kiocb *req, struct io_tw_state *ts)
1125-
{
1126-
struct io_ring_ctx *ctx = req->ctx;
1127-
1128-
if (req->rsrc_node) {
1129-
io_tw_lock(ctx, ts);
1130-
io_put_rsrc_node(ctx, req->rsrc_node);
1131-
}
1132-
io_dismantle_req(req);
1133-
io_put_task_remote(req->task, 1);
1134-
1135-
spin_lock(&ctx->completion_lock);
1136-
wq_list_add_head(&req->comp_list, &ctx->locked_free_list);
1137-
ctx->locked_free_nr++;
1138-
spin_unlock(&ctx->completion_lock);
1139-
}
1140-
11411124
__cold void io_free_req(struct io_kiocb *req)
11421125
{
1143-
req->io_task_work.func = io_free_req_tw;
1126+
/* refs were already put, restore them for io_req_task_complete() */
1127+
req->flags &= ~REQ_F_REFCOUNT;
1128+
/* we only want to free it, don't post CQEs */
1129+
req->flags |= REQ_F_CQE_SKIP;
1130+
req->io_task_work.func = io_req_task_complete;
11441131
io_req_task_work_add(req);
11451132
}
11461133

0 commit comments

Comments
 (0)