From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH 13/13] io_uring: don't bounce submit_state cachelines
Date: Sun, 16 May 2021 22:58:12 +0100 [thread overview]
Message-ID: <290cb5412b76892e8631978ee8ab9db0c6290dd5.1621201931.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
struct io_submit_state contains struct io_comp_state and so
locked_free_*, that renders cachelines around ->locked_free* being
invalidated on most non-inline completions, that may terrorise caches if
submissions and completions are done by different tasks.
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index a0b3a9c99044..e387ce687f4d 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -298,11 +298,8 @@ struct io_sq_data {
struct io_comp_state {
struct io_kiocb *reqs[IO_COMPL_BATCH];
unsigned int nr;
- unsigned int locked_free_nr;
/* inline/task_work completion list, under ->uring_lock */
struct list_head free_list;
- /* IRQ completion list, under ->completion_lock */
- struct list_head locked_free_list;
};
struct io_submit_link {
@@ -379,6 +376,9 @@ struct io_ring_ctx {
} ____cacheline_aligned_in_smp;
struct io_submit_state submit_state;
+ /* IRQ completion list, under ->completion_lock */
+ struct list_head locked_free_list;
+ unsigned int locked_free_nr;
struct io_rings *rings;
@@ -1184,7 +1184,7 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
init_llist_head(&ctx->rsrc_put_llist);
INIT_LIST_HEAD(&ctx->tctx_list);
INIT_LIST_HEAD(&ctx->submit_state.comp.free_list);
- INIT_LIST_HEAD(&ctx->submit_state.comp.locked_free_list);
+ INIT_LIST_HEAD(&ctx->locked_free_list);
return ctx;
err:
kfree(ctx->dummy_ubuf);
@@ -1587,8 +1587,6 @@ static void io_req_complete_post(struct io_kiocb *req, long res,
* free_list cache.
*/
if (req_ref_put_and_test(req)) {
- struct io_comp_state *cs = &ctx->submit_state.comp;
-
if (req->flags & (REQ_F_LINK | REQ_F_HARDLINK)) {
if (req->flags & (REQ_F_LINK_TIMEOUT | REQ_F_FAIL))
io_disarm_next(req);
@@ -1599,8 +1597,8 @@ static void io_req_complete_post(struct io_kiocb *req, long res,
}
io_dismantle_req(req);
io_put_task(req->task, 1);
- list_add(&req->compl.list, &cs->locked_free_list);
- cs->locked_free_nr++;
+ list_add(&req->compl.list, &ctx->locked_free_list);
+ ctx->locked_free_nr++;
} else {
if (!percpu_ref_tryget(&ctx->refs))
req = NULL;
@@ -1655,8 +1653,8 @@ static void io_flush_cached_locked_reqs(struct io_ring_ctx *ctx,
struct io_comp_state *cs)
{
spin_lock_irq(&ctx->completion_lock);
- list_splice_init(&cs->locked_free_list, &cs->free_list);
- cs->locked_free_nr = 0;
+ list_splice_init(&ctx->locked_free_list, &cs->free_list);
+ ctx->locked_free_nr = 0;
spin_unlock_irq(&ctx->completion_lock);
}
@@ -1672,7 +1670,7 @@ static bool io_flush_cached_reqs(struct io_ring_ctx *ctx)
* locked cache, grab the lock and move them over to our submission
* side cache.
*/
- if (READ_ONCE(cs->locked_free_nr) > IO_COMPL_BATCH)
+ if (READ_ONCE(ctx->locked_free_nr) > IO_COMPL_BATCH)
io_flush_cached_locked_reqs(ctx, cs);
nr = state->free_reqs;
--
2.31.1
next prev parent reply other threads:[~2021-05-16 21:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-16 21:57 [PATCH for-next 00/13] 5.14 cleanups Pavel Begunkov
2021-05-16 21:58 ` [PATCH 01/13] io_uring: improve sqpoll event/state handling Pavel Begunkov
2021-05-16 21:58 ` [PATCH 02/13] io_uring: improve sq_thread waiting check Pavel Begunkov
2021-05-16 21:58 ` [PATCH 03/13] io_uring: remove unused park_task_work Pavel Begunkov
2021-05-16 21:58 ` [PATCH 04/13] io_uring: simplify waking sqo_sq_wait Pavel Begunkov
2021-05-16 21:58 ` [PATCH 05/13] io_uring: get rid of files in exit cancel Pavel Begunkov
2021-05-16 21:58 ` [PATCH 06/13] io_uring: make fail flag not link specific Pavel Begunkov
2021-05-16 21:58 ` [PATCH 07/13] io_uring: shuffle rarely used ctx fields Pavel Begunkov
2021-05-16 21:58 ` [PATCH 08/13] io_uring: better locality for rsrc fields Pavel Begunkov
2021-05-16 21:58 ` [PATCH 09/13] io_uring: remove dependency on ring->sq/cq_entries Pavel Begunkov
2021-05-16 21:58 ` [PATCH 10/13] io_uring: deduce cq_mask from cq_entries Pavel Begunkov
2021-05-16 21:58 ` [PATCH 11/13] io_uring: kill cached_cq_overflow Pavel Begunkov
2021-05-16 21:58 ` [PATCH 12/13] io_uring: rename io_get_cqring Pavel Begunkov
2021-05-16 21:58 ` Pavel Begunkov [this message]
2021-05-24 17:41 ` [PATCH for-next 00/13] 5.14 cleanups 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=290cb5412b76892e8631978ee8ab9db0c6290dd5.1621201931.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