Skip to content

Commit 4ea15b5

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: use wq for quiescing
Replace completions with waitqueues for rsrc data quiesce, the main wakeup condition is when data refs hit zero. Note that data refs are only changes under ->uring_lock, so we prepare before mutex_unlock() reacquire it after taking the lock back. This change will be needed in the next patch. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/1d0dbc74b3b4fd67c8f01819e680c5e0da252956.1681395792.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent eef81fc commit 4ea15b5

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

include/linux/io_uring_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ struct io_ring_ctx {
333333
/* protected by ->uring_lock */
334334
struct list_head rsrc_ref_list;
335335
struct io_alloc_cache rsrc_node_cache;
336+
struct wait_queue_head rsrc_quiesce_wq;
336337

337338
struct list_head io_buffers_pages;
338339

io_uring/io_uring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
321321
mutex_init(&ctx->uring_lock);
322322
init_waitqueue_head(&ctx->cq_wait);
323323
init_waitqueue_head(&ctx->poll_wq);
324+
init_waitqueue_head(&ctx->rsrc_quiesce_wq);
324325
spin_lock_init(&ctx->completion_lock);
325326
spin_lock_init(&ctx->timeout_lock);
326327
INIT_WQ_LIST(&ctx->iopoll_list);

io_uring/rsrc.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static void io_rsrc_put_work_one(struct io_rsrc_data *rsrc_data,
158158
static void __io_rsrc_put_work(struct io_rsrc_node *ref_node)
159159
{
160160
struct io_rsrc_data *rsrc_data = ref_node->rsrc_data;
161+
struct io_ring_ctx *ctx = rsrc_data->ctx;
161162
struct io_rsrc_put *prsrc, *tmp;
162163

163164
if (ref_node->inline_items)
@@ -171,13 +172,13 @@ static void __io_rsrc_put_work(struct io_rsrc_node *ref_node)
171172

172173
io_rsrc_node_destroy(rsrc_data->ctx, ref_node);
173174
if (io_put_rsrc_data_ref(rsrc_data))
174-
complete(&rsrc_data->done);
175+
wake_up_all(&ctx->rsrc_quiesce_wq);
175176
}
176177

177178
void io_wait_rsrc_data(struct io_rsrc_data *data)
178179
{
179-
if (data && !io_put_rsrc_data_ref(data))
180-
wait_for_completion(&data->done);
180+
if (data)
181+
WARN_ON_ONCE(!io_put_rsrc_data_ref(data));
181182
}
182183

183184
void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
@@ -257,6 +258,7 @@ int io_rsrc_node_switch_start(struct io_ring_ctx *ctx)
257258
__cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
258259
struct io_ring_ctx *ctx)
259260
{
261+
DEFINE_WAIT(we);
260262
int ret;
261263

262264
/* As we may drop ->uring_lock, other task may have started quiesce */
@@ -273,7 +275,9 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
273275

274276
data->quiesce = true;
275277
do {
278+
prepare_to_wait(&ctx->rsrc_quiesce_wq, &we, TASK_INTERRUPTIBLE);
276279
mutex_unlock(&ctx->uring_lock);
280+
277281
ret = io_run_task_work_sig(ctx);
278282
if (ret < 0) {
279283
mutex_lock(&ctx->uring_lock);
@@ -285,12 +289,15 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
285289
}
286290
break;
287291
}
288-
wait_for_completion_interruptible(&data->done);
292+
293+
schedule();
294+
__set_current_state(TASK_RUNNING);
289295
mutex_lock(&ctx->uring_lock);
290296
ret = 0;
291297
} while (data->refs);
292-
data->quiesce = false;
293298

299+
finish_wait(&ctx->rsrc_quiesce_wq, &we);
300+
data->quiesce = false;
294301
return ret;
295302
}
296303

@@ -366,7 +373,6 @@ __cold static int io_rsrc_data_alloc(struct io_ring_ctx *ctx,
366373
goto fail;
367374
}
368375
}
369-
init_completion(&data->done);
370376
*pdata = data;
371377
return 0;
372378
fail:

io_uring/rsrc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct io_rsrc_data {
3535
u64 **tags;
3636
unsigned int nr;
3737
rsrc_put_fn *do_put;
38-
struct completion done;
3938
int refs;
4039
bool quiesce;
4140
};

0 commit comments

Comments
 (0)