Skip to content

Commit 2fdd6fb

Browse files
isilenceaxboe
authored andcommitted
io_uring: don't batch task put on reqs free
We're trying to batch io_put_task() in io_free_batch_list(), but considering that the hot path is a simple inc, it's most cerainly and probably faster to just do io_put_task() instead of task tracking. We don't care about io_put_task_remote() as it's only for IOPOLL where polling/waiting is done by not the submitter task. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://lore.kernel.org/r/4a7ef7dce845fe2bd35507bf389d6bd2d5c1edf0.1687518903.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5a754de commit 2fdd6fb

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

io_uring/io_uring.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -754,29 +754,29 @@ static void io_cqring_overflow_flush(struct io_ring_ctx *ctx)
754754
}
755755

756756
/* can be called by any task */
757-
static void io_put_task_remote(struct task_struct *task, int nr)
757+
static void io_put_task_remote(struct task_struct *task)
758758
{
759759
struct io_uring_task *tctx = task->io_uring;
760760

761-
percpu_counter_sub(&tctx->inflight, nr);
761+
percpu_counter_sub(&tctx->inflight, 1);
762762
if (unlikely(atomic_read(&tctx->in_cancel)))
763763
wake_up(&tctx->wait);
764-
put_task_struct_many(task, nr);
764+
put_task_struct(task);
765765
}
766766

767767
/* used by a task to put its own references */
768-
static void io_put_task_local(struct task_struct *task, int nr)
768+
static void io_put_task_local(struct task_struct *task)
769769
{
770-
task->io_uring->cached_refs += nr;
770+
task->io_uring->cached_refs++;
771771
}
772772

773773
/* must to be called somewhat shortly after putting a request */
774-
static inline void io_put_task(struct task_struct *task, int nr)
774+
static inline void io_put_task(struct task_struct *task)
775775
{
776776
if (likely(task == current))
777-
io_put_task_local(task, nr);
777+
io_put_task_local(task);
778778
else
779-
io_put_task_remote(task, nr);
779+
io_put_task_remote(task);
780780
}
781781

782782
void io_task_refs_refill(struct io_uring_task *tctx)
@@ -1033,7 +1033,7 @@ static void __io_req_complete_post(struct io_kiocb *req, unsigned issue_flags)
10331033
* we don't hold ->completion_lock. Clean them here to avoid
10341034
* deadlocks.
10351035
*/
1036-
io_put_task_remote(req->task, 1);
1036+
io_put_task_remote(req->task);
10371037
wq_list_add_head(&req->comp_list, &ctx->locked_free_list);
10381038
ctx->locked_free_nr++;
10391039
}
@@ -1518,9 +1518,6 @@ void io_queue_next(struct io_kiocb *req)
15181518
void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
15191519
__must_hold(&ctx->uring_lock)
15201520
{
1521-
struct task_struct *task = NULL;
1522-
int task_refs = 0;
1523-
15241521
do {
15251522
struct io_kiocb *req = container_of(node, struct io_kiocb,
15261523
comp_list);
@@ -1550,19 +1547,10 @@ void io_free_batch_list(struct io_ring_ctx *ctx, struct io_wq_work_node *node)
15501547

15511548
io_req_put_rsrc_locked(req, ctx);
15521549

1553-
if (req->task != task) {
1554-
if (task)
1555-
io_put_task(task, task_refs);
1556-
task = req->task;
1557-
task_refs = 0;
1558-
}
1559-
task_refs++;
1550+
io_put_task(req->task);
15601551
node = req->comp_list.next;
15611552
io_req_add_to_cache(req, ctx);
15621553
} while (node);
1563-
1564-
if (task)
1565-
io_put_task(task, task_refs);
15661554
}
15671555

15681556
static void __io_submit_flush_completions(struct io_ring_ctx *ctx)

0 commit comments

Comments
 (0)