io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, io-uring@vger.kernel.org
Subject: [PATCH 14/14] io_uring: save atomic dec for inline executed reqs
Date: Tue, 19 Jan 2021 13:32:47 +0000	[thread overview]
Message-ID: <300674e8a1a53566f4ed10b0cafb44faf595d1be.1611062505.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1611062505.git.asml.silence@gmail.com>

When a request is completed with comp_state, its completion reference
put is deferred to io_submit_flush_completions(), but the submission
is put not far from there, so do it together to save one atomic dec per
request. That targets requests that complete inline, e.g. buffered rw,
send/recv.

Proper benchmarking haven't been conducted but for nops(batch=32) it was
around 7901 vs 8117 KIOPS (~2.7%), or ~4% per perf profiling.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 1e46d471aa76..fb4e2a97e4f3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -618,6 +618,7 @@ enum {
 	REQ_F_NO_FILE_TABLE_BIT,
 	REQ_F_WORK_INITIALIZED_BIT,
 	REQ_F_LTIMEOUT_ACTIVE_BIT,
+	REQ_F_COMPLETE_INLINE_BIT,
 
 	/* not a real bit, just to check we're not overflowing the space */
 	__REQ_F_LAST_BIT,
@@ -661,6 +662,8 @@ enum {
 	REQ_F_WORK_INITIALIZED	= BIT(REQ_F_WORK_INITIALIZED_BIT),
 	/* linked timeout is active, i.e. prepared by link's head */
 	REQ_F_LTIMEOUT_ACTIVE	= BIT(REQ_F_LTIMEOUT_ACTIVE_BIT),
+	/* completion is deferred through io_comp_state */
+	REQ_F_COMPLETE_INLINE	= BIT(REQ_F_COMPLETE_INLINE_BIT),
 };
 
 struct async_poll {
@@ -1899,14 +1902,15 @@ static void io_submit_flush_completions(struct io_comp_state *cs)
 		 * io_free_req() doesn't care about completion_lock unless one
 		 * of these flags is set. REQ_F_WORK_INITIALIZED is in the list
 		 * because of a potential deadlock with req->work.fs->lock
+		 * We defer both, completion and submission refs.
 		 */
 		if (req->flags & (REQ_F_FAIL_LINK|REQ_F_LINK_TIMEOUT
 				 |REQ_F_WORK_INITIALIZED)) {
 			spin_unlock_irq(&ctx->completion_lock);
-			io_put_req(req);
+			io_double_put_req(req);
 			spin_lock_irq(&ctx->completion_lock);
 		} else {
-			io_put_req(req);
+			io_double_put_req(req);
 		}
 	}
 	io_commit_cqring(ctx);
@@ -1922,8 +1926,7 @@ static void io_req_complete_state(struct io_kiocb *req, long res,
 	io_clean_op(req);
 	req->result = res;
 	req->compl.cflags = cflags;
-	list_add_tail(&req->compl.list, &cs->list);
-	cs->nr++;
+	req->flags |= REQ_F_COMPLETE_INLINE;
 }
 
 static inline void __io_req_complete(struct io_kiocb *req, long res,
@@ -6537,9 +6540,9 @@ static void __io_queue_sqe(struct io_kiocb *req, struct io_comp_state *cs)
 			io_queue_linked_timeout(linked_timeout);
 	} else if (likely(!ret)) {
 		/* drop submission reference */
-		if (cs) {
-			io_put_req(req);
-			if (cs->nr >= 32)
+		if (req->flags & REQ_F_COMPLETE_INLINE) {
+			list_add_tail(&req->compl.list, &cs->list);
+			if (++cs->nr >= 32)
 				io_submit_flush_completions(cs);
 			req = NULL;
 		} else {
-- 
2.24.0


  parent reply	other threads:[~2021-01-19 14:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19 13:32 [PATCH for-next 00/14] mostly cleanups for 5.12 Pavel Begunkov
2021-01-19 13:32 ` [PATCH 01/14] io_uring: optimise io_rw_reissue() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 02/14] io_uring: refactor io_resubmit_prep() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 03/14] io_uring: cleanup personalities under uring_lock Pavel Begunkov
2021-01-19 13:32 ` [PATCH 04/14] io_uring: inline io_async_submit() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 05/14] io_uring: inline __io_commit_cqring() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 06/14] io_uring: further deduplicate #CQ events calc Pavel Begunkov
2021-01-19 13:32 ` [PATCH 07/14] io_uring: simplify io_alloc_req() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 08/14] io_uring: remove __io_state_file_put Pavel Begunkov
2021-01-19 13:32 ` [PATCH 09/14] io_uring: deduplicate failing task_work_add Pavel Begunkov
2021-01-19 13:32 ` [PATCH 10/14] io_uring: don't block resource recycle by oveflows Pavel Begunkov
2021-01-19 22:59   ` Jens Axboe
2021-01-19 23:08     ` Pavel Begunkov
2021-01-19 13:32 ` [PATCH 11/14] io_uring: add a helper timeout mode calculation Pavel Begunkov
2021-01-19 13:32 ` [PATCH 12/14] io_uring: help inlining of io_req_complete() Pavel Begunkov
2021-01-19 13:32 ` [PATCH 13/14] io_uring: don't flush CQEs deep down the stack Pavel Begunkov
2021-01-19 13:32 ` Pavel Begunkov [this message]
2021-01-19 23:01 ` [PATCH for-next 00/14] mostly cleanups for 5.12 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=300674e8a1a53566f4ed10b0cafb44faf595d1be.1611062505.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).