Skip to content

Commit

Permalink
io_uring: batch cancel in io_uring_cancel_files()
Browse files Browse the repository at this point in the history
Instead of waiting for each request one by one, first try to cancel all
of them in a batched manner, and then go over inflight_list/etc to reap
leftovers.

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 Jun 15, 2020
1 parent 44e728b commit 67c4d9e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -7366,9 +7366,22 @@ static int io_uring_release(struct inode *inode, struct file *file)
return 0;
}

static bool io_wq_files_match(struct io_wq_work *work, void *data)
{
struct files_struct *files = data;

return work->files == files;
}

static void io_uring_cancel_files(struct io_ring_ctx *ctx,
struct files_struct *files)
{
if (list_empty_careful(&ctx->inflight_list))
return;

/* cancel all at once, should be faster than doing it one by one*/
io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true);

while (!list_empty_careful(&ctx->inflight_list)) {
struct io_kiocb *cancel_req = NULL, *req;
DEFINE_WAIT(wait);
Expand Down

0 comments on commit 67c4d9e

Please sign in to comment.