From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH for-next 1/5] io_uring: improve io_fail_links()
Date: Sat, 25 Jun 2022 11:52:58 +0100 [thread overview]
Message-ID: <a2f68708b970a21f4e84ddfa7b3abd67a8fffb27.1656153285.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
io_fail_links() is called with ->completion_lock held and for that
reason we'd want to keep it as small as we can. Instead of doing
__io_req_complete_post() for each linked request under the lock, fail
them in a task_work handler under ->uring_lock.
Signed-off-by: Pavel Begunkov <[email protected]>
---
io_uring/timeout.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index 4af074b8f6b7..2f9e56935479 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -101,32 +101,44 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
spin_unlock_irq(&ctx->timeout_lock);
}
-static void io_fail_links(struct io_kiocb *req)
- __must_hold(&req->ctx->completion_lock)
+static void io_req_tw_fail_links(struct io_kiocb *link, bool *locked)
{
- struct io_kiocb *nxt, *link = req->link;
- bool ignore_cqes = req->flags & REQ_F_SKIP_LINK_CQES;
-
- req->link = NULL;
+ io_tw_lock(link->ctx, locked);
while (link) {
+ struct io_kiocb *nxt = link->link;
long res = -ECANCELED;
if (link->flags & REQ_F_FAIL)
res = link->cqe.res;
-
- nxt = link->link;
link->link = NULL;
+ io_req_set_res(link, res, 0);
+ io_req_task_complete(link, locked);
+ link = nxt;
+ }
+}
- trace_io_uring_fail_link(req, link);
+static void io_fail_links(struct io_kiocb *req)
+ __must_hold(&req->ctx->completion_lock)
+{
+ struct io_kiocb *link = req->link;
+ bool ignore_cqes = req->flags & REQ_F_SKIP_LINK_CQES;
+
+ if (!link)
+ return;
+ while (link) {
if (ignore_cqes)
link->flags |= REQ_F_CQE_SKIP;
else
link->flags &= ~REQ_F_CQE_SKIP;
- io_req_set_res(link, res, 0);
- __io_req_complete_post(link);
- link = nxt;
+ trace_io_uring_fail_link(req, link);
+ link = link->link;
}
+
+ link = req->link;
+ link->io_task_work.func = io_req_tw_fail_links;
+ io_req_task_work_add(link);
+ req->link = NULL;
}
static inline void io_remove_next_linked(struct io_kiocb *req)
--
2.36.1
next prev parent reply other threads:[~2022-06-25 10:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-25 10:52 [PATCH for-next 0/5] random 5.20 patches Pavel Begunkov
2022-06-25 10:52 ` Pavel Begunkov [this message]
2022-06-25 10:52 ` [PATCH for-next 2/5] io_uring: fuse fallback_node and normal tw node Pavel Begunkov
2022-06-25 10:53 ` [PATCH for-next 3/5] io_uring: remove extra TIF_NOTIFY_SIGNAL check Pavel Begunkov
2022-06-25 10:53 ` [PATCH for-next 4/5] io_uring: don't check file ops of registered rings Pavel Begunkov
2022-06-25 10:53 ` [PATCH for-next 5/5] io_uring: remove ctx->refs pinning on enter Pavel Begunkov
2022-06-25 12:49 ` [PATCH for-next 0/5] random 5.20 patches Jens Axboe
2022-06-25 12:49 ` 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=a2f68708b970a21f4e84ddfa7b3abd67a8fffb27.1656153285.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