23211,23213: Try sliding mmap window over memory file (10MB window), works better...
authorLove Hörnquist Åstrand <lha@kth.se>
Thu, 29 May 2008 03:41:44 +0000 (03:41 +0000)
committerLove Hörnquist Åstrand <lha@kth.se>
Thu, 29 May 2008 03:41:44 +0000 (03:41 +0000)
git-svn-id: svn://svn.h5l.se/heimdal/branches/heimdal-release/heimdal-1-2-branch@23214 ec53bebd-3082-4978-b11e-865c3cabbd6b

appl/ftp/ftp/ftp.c

index 2c58835b00541b9b626ae1024a526bf0bc54ea28..6783555487c95a86e6902830eb25edae8d38d61f 100644 (file)
@@ -579,6 +579,9 @@ copy_stream (FILE * from, FILE * to)
 
 #if defined(HAVE_MMAP) && !defined(NO_MMAP)
     void *chunk;
+    size_t off;
+
+#define BLOCKSIZE (1024 * 1024 * 10)
 
 #ifndef MAP_FAILED
 #define MAP_FAILED (-1)
@@ -590,17 +593,33 @@ copy_stream (FILE * from, FILE * to)
         */
        if (st.st_size == 0)
            return 0;
-       chunk = mmap (0, st.st_size, PROT_READ, MAP_SHARED, fileno (from), 0);
-       if (chunk != (void *) MAP_FAILED) {
-           int res;
-
-           res = sec_write (fileno (to), chunk, st.st_size);
+       off = 0;
+       while (off != st.st_size) {
+           size_t len;
+           ssize_t res;
+
+           len = st.st_size - off;
+           if (len > BLOCKSIZE)
+               len = BLOCKSIZE;
+
+           chunk = mmap (0, len, PROT_READ, MAP_SHARED, fileno (from), off);
+           if (chunk == (void *) MAP_FAILED) {
+               if (off == 0) /* try read if mmap doesn't work */
+                   goto try_read;
+               break;
+           }
+               
+           res = sec_write (fileno (to), chunk, len);
            if (munmap (chunk, st.st_size) < 0)
                warn ("munmap");
            sec_fflush (to);
-           return res;
+           if (res != len)
+               return off;
+           off += len;
        }
+       return off;
     }
+try_read:
 #endif
 
     buf = alloc_buffer (buf, &bufsize,