From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 03/16] io_uring: unify files and task cancel
Date: Sun, 11 Apr 2021 01:46:27 +0100 [thread overview]
Message-ID: <1a5986a97df4dc1378f3fe0ca1eb483dbcf42112.1618101759.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Now __io_uring_cancel() and __io_uring_files_cancel() are very similar
and mostly differ by how we count requests, merge them and allow
tctx_inflight() to handle counting.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 56 ++++++++++------------------------------
include/linux/io_uring.h | 12 ++++-----
2 files changed, 19 insertions(+), 49 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3353a0b1032a..0dcf9b7a7423 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8926,13 +8926,10 @@ static void io_uring_clean_tctx(struct io_uring_task *tctx)
}
}
-static s64 tctx_inflight_tracked(struct io_uring_task *tctx)
-{
- return atomic_read(&tctx->inflight_tracked);
-}
-
-static s64 tctx_inflight(struct io_uring_task *tctx)
+static s64 tctx_inflight(struct io_uring_task *tctx, bool tracked)
{
+ if (tracked)
+ return atomic_read(&tctx->inflight_tracked);
return percpu_counter_sum(&tctx->inflight);
}
@@ -8999,7 +8996,7 @@ static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx)
atomic_inc(&tctx->in_idle);
do {
/* read completions before cancelations */
- inflight = tctx_inflight(tctx);
+ inflight = tctx_inflight(tctx, false);
if (!inflight)
break;
io_uring_try_cancel_requests(ctx, current, NULL);
@@ -9010,43 +9007,18 @@ static void io_uring_cancel_sqpoll(struct io_ring_ctx *ctx)
* avoids a race where a completion comes in before we did
* prepare_to_wait().
*/
- if (inflight == tctx_inflight(tctx))
+ if (inflight == tctx_inflight(tctx, false))
schedule();
finish_wait(&tctx->wait, &wait);
} while (1);
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(tctx);
- if (!inflight)
- break;
- io_uring_try_cancel(files);
-
- prepare_to_wait(&tctx->wait, &wait, TASK_UNINTERRUPTIBLE);
- if (inflight == tctx_inflight_tracked(tctx))
- 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.
*/
-void __io_uring_task_cancel(void)
+void __io_uring_cancel(struct files_struct *files)
{
struct io_uring_task *tctx = current->io_uring;
DEFINE_WAIT(wait);
@@ -9054,15 +9026,14 @@ void __io_uring_task_cancel(void)
/* make sure overflow events are dropped */
atomic_inc(&tctx->in_idle);
- __io_uring_files_cancel(NULL);
+ io_uring_try_cancel(files);
do {
/* read completions before cancelations */
- inflight = tctx_inflight(tctx);
+ inflight = tctx_inflight(tctx, !!files);
if (!inflight)
break;
- io_uring_try_cancel(NULL);
-
+ io_uring_try_cancel(files);
prepare_to_wait(&tctx->wait, &wait, TASK_UNINTERRUPTIBLE);
/*
@@ -9070,16 +9041,17 @@ void __io_uring_task_cancel(void)
* avoids a race where a completion comes in before we did
* prepare_to_wait().
*/
- if (inflight == tctx_inflight(tctx))
+ if (inflight == tctx_inflight(tctx, !!files))
schedule();
finish_wait(&tctx->wait, &wait);
} while (1);
-
atomic_dec(&tctx->in_idle);
io_uring_clean_tctx(tctx);
- /* all current's requests should be gone, we can kill tctx */
- __io_uring_free(current);
+ if (!files) {
+ /* for exec all current's requests should be gone, kill tctx */
+ __io_uring_free(current);
+ }
}
static void *io_uring_validate_mmap_request(struct file *file,
diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h
index 79cde9906be0..04b650bcbbe5 100644
--- a/include/linux/io_uring.h
+++ b/include/linux/io_uring.h
@@ -7,19 +7,17 @@
#if defined(CONFIG_IO_URING)
struct sock *io_uring_get_socket(struct file *file);
-void __io_uring_task_cancel(void);
-void __io_uring_files_cancel(struct files_struct *files);
+void __io_uring_cancel(struct files_struct *files);
void __io_uring_free(struct task_struct *tsk);
-static inline void io_uring_task_cancel(void)
+static inline void io_uring_files_cancel(struct files_struct *files)
{
if (current->io_uring)
- __io_uring_task_cancel();
+ __io_uring_cancel(files);
}
-static inline void io_uring_files_cancel(struct files_struct *files)
+static inline void io_uring_task_cancel(void)
{
- if (current->io_uring)
- __io_uring_files_cancel(files);
+ return io_uring_files_cancel(NULL);
}
static inline void io_uring_free(struct task_struct *tsk)
{
--
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 ` [PATCH 01/16] io_uring: unify task and files cancel loops Pavel Begunkov
2021-04-11 0:46 ` [PATCH 02/16] io_uring: track inflight requests through counter Pavel Begunkov
2021-04-11 0:46 ` Pavel Begunkov [this message]
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=1a5986a97df4dc1378f3fe0ca1eb483dbcf42112.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