Skip to content

Commit

Permalink
io_uring: do not always force run task_work in io_uring_register
Browse files Browse the repository at this point in the history
Running task work when not needed can unnecessarily delay
operations. Specifically IORING_SETUP_DEFER_TASKRUN tries to avoid running
task work until the user requests it. Therefore do not run it in
io_uring_register any more.

The one catch is that io_rsrc_ref_quiesce expects it to have run in order
to process all outstanding references, and so reorder it's loop to do this.

Signed-off-by: Dylan Yudaken <dylany@meta.com>
Link: https://lore.kernel.org/r/20221107123349.4106213-1-dylany@meta.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Dylan Yudaken authored and axboe committed Nov 21, 2022
1 parent df730ec commit ef67fcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 0 additions & 2 deletions io_uring/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -4056,8 +4056,6 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode,

ctx = f.file->private_data;

io_run_task_work_ctx(ctx);

mutex_lock(&ctx->uring_lock);
ret = __io_uring_register(ctx, opcode, arg, nr_args);
mutex_unlock(&ctx->uring_lock);
Expand Down
7 changes: 6 additions & 1 deletion io_uring/rsrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
if (atomic_dec_and_test(&data->refs))
break;
mutex_unlock(&ctx->uring_lock);

ret = io_run_task_work_sig(ctx);
if (ret < 0)
goto reinit;

flush_delayed_work(&ctx->rsrc_put_work);
ret = wait_for_completion_interruptible(&data->done);
if (!ret) {
Expand All @@ -336,12 +341,12 @@ __cold static int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
}
}

reinit:
atomic_inc(&data->refs);
/* wait for all works potentially completing data->done */
flush_delayed_work(&ctx->rsrc_put_work);
reinit_completion(&data->done);

ret = io_run_task_work_sig(ctx);
mutex_lock(&ctx->uring_lock);
} while (ret >= 0);
data->quiesce = false;
Expand Down

0 comments on commit ef67fcb

Please sign in to comment.