s3:lib/recvfile: make use of F_SETPIPE_SZ and reduce the splice syscalls.
authorStefan Metzmacher <metze@samba.org>
Tue, 5 Mar 2013 08:41:52 +0000 (09:41 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 4 Oct 2016 12:51:52 +0000 (14:51 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/lib/recvfile.c

index e1eb241d7bd8ce168443882d3cc7cad145cb6590..302122db080c0395e755da70d1465ca5516c6773 100644 (file)
@@ -160,6 +160,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;
 
@@ -186,16 +187,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;