summaryrefslogtreecommitdiff
path: root/src/system.h
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-03-06 22:30:55 +0000
committerPádraig Brady <P@draigBrady.com>2009-03-11 14:19:08 +0000
commit55efc5f3ee485b3e31a91c331f07c89aeccc4e89 (patch)
tree95b9123d558a3583053b103ca8a294a0dcc84464 /src/system.h
parent93f6771e82401f4c88219938602d4f09628301f4 (diff)
downloadcoreutils-55efc5f3ee485b3e31a91c331f07c89aeccc4e89.tar.xz
cat,cp,mv,install,split: Set the minimum IO block size used to 32KiB
This is following on from this change: [02c3dc9d 2008-03-06 cat: use larger buffer sizes ...] which increased the IO block size used by cat by 8 times, but also capped it at 32KiB. * NEWS: Mention the change in behavior. * src/system.h: Add a new io_blksize() function that returns the max of ST_BLKSIZE or 32KiB, as this was seen as a good value for a minimum block size to use to get good performance while minimizing system call overhead. * src/cat.c: Use it. * src/copy.c: ditto * src/split.c: ditto
Diffstat (limited to 'src/system.h')
-rw-r--r--src/system.h50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/system.h b/src/system.h
index ba74da448..dbb4da1ed 100644
--- a/src/system.h
+++ b/src/system.h
@@ -147,6 +147,9 @@ enum
# define D_INO(dp) NOT_AN_INODE_NUMBER
#endif
+/* include here for SIZE_MAX. */
+#include <inttypes.h>
+
/* Get or fake the disk device blocksize.
Usually defined by sys/param.h (if at all). */
#if !defined DEV_BSIZE && defined BSIZE
@@ -218,6 +221,51 @@ enum
# endif
#endif
+/* As of Mar 2009, 32KiB is determined to be the minimium
+ blksize to best minimize system call overhead.
+ This can be tested with this script with the results
+ shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM:
+
+ for i in $(seq 0 10); do
+ size=$((8*1024**3)) #ensure this is big enough
+ bs=$((1024*2**$i))
+ printf "%7s=" $bs
+ dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 |
+ sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p'
+ done
+
+ 1024=734 MB/s
+ 2048=1.3 GB/s
+ 4096=2.4 GB/s
+ 8192=3.5 GB/s
+ 16384=3.9 GB/s
+ 32768=5.2 GB/s
+ 65536=5.3 GB/s
+ 131072=5.5 GB/s
+ 262144=5.7 GB/s
+ 524288=5.7 GB/s
+ 1048576=5.8 GB/s
+
+ Note that this is to minimize system call overhead.
+ Other values may be appropriate to minimize file system
+ or disk overhead. For example on my current linux system
+ the readahead setting is 128KiB which was read using:
+
+ file="."
+ device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1)
+ echo $(( $(blockdev --getra $device) * 512 ))
+
+ However there isn't a portable way to get the above.
+ In the future we could use the above method if available
+ and default to io_blksize() if not.
+ */
+enum { IO_BUFSIZE = 32*1024 };
+static inline size_t
+io_blksize (struct stat sb)
+{
+ return MAX (IO_BUFSIZE, ST_BLKSIZE (sb));
+}
+
/* Redirection and wildcarding when done by the utility itself.
Generally a noop, but used in particular for native VMS. */
#ifndef initialize_main
@@ -228,8 +276,6 @@ enum
#include "timespec.h"
-#include <inttypes.h>
-
#include <ctype.h>
#if ! (defined isblank || HAVE_DECL_ISBLANK)