Commit e98e49b2 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: extend task put optimisations

Now with IRQ completions done via IRQ, almost all requests freeing
are done from the context of submitter task, so it makes sense to
extend task_put optimisation from io_req_free_batch_finish() to cover
all the cases including task_work by moving it into io_put_task().
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/824a7cbd745ddeee4a0f3ff85c558a24fd005872.1629302453.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 316319e8
...@@ -1623,10 +1623,14 @@ static inline void io_put_task(struct task_struct *task, int nr) ...@@ -1623,10 +1623,14 @@ static inline void io_put_task(struct task_struct *task, int nr)
{ {
struct io_uring_task *tctx = task->io_uring; struct io_uring_task *tctx = task->io_uring;
if (likely(task == current)) {
tctx->cached_refs += nr;
} else {
percpu_counter_sub(&tctx->inflight, nr); percpu_counter_sub(&tctx->inflight, nr);
if (unlikely(atomic_read(&tctx->in_idle))) if (unlikely(atomic_read(&tctx->in_idle)))
wake_up(&tctx->wait); wake_up(&tctx->wait);
put_task_struct_many(task, nr); put_task_struct_many(task, nr);
}
} }
static bool io_cqring_event_overflow(struct io_ring_ctx *ctx, u64 user_data, static bool io_cqring_event_overflow(struct io_ring_ctx *ctx, u64 user_data,
...@@ -2171,9 +2175,7 @@ static void io_req_free_batch_finish(struct io_ring_ctx *ctx, ...@@ -2171,9 +2175,7 @@ static void io_req_free_batch_finish(struct io_ring_ctx *ctx,
{ {
if (rb->ctx_refs) if (rb->ctx_refs)
percpu_ref_put_many(&ctx->refs, rb->ctx_refs); percpu_ref_put_many(&ctx->refs, rb->ctx_refs);
if (rb->task == current) if (rb->task)
current->io_uring->cached_refs += rb->task_refs;
else if (rb->task)
io_put_task(rb->task, rb->task_refs); io_put_task(rb->task, rb->task_refs);
} }
......
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