Skip to content

Commit

Permalink
io_uring: remove wait loop spurious wakeups
Browse files Browse the repository at this point in the history
Any changes interesting to tasks waiting in io_cqring_wait() are
commited with io_cqring_ev_posted(). However, io_ring_drop_ctx_refs()
also tries to do that but with no reason, that means spurious wakeups
every io_free_req() and io_uring_enter().

Just use percpu_ref_put() instead.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Oct 8, 2019
1 parent b84477d commit 6805b32
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,6 @@ static void io_cqring_add_event(struct io_ring_ctx *ctx, u64 user_data,
io_cqring_ev_posted(ctx);
}

static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs)
{
percpu_ref_put_many(&ctx->refs, refs);

if (waitqueue_active(&ctx->wait))
wake_up(&ctx->wait);
}

static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
struct io_submit_state *state)
{
Expand Down Expand Up @@ -646,15 +638,15 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
req->result = 0;
return req;
out:
io_ring_drop_ctx_refs(ctx, 1);
percpu_ref_put(&ctx->refs);
return NULL;
}

static void io_free_req_many(struct io_ring_ctx *ctx, void **reqs, int *nr)
{
if (*nr) {
kmem_cache_free_bulk(req_cachep, *nr, reqs);
io_ring_drop_ctx_refs(ctx, *nr);
percpu_ref_put_many(&ctx->refs, *nr);
*nr = 0;
}
}
Expand All @@ -663,7 +655,7 @@ static void __io_free_req(struct io_kiocb *req)
{
if (req->file && !(req->flags & REQ_F_FIXED_FILE))
fput(req->file);
io_ring_drop_ctx_refs(req->ctx, 1);
percpu_ref_put(&req->ctx->refs);
kmem_cache_free(req_cachep, req);
}

Expand Down Expand Up @@ -3584,7 +3576,7 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
}
}

io_ring_drop_ctx_refs(ctx, 1);
percpu_ref_put(&ctx->refs);
out_fput:
fdput(f);
return submitted ? submitted : ret;
Expand Down

0 comments on commit 6805b32

Please sign in to comment.