summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorPavel Begunkov <asml.silence@gmail.com>2021-04-14 15:38:34 +0300
committerJens Axboe <axboe@kernel.dk>2021-04-14 19:42:31 +0300
commit7f00651aebc9af600be1d9df2a775eeeaee6bebb (patch)
treea8348128a0b1b5fd9e9a4293c291264f06223522 /fs
parentf39c8a5b1130fe17db9c66d08aa473d9587543a9 (diff)
downloadlinux-7f00651aebc9af600be1d9df2a775eeeaee6bebb.tar.xz
io_uring: refactor io_ring_exit_work()
Don't reinit io_ring_exit_work()'s exit work/completions on each iteration, that's wasteful. Also add list_rotate_left(), so if we failed to complete the task job, we don't try it again and again but defer it until others are processed. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r--fs/io_uring.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a807c3f22778..f0e6349f9919 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8575,6 +8575,9 @@ static void io_ring_exit_work(struct work_struct *work)
WARN_ON_ONCE(time_after(jiffies, timeout));
} while (!wait_for_completion_timeout(&ctx->ref_comp, HZ/20));
+ init_completion(&exit.completion);
+ init_task_work(&exit.task_work, io_tctx_exit_cb);
+ exit.ctx = ctx;
/*
* Some may use context even when all refs and requests have been put,
* and they are free to do so while still holding uring_lock or
@@ -8587,9 +8590,8 @@ static void io_ring_exit_work(struct work_struct *work)
node = list_first_entry(&ctx->tctx_list, struct io_tctx_node,
ctx_node);
- exit.ctx = ctx;
- init_completion(&exit.completion);
- init_task_work(&exit.task_work, io_tctx_exit_cb);
+ /* don't spin on a single task if cancellation failed */
+ list_rotate_left(&ctx->tctx_list);
ret = task_work_add(node->task, &exit.task_work, TWA_SIGNAL);
if (WARN_ON_ONCE(ret))
continue;
@@ -8597,7 +8599,6 @@ static void io_ring_exit_work(struct work_struct *work)
mutex_unlock(&ctx->uring_lock);
wait_for_completion(&exit.completion);
- cond_resched();
mutex_lock(&ctx->uring_lock);
}
mutex_unlock(&ctx->uring_lock);