From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 01/16] io_uring: unify task and files cancel loops
Date: Sun, 11 Apr 2021 01:46:25 +0100 [thread overview]
Message-ID: <dca5a395efebd1e3e0f3bbc6b9640c5e8aa7e468.1618101759.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Move tracked inflight number check up the stack into
__io_uring_files_cancel() so it's similar to task cancel. Will be used
for further cleaning.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 74 ++++++++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 33 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index f1fcb32f8e0b..5c2364ceb6e1 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8869,28 +8869,6 @@ static int io_uring_count_inflight(struct io_ring_ctx *ctx,
return cnt;
}
-static void io_uring_cancel_files(struct io_ring_ctx *ctx,
- struct task_struct *task,
- struct files_struct *files)
-{
- while (!list_empty_careful(&ctx->inflight_list)) {
- DEFINE_WAIT(wait);
- int inflight;
-
- inflight = io_uring_count_inflight(ctx, task, files);
- if (!inflight)
- break;
-
- io_uring_try_cancel_requests(ctx, task, files);
-
- prepare_to_wait(&task->io_uring->wait, &wait,
- TASK_UNINTERRUPTIBLE);
- if (inflight == io_uring_count_inflight(ctx, task, files))
- schedule();
- finish_wait(&task->io_uring->wait, &wait);
- }
-}
-
static int __io_uring_add_task_file(struct io_ring_ctx *ctx)
{
struct io_uring_task *tctx = current->io_uring;
@@ -8976,6 +8954,19 @@ static void io_uring_clean_tctx(struct io_uring_task *tctx)
}
}
+static s64 tctx_inflight_tracked(struct task_struct *task,
+ struct files_struct *files)
+{
+ struct io_uring_task *tctx = task->io_uring;
+ struct io_tctx_node *node;
+ unsigned long index;
+ s64 cnt = 0;
+
+ xa_for_each(&tctx->xa, index, node)
+ cnt += io_uring_count_inflight(node->ctx, task, files);
+ return cnt;
+}
+
static s64 tctx_inflight(struct io_uring_task *tctx)
{
return percpu_counter_sum(&tctx->inflight);
@@ -9014,14 +9005,12 @@ static void io_sqpoll_cancel_sync(struct io_ring_ctx *ctx)
wait_for_completion(&work.completion);
}
-void __io_uring_files_cancel(struct files_struct *files)
+static void io_uring_try_cancel(struct files_struct *files)
{
struct io_uring_task *tctx = current->io_uring;
struct io_tctx_node *node;
unsigned long index;
- /* make sure overflow events are dropped */
- atomic_inc(&tctx->in_idle);
xa_for_each(&tctx->xa, index, node) {
struct io_ring_ctx *ctx = node->ctx;
@@ -9029,14 +9018,8 @@ void __io_uring_files_cancel(struct files_struct *files)
io_sqpoll_cancel_sync(ctx);
continue;
}
- io_uring_cancel_files(ctx, current, files);
- if (!files)
- io_uring_try_cancel_requests(ctx, current, NULL);
+ io_uring_try_cancel_requests(ctx, current, files);
}
- atomic_dec(&tctx->in_idle);
-
- if (files)
- io_uring_clean_tctx(tctx);
}
/* should only be called by SQPOLL task */
@@ -9070,6 +9053,31 @@ static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx)
atomic_dec(&tctx->in_idle);
}
+void __io_uring_files_cancel(struct files_struct *files)
+{
+ struct io_uring_task *tctx = current->io_uring;
+ DEFINE_WAIT(wait);
+ s64 inflight;
+
+ /* make sure overflow events are dropped */
+ atomic_inc(&tctx->in_idle);
+ do {
+ /* read completions before cancelations */
+ inflight = tctx_inflight_tracked(current, files);
+ if (!inflight)
+ break;
+ io_uring_try_cancel(files);
+
+ prepare_to_wait(&tctx->wait, &wait, TASK_UNINTERRUPTIBLE);
+ if (inflight == tctx_inflight_tracked(current, files))
+ schedule();
+ finish_wait(&tctx->wait, &wait);
+ } while (1);
+ atomic_dec(&tctx->in_idle);
+
+ io_uring_clean_tctx(tctx);
+}
+
/*
* Find any io_uring fd that this task has registered or done IO on, and cancel
* requests.
@@ -9089,7 +9097,7 @@ void __io_uring_task_cancel(void)
inflight = tctx_inflight(tctx);
if (!inflight)
break;
- __io_uring_files_cancel(NULL);
+ io_uring_try_cancel(NULL);
prepare_to_wait(&tctx->wait, &wait, TASK_UNINTERRUPTIBLE);
--
2.24.0
next prev parent reply other threads:[~2021-04-11 0:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-11 0:46 [PATCH 5.13 00/16] random 5.13 patches Pavel Begunkov
2021-04-11 0:46 ` Pavel Begunkov [this message]
2021-04-11 0:46 ` [PATCH 02/16] io_uring: track inflight requests through counter Pavel Begunkov
2021-04-11 0:46 ` [PATCH 03/16] io_uring: unify files and task cancel Pavel Begunkov
2021-04-11 0:46 ` [PATCH 04/16] io_uring: refactor io_close Pavel Begunkov
2021-04-11 0:46 ` [PATCH 05/16] io_uring: enable inline completion for more cases Pavel Begunkov
2021-04-11 0:46 ` [PATCH 06/16] io_uring: refactor compat_msghdr import Pavel Begunkov
2021-04-11 0:46 ` [PATCH 07/16] io_uring: optimise non-eventfd post-event Pavel Begunkov
2021-04-11 0:46 ` [PATCH 08/16] io_uring: always pass cflags into fill_event() Pavel Begunkov
2021-04-11 0:46 ` [PATCH 09/16] io_uring: optimise fill_event() by inlining Pavel Begunkov
2021-04-11 0:46 ` [PATCH 10/16] io_uring: simplify io_rsrc_data refcounting Pavel Begunkov
2021-04-11 0:46 ` [PATCH 11/16] io_uring: add buffer unmap helper Pavel Begunkov
2021-04-11 0:46 ` [PATCH 12/16] io_uring: cleanup buffer register Pavel Begunkov
2021-04-11 0:46 ` [PATCH 13/16] io_uring: split file table from rsrc nodes Pavel Begunkov
2021-04-11 0:46 ` [PATCH 14/16] io_uring: improve sqo stop Pavel Begunkov
2021-04-11 0:46 ` [PATCH 15/16] io_uring: improve hardlink code generation Pavel Begunkov
2021-04-11 0:46 ` [PATCH 16/16] io_uring: return back safer resurrect Pavel Begunkov
2021-05-10 2:22 ` yangerkun
2021-05-10 9:15 ` Pavel Begunkov
2021-05-11 1:11 ` yangerkun
2022-03-16 16:18 ` [PATCH] " Lee Jones
2022-03-16 16:38 ` Greg KH
2022-03-16 16:46 ` Lee Jones
2021-04-11 2:38 ` [PATCH 5.13 00/16] random 5.13 patches Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dca5a395efebd1e3e0f3bbc6b9640c5e8aa7e468.1618101759.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox