Skip to content

Commit faf7b51

Browse files
committed
io_uring: batch account ->req_issue and task struct references
Identical to how we handle the ctx reference counts, increase by the batch we're expecting to submit, and handle any slow path residual, if any. The request alloc-and-issue path is very hot, and this makes a noticeable difference by avoiding an two atomic incs for each individual request. Signed-off-by: Jens Axboe <[email protected]>
1 parent 87c4311 commit faf7b51

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/io_uring.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6429,8 +6429,6 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
64296429
/* one is dropped after submission, the other at completion */
64306430
refcount_set(&req->refs, 2);
64316431
req->task = current;
6432-
get_task_struct(req->task);
6433-
atomic_long_inc(&req->task->io_uring->req_issue);
64346432
req->result = 0;
64356433

64366434
if (unlikely(req->opcode >= IORING_OP_LAST))
@@ -6488,6 +6486,9 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
64886486
if (!percpu_ref_tryget_many(&ctx->refs, nr))
64896487
return -EAGAIN;
64906488

6489+
atomic_long_add(nr, &current->io_uring->req_issue);
6490+
refcount_add(nr, &current->usage);
6491+
64916492
io_submit_state_start(&state, ctx, nr);
64926493

64936494
for (i = 0; i < nr; i++) {
@@ -6530,6 +6531,8 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
65306531
int ref_used = (submitted == -EAGAIN) ? 0 : submitted;
65316532

65326533
percpu_ref_put_many(&ctx->refs, nr - ref_used);
6534+
atomic_long_sub(nr - ref_used, &current->io_uring->req_issue);
6535+
put_task_struct_many(current, nr - ref_used);
65336536
}
65346537
if (link)
65356538
io_queue_link_head(link, &state.comp);

0 commit comments

Comments
 (0)