summaryrefslogtreecommitdiff
path: root/src/ioblksize.h
diff options
context:
space:
mode:
authorJames Youngman <jay@gnu.org>2011-06-11 16:28:34 +0100
committerJim Meyering <meyering@redhat.com>2011-06-13 12:39:22 +0200
commit5a3879ad03ff926e504b48694d8e589089154369 (patch)
treecda0d0b41e35264578a58d04cb01cd9d44c73a8b /src/ioblksize.h
parente4feb5c03bb4122344050efe75325d432db5791c (diff)
downloadcoreutils-5a3879ad03ff926e504b48694d8e589089154369.tar.xz
maint: use stat-size module from gnulib
* gnulib: Update to latest. * src/system.h: Definitions of ST_* macros have moved into the gnulib module stat-size (specifically, the header file stat-size.h), so remove them from here. * src/truncate.c: Include stat-size.h. * src/stat.c: Likewise. * src/shred.c: Likewise. * src/ls.c: Likewise. * src/du.c: Likewise. * src/ioblksize.h: New file. Move definition of io_blksize out of system.h so that system.h does not have to include stat-size.h. * src/cat.c: Include ioblksize.h. * src/split.c: Likewise. * src/copy.c: Include both stat-size.h and ioblksize.h. * src/Makefile.am (noinst_HEADERS): Add ioblksize.h.
Diffstat (limited to 'src/ioblksize.h')
-rw-r--r--src/ioblksize.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/ioblksize.h b/src/ioblksize.h
new file mode 100644
index 000000000..eaeced30b
--- /dev/null
+++ b/src/ioblksize.h
@@ -0,0 +1,66 @@
+/* I/O block size definitions for coreutils
+ Copyright (C) 1989, 1991-2011 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Include this file _after_ system headers if possible. */
+
+/* sys/stat.h will already have been included by system.h. */
+#include "stat-size.h"
+
+
+/* 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 GNU/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));
+}