Skip to content

Commit 90df085

Browse files
isilenceaxboe
authored andcommitted
io_uring: cancel more aggressively in exit_work
While io_ring_exit_work() is running new requests of all sorts may be issued, so it should do a bit more to cancel them, otherwise they may just get stuck. e.g. in io-wq, in poll lists, etc. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent de7f1d9 commit 90df085

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

fs/io_uring.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,9 @@ enum io_mem_account {
992992
ACCT_PINNED,
993993
};
994994

995+
static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
996+
struct task_struct *task);
997+
995998
static void destroy_fixed_file_ref_node(struct fixed_file_ref_node *ref_node);
996999
static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
9971000
struct io_ring_ctx *ctx);
@@ -8675,7 +8678,7 @@ static void io_ring_exit_work(struct work_struct *work)
86758678
* as nobody else will be looking for them.
86768679
*/
86778680
do {
8678-
io_iopoll_try_reap_events(ctx);
8681+
__io_uring_cancel_task_requests(ctx, NULL);
86798682
} while (!wait_for_completion_timeout(&ctx->ref_comp, HZ/20));
86808683
io_ring_ctx_free(ctx);
86818684
}
@@ -8830,9 +8833,11 @@ static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx,
88308833
enum io_wq_cancel cret;
88318834
bool ret = false;
88328835

8833-
cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb, &cancel, true);
8834-
if (cret != IO_WQ_CANCEL_NOTFOUND)
8835-
ret = true;
8836+
if (ctx->io_wq) {
8837+
cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb,
8838+
&cancel, true);
8839+
ret |= (cret != IO_WQ_CANCEL_NOTFOUND);
8840+
}
88368841

88378842
/* SQPOLL thread does its own polling */
88388843
if (!(ctx->flags & IORING_SETUP_SQPOLL)) {

0 commit comments

Comments
 (0)