Skip to content

Commit 01cec8c

Browse files
isilenceaxboe
authored andcommitted
io_uring: get rid of atomic FAA for cq_timeouts
If ->cq_timeouts modifications are done under ->completion_lock, we don't really nee any fetch-and-add and other complex atomics. Replace it with non-atomic FAA, that saves an implicit full memory barrier. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4693014 commit 01cec8c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/io_uring.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,8 @@ static void io_kill_timeout(struct io_kiocb *req)
12051205

12061206
ret = hrtimer_try_to_cancel(&req->io->timeout.timer);
12071207
if (ret != -1) {
1208-
atomic_inc(&req->ctx->cq_timeouts);
1208+
atomic_set(&req->ctx->cq_timeouts,
1209+
atomic_read(&req->ctx->cq_timeouts) + 1);
12091210
list_del_init(&req->timeout.list);
12101211
req->flags |= REQ_F_COMP_LOCKED;
12111212
io_cqring_fill_event(req, 0);
@@ -4972,9 +4973,10 @@ static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer)
49724973
struct io_ring_ctx *ctx = req->ctx;
49734974
unsigned long flags;
49744975

4975-
atomic_inc(&ctx->cq_timeouts);
4976-
49774976
spin_lock_irqsave(&ctx->completion_lock, flags);
4977+
atomic_set(&req->ctx->cq_timeouts,
4978+
atomic_read(&req->ctx->cq_timeouts) + 1);
4979+
49784980
/*
49794981
* We could be racing with timeout deletion. If the list is empty,
49804982
* then timeout lookup already found it and will be handling it.

0 commit comments

Comments
 (0)