From: luhongfei <luhongfei@vivo.com>
To: Jens Axboe <axboe@kernel.dk>,
Pavel Begunkov <asml.silence@gmail.com>,
io-uring@vger.kernel.org (open list:IO_URING),
linux-kernel@vger.kernel.org (open list)
Cc: opensource.kernel@vivo.com, luhongfei <luhongfei@vivo.com>
Subject: [PATCH] io_uring: Optimization of buffered random write
Date: Wed, 19 Apr 2023 17:22:33 +0800 [thread overview]
Message-ID: <20230419092233.56338-1-luhongfei@vivo.com> (raw)
The buffered random write performance of io_uring is poor
due to the following reason:
By default, when performing buffered random writes, io_sq_thread
will call io_issue_sqe writes req, but due to the setting of
IO_URING_F_NONBLOCK, req is executed asynchronously in iou-wrk,
where io_wq_submit_work calls io_issue_sqe completes the write req,
with issue_flag as IO_URING_F_UNLOCKED | IO_URING_F_IOWQ,
which will reduce performance.
This patch will determine whether this req is a buffered random write,
and if so, io_sq_thread directly calls io_issue_sqe(req, 0)
completes req instead of completing it asynchronously in iou wrk.
Performance results:
For fio the following results have been obtained with a queue depth of
8 and 4k block size:
random writes:
without patch with patch libaio psync
iops: 287k 560k 248K 324K
bw: 1123MB/s 2188MB/s 970MB/s 1267MB/s
clat: 52760ns 69918ns 28405ns 2109ns
Signed-off-by: luhongfei <luhongfei@vivo.com>
---
io_uring/io_uring.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
mode change 100644 => 100755 io_uring/io_uring.c
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 4a865f0e85d0..64bb91beb4d6
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -2075,8 +2075,23 @@ static inline void io_queue_sqe(struct io_kiocb *req)
__must_hold(&req->ctx->uring_lock)
{
int ret;
+ bool is_write;
- ret = io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_COMPLETE_DEFER);
+ switch (req->opcode) {
+ case IORING_OP_WRITEV:
+ case IORING_OP_WRITE_FIXED:
+ case IORING_OP_WRITE:
+ is_write = true;
+ break;
+ default:
+ is_write = false;
+ break;
+ }
+
+ if (!is_write || (req->rw.kiocb.ki_flags & IOCB_DIRECT))
+ ret = io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_COMPLETE_DEFER);
+ else
+ ret = io_issue_sqe(req, 0);
/*
* We async punt it if the file wasn't marked NOWAIT, or if the file
--
2.39.0
next reply other threads:[~2023-04-19 9:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 9:22 luhongfei [this message]
2023-04-19 13:32 ` [PATCH] io_uring: Optimization of buffered random write Jens Axboe
2023-04-19 14:11 ` Jens Axboe
2023-04-19 19:26 ` kernel test robot
2023-04-19 21:30 ` kernel test robot
2023-04-19 21:40 ` 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=20230419092233.56338-1-luhongfei@vivo.com \
--to=luhongfei@vivo.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=opensource.kernel@vivo.com \
/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).