Hello,

I've ran into an issue with using the 'cp' tool.  In short, I was
wondering why the optimal buffer size (as noted in comments) for a
copy is the destination block size (as reported by fstat) instead of
the maximum of the source and destination block sizes.

Imagine the following scenario:

When copying a file from ext2 to a remote filesystem with a block size
of 4MB (instead of ~4K), the copy moves data quickly (in 4MB blocks).

When copying from a remote filesystem with a block size of 4MB to a
filesystem with a 4K blocksize, the copy is *very* slow (using *many*
small 4K blocks).

I realize that using the destination block size can allow for
optimizations for the destination filesystem, but didn't know if that
is necessarily the case.

The attached 1 line patch uses the maximum of the two block sizes and
fixes the problem I'm seeing.  Comments are appreciated.


Best regards,
-Neill.
diff -N -P -r -u coreutils-5.0.91/src/copy.c coreutils-5.0.91-patched/src/copy.c
--- coreutils-5.0.91/src/copy.c 2003-08-30 10:57:32.000000000 -0500
+++ coreutils-5.0.91-patched/src/copy.c 2003-10-30 13:33:17.000000000 -0600
@@ -285,7 +285,8 @@
       goto close_src_and_dst_desc;
     }
 
-  buf_size = ST_BLKSIZE (sb);
+  buf_size = ((ST_BLKSIZE (sb) > ST_BLKSIZE(src_open_sb)) ?
+    ST_BLKSIZE(sb) : ST_BLKSIZE(src_open_sb));
 
 #if HAVE_STRUCT_STAT_ST_BLOCKS
   if (x->sparse_mode == SPARSE_AUTO && S_ISREG (sb.st_mode))
_______________________________________________
Bug-coreutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to