From: Hao Xu <hao.xu@linux.dev>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>,
Pavel Begunkov <asml.silence@gmail.com>,
linux-fsdevel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Luis Chamberlain <mcgrof@kernel.org>,
Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Subject: [PATCH 4/5] io_uring: support nonblock try for splicing from pipe to pipe
Date: Tue, 7 Jun 2022 16:06:18 +0800 [thread overview]
Message-ID: <20220607080619.513187-5-hao.xu@linux.dev> (raw)
In-Reply-To: <20220607080619.513187-1-hao.xu@linux.dev>
From: Hao Xu <howeyxu@tencent.com>
splice() in io_uring is running in a slow way since it fully depends on
io workers. While splicing from pipe to pipe is a simpler case compared
with file to pipe and pipe to file. Let's make it support nonblock
first. This way we get a fast path for splicing fom pipe to pipe.
Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
io_uring/splice.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/io_uring/splice.c b/io_uring/splice.c
index b2cd1044c3ee..650c70e3dde1 100644
--- a/io_uring/splice.c
+++ b/io_uring/splice.c
@@ -88,6 +88,14 @@ int io_splice_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
return __io_splice_prep(req, sqe);
}
+bool io_splice_support_nowait(struct file *in, struct file *out)
+{
+ if (get_pipe_info(in, true) && get_pipe_info(out, true))
+ return true;
+
+ return false;
+}
+
int io_splice(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_splice *sp = io_kiocb_to_cmd(req);
@@ -100,9 +108,6 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(!sp->len))
goto done;
- if (issue_flags & IO_URING_F_NONBLOCK)
- return -EAGAIN;
-
if (sp->flags & SPLICE_F_FD_IN_FIXED)
in = io_file_get_fixed(req, sp->splice_fd_in, issue_flags);
else
@@ -112,6 +117,16 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
goto done;
}
+ if (issue_flags & IO_URING_F_NONBLOCK) {
+ if (io_splice_support_nowait(in, out)) {
+ flags |= SPLICE_F_NONBLOCK;
+ } else {
+ if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
+ io_put_file(in);
+ return -EAGAIN;
+ }
+ }
+
poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
@@ -119,6 +134,9 @@ int io_splice(struct io_kiocb *req, unsigned int issue_flags)
if (!(sp->flags & SPLICE_F_FD_IN_FIXED))
io_put_file(in);
+ if (ret == -EAGAIN)
+ return ret;
+
done:
if (ret != sp->len)
req_set_fail(req);
--
2.25.1
next prev parent reply other threads:[~2022-06-07 8:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 8:06 [RFC 0/5] support nonblock submission for splice pipe to pipe Hao Xu
2022-06-07 8:06 ` [PATCH 1/5] io_uring: move sp->len check up for splice and tee Hao Xu
2022-06-07 8:06 ` [PATCH 2/5] pipe: add trylock helpers for pipe lock Hao Xu
2022-06-07 8:06 ` [PATCH 3/5] splice: support nonblock for splice from pipe to pipe Hao Xu
2022-06-07 8:06 ` Hao Xu [this message]
2022-06-07 21:38 ` [PATCH 4/5] io_uring: support nonblock try for splicing " kernel test robot
2022-06-08 14:18 ` kernel test robot
2022-06-09 2:24 ` kernel test robot
2022-06-07 8:06 ` [PATCH 5/5] io_uring: add file_in in io_splice{} to avoid duplicate calculation Hao Xu
2022-06-07 8:13 ` [RFC 0/5] support nonblock submission for splice pipe to pipe Hao Xu
2022-06-07 9:27 ` Pavel Begunkov
2022-06-08 4:19 ` Hao Xu
2022-06-08 4:31 ` Jens Axboe
2022-06-08 11:33 ` Pavel Begunkov
2022-06-14 13:23 ` Hao Xu
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=20220607080619.513187-5-hao.xu@linux.dev \
--to=hao.xu@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=kuniyu@amazon.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).