Commit 5afa4650 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: refactor io_put_task helpers

Add a helper for putting refs from the target task context, rename
__io_put_task() and add a couple of comments around. Use the remote
version for __io_req_complete_post(), the local is only needed for
__io_submit_flush_completions().
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/3bf92ebd594769d8a5d648472a8e335f2031d542.1674484266.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent c8576f3e
...@@ -713,7 +713,8 @@ static void io_cqring_overflow_flush(struct io_ring_ctx *ctx) ...@@ -713,7 +713,8 @@ static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)
io_cqring_do_overflow_flush(ctx); io_cqring_do_overflow_flush(ctx);
} }
static void __io_put_task(struct task_struct *task, int nr) /* can be called by any task */
static void io_put_task_remote(struct task_struct *task, int nr)
{ {
struct io_uring_task *tctx = task->io_uring; struct io_uring_task *tctx = task->io_uring;
...@@ -723,13 +724,19 @@ static void __io_put_task(struct task_struct *task, int nr) ...@@ -723,13 +724,19 @@ static void __io_put_task(struct task_struct *task, int nr)
put_task_struct_many(task, nr); put_task_struct_many(task, nr);
} }
/* used by a task to put its own references */
static void io_put_task_local(struct task_struct *task, int nr)
{
task->io_uring->cached_refs += nr;
}
/* must to be called somewhat shortly after putting a request */ /* must to be called somewhat shortly after putting a request */
static inline void io_put_task(struct task_struct *task, int nr) static inline void io_put_task(struct task_struct *task, int nr)
{ {
if (likely(task == current)) if (likely(task == current))
task->io_uring->cached_refs += nr; io_put_task_local(task, nr);
else else
__io_put_task(task, nr); io_put_task_remote(task, nr);
} }
void io_task_refs_refill(struct io_uring_task *tctx) void io_task_refs_refill(struct io_uring_task *tctx)
...@@ -982,7 +989,7 @@ static void __io_req_complete_post(struct io_kiocb *req) ...@@ -982,7 +989,7 @@ static void __io_req_complete_post(struct io_kiocb *req)
* we don't hold ->completion_lock. Clean them here to avoid * we don't hold ->completion_lock. Clean them here to avoid
* deadlocks. * deadlocks.
*/ */
io_put_task(req->task, 1); io_put_task_remote(req->task, 1);
wq_list_add_head(&req->comp_list, &ctx->locked_free_list); wq_list_add_head(&req->comp_list, &ctx->locked_free_list);
ctx->locked_free_nr++; ctx->locked_free_nr++;
} }
...@@ -1105,7 +1112,7 @@ __cold void io_free_req(struct io_kiocb *req) ...@@ -1105,7 +1112,7 @@ __cold void io_free_req(struct io_kiocb *req)
io_req_put_rsrc(req); io_req_put_rsrc(req);
io_dismantle_req(req); io_dismantle_req(req);
io_put_task(req->task, 1); io_put_task_remote(req->task, 1);
spin_lock(&ctx->completion_lock); spin_lock(&ctx->completion_lock);
wq_list_add_head(&req->comp_list, &ctx->locked_free_list); wq_list_add_head(&req->comp_list, &ctx->locked_free_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment