Skip to content

Commit d62c2f0

Browse files
committed
io_uring: ensure io_queue_deferred() is out-of-line
This is not the hot path, it's a slow path. Yet the locking for it is in the hot path, and __cold does not prevent it from being inlined. Move the locking to the function itself, and mark it noinline as well to avoid it polluting the icache of the hot path. Signed-off-by: Jens Axboe <[email protected]>
1 parent c5f7191 commit d62c2f0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

io_uring/io_uring.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,9 @@ void io_req_queue_iowq(struct io_kiocb *req)
550550
io_req_task_work_add(req);
551551
}
552552

553-
static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
553+
static __cold noinline void io_queue_deferred(struct io_ring_ctx *ctx)
554554
{
555+
spin_lock(&ctx->completion_lock);
555556
while (!list_empty(&ctx->defer_list)) {
556557
struct io_defer_entry *de = list_first_entry(&ctx->defer_list,
557558
struct io_defer_entry, list);
@@ -562,6 +563,7 @@ static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
562563
io_req_task_queue(de->req);
563564
kfree(de);
564565
}
566+
spin_unlock(&ctx->completion_lock);
565567
}
566568

567569
void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
@@ -570,11 +572,8 @@ void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
570572
io_poll_wq_wake(ctx);
571573
if (ctx->off_timeout_used)
572574
io_flush_timeouts(ctx);
573-
if (ctx->drain_active) {
574-
spin_lock(&ctx->completion_lock);
575+
if (ctx->drain_active)
575576
io_queue_deferred(ctx);
576-
spin_unlock(&ctx->completion_lock);
577-
}
578577
if (ctx->has_evfd)
579578
io_eventfd_flush_signal(ctx);
580579
}

0 commit comments

Comments
 (0)