public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
	[email protected], [email protected]
Subject: [PATCH 4/4] io_uring: batch cancel in io_uring_cancel_files()
Date: Sun,  7 Jun 2020 18:32:25 +0300	[thread overview]
Message-ID: <156ed08ba6c25ce97f6ba3261e64b2ffba6b2b58.1591541128.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 fs/io_uring.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index bcfb3b14b888..3aebbf96c123 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7519,9 +7519,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);
-- 
2.24.0


  parent reply	other threads:[~2020-06-07 15:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-07 15:32 [PATCH 0/4] cancel all reqs of an exiting task Pavel Begunkov
2020-06-07 15:32 ` [liburing PATCH] flush/test: test flush of dying process Pavel Begunkov
2020-06-07 15:32 ` [PATCH 1/4] io-wq: reorder cancellation pending -> running Pavel Begunkov
2020-06-07 15:32 ` [PATCH 2/4] io-wq: add an option to cancel all matched reqs Pavel Begunkov
2020-06-07 15:32 ` [PATCH 3/4] io_uring: cancel all task's requests on exit Pavel Begunkov
2020-06-07 15:32 ` Pavel Begunkov [this message]
2020-06-08  0:12 ` [PATCH 0/4] cancel all reqs of an exiting task Jens Axboe
2020-06-08  7:35   ` Pavel Begunkov

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=156ed08ba6c25ce97f6ba3261e64b2ffba6b2b58.1591541128.git.asml.silence@gmail.com \
    [email protected] \
    [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