From: Hao Xu <howeyxu@xxxxxxxxxxx> 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@xxxxxxxxxxx> --- 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