From ea7d8123fb89d29e5b48c36271eac1c852574f45 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 5 Mar 2013 09:41:52 +0100 Subject: [PATCH] s3:lib/recvfile: make use of F_SETPIPE_SZ and reduce the splice syscalls. Signed-off-by: Stefan Metzmacher --- source3/lib/recvfile.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/source3/lib/recvfile.c b/source3/lib/recvfile.c index c53ba77..e2c16df 100644 --- a/source3/lib/recvfile.c +++ b/source3/lib/recvfile.c @@ -145,6 +145,7 @@ ssize_t sys_recvfile(int fromfd, { static int pipefd[2] = { -1, -1 }; static bool try_splice_call = false; + static size_t chunk_size = 16384; size_t total_written = 0; loff_t splice_offset = offset; @@ -171,16 +172,29 @@ ssize_t sys_recvfile(int fromfd, count); } - if ((pipefd[0] == -1) && (pipe(pipefd) == -1)) { - try_splice_call = false; - return default_sys_recvfile(fromfd, tofd, offset, count); + if (pipefd[0] == -1) { + int ret; + + ret = pipe(pipefd); + if (ret == -1) { + try_splice_call = false; + return default_sys_recvfile(fromfd, tofd, offset, count); + } + +#ifdef F_SETPIPE_SZ + fcntl(pipefd[1], F_SETPIPE_SZ, 1048576); + ret = fcntl(pipefd[1], F_GETPIPE_SZ); + if (ret > chunk_size) { + chunk_size = ret; + } +#endif } while (count > 0) { int nread, to_write; nread = splice(fromfd, NULL, pipefd[1], NULL, - MIN(count, 16384), SPLICE_F_MOVE); + MIN(count, chunk_size), SPLICE_F_MOVE); if (nread == -1) { if (errno == EINTR) { continue; -- 1.7.9.5