From: Keith Busch <[email protected]>
To: <[email protected]>, <[email protected]>,
<[email protected]>, <[email protected]>
Cc: Keith Busch <[email protected]>
Subject: [PATCH 2/3] io_uring: split req prep and submit loops
Date: Fri, 28 Jul 2023 13:14:48 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
From: Keith Busch <[email protected]>
Do all the prep work up front, then dispatch all synchronous requests at
once. This will make it easier to count batches for plugging.
Signed-off-by: Keith Busch <[email protected]>
---
io_uring/io_uring.c | 26 ++++++++++++++++++--------
io_uring/slist.h | 4 ++++
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 818b2d1661c5e..5434aef0a8ef7 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1082,6 +1082,7 @@ static void io_preinit_req(struct io_kiocb *req, struct io_ring_ctx *ctx)
req->ctx = ctx;
req->link = NULL;
req->async_data = NULL;
+ req->comp_list.next = NULL;
/* not necessary, but safer to zero */
req->cqe.res = 0;
}
@@ -2282,11 +2283,7 @@ static __cold int io_submit_fail_init(const struct io_uring_sqe *sqe,
static inline void io_submit_sqe(struct io_kiocb *req)
{
trace_io_uring_submit_req(req);
-
- if (unlikely(req->flags & (REQ_F_FORCE_ASYNC | REQ_F_FAIL)))
- io_queue_sqe_fallback(req);
- else
- io_queue_sqe(req);
+ io_queue_sqe(req);
}
static int io_setup_link(struct io_submit_link *link, struct io_kiocb **orig)
@@ -2409,6 +2406,9 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
{
struct io_submit_link *link = &ctx->submit_state.link;
unsigned int entries = io_sqring_entries(ctx);
+ struct io_wq_work_node *pos, *next;
+ struct io_wq_work_list req_list;
+ struct io_kiocb *req;
unsigned int left;
int ret, err;
@@ -2419,6 +2419,7 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
io_get_task_refs(left);
io_submit_state_start(&ctx->submit_state, left);
+ INIT_WQ_LIST(&req_list);
do {
const struct io_uring_sqe *sqe;
struct io_kiocb *req;
@@ -2437,9 +2438,12 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
err = io_setup_link(link, &req);
if (unlikely(err))
goto error;
-
- if (likely(req))
- io_submit_sqe(req);
+ else if (unlikely(!req))
+ continue;
+ else if (unlikely(req->flags & (REQ_F_FORCE_ASYNC | REQ_F_FAIL)))
+ io_queue_sqe_fallback(req);
+ else
+ wq_list_add_tail(&req->comp_list, &req_list);
continue;
error:
/*
@@ -2453,6 +2457,12 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
}
} while (--left);
+ wq_list_for_each_safe(pos, next, &req_list) {
+ req = container_of(pos, struct io_kiocb, comp_list);
+ req->comp_list.next = NULL;
+ io_submit_sqe(req);
+ }
+
if (unlikely(left)) {
ret -= left;
/* try again if it submitted nothing and can't allocate a req */
diff --git a/io_uring/slist.h b/io_uring/slist.h
index 0eb194817242e..93fbb715111ca 100644
--- a/io_uring/slist.h
+++ b/io_uring/slist.h
@@ -12,6 +12,10 @@
#define wq_list_for_each_resume(pos, prv) \
for (; pos; prv = pos, pos = (pos)->next)
+#define wq_list_for_each_safe(pos, n, head) \
+ for (pos = (head)->first, n = pos ? pos->next : NULL; \
+ pos; pos = n, n = pos ? pos->next : NULL)
+
#define wq_list_empty(list) (READ_ONCE((list)->first) == NULL)
#define INIT_WQ_LIST(list) do { \
--
2.34.1
next prev parent reply other threads:[~2023-07-28 20:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 20:14 [PATCH 1/3] io_uring: split req init from submit Keith Busch
2023-07-28 20:14 ` Keith Busch [this message]
2023-07-28 20:14 ` [PATCH 3/3] io_uring: set plug tags for same file Keith Busch
2023-07-31 12:53 ` [PATCH 1/3] io_uring: split req init from submit Pavel Begunkov
2023-07-31 21:00 ` Jens Axboe
2023-08-01 14:13 ` Pavel Begunkov
2023-08-01 15:17 ` Keith Busch
2023-08-01 16:05 ` 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 \
[email protected] \
[email protected] \
[email protected] \
[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