maint: revert "build: update gnulib submodule to latest"
[coreutils/ericb.git] / src / ioblksize.h
blobeaeced30b523ea1396803c5b8635b23e9ec68d8d
1 /* I/O block size definitions for coreutils
2 Copyright (C) 1989, 1991-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Include this file _after_ system headers if possible. */
19 /* sys/stat.h will already have been included by system.h. */
20 #include "stat-size.h"
23 /* As of Mar 2009, 32KiB is determined to be the minimium
24 blksize to best minimize system call overhead.
25 This can be tested with this script with the results
26 shown for a 1.7GHz pentium-m with 2GB of 400MHz DDR2 RAM:
28 for i in $(seq 0 10); do
29 size=$((8*1024**3)) #ensure this is big enough
30 bs=$((1024*2**$i))
31 printf "%7s=" $bs
32 dd bs=$bs if=/dev/zero of=/dev/null count=$(($size/$bs)) 2>&1 |
33 sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p'
34 done
36 1024=734 MB/s
37 2048=1.3 GB/s
38 4096=2.4 GB/s
39 8192=3.5 GB/s
40 16384=3.9 GB/s
41 32768=5.2 GB/s
42 65536=5.3 GB/s
43 131072=5.5 GB/s
44 262144=5.7 GB/s
45 524288=5.7 GB/s
46 1048576=5.8 GB/s
48 Note that this is to minimize system call overhead.
49 Other values may be appropriate to minimize file system
50 or disk overhead. For example on my current GNU/Linux system
51 the readahead setting is 128KiB which was read using:
53 file="."
54 device=$(df -P --local "$file" | tail -n1 | cut -d' ' -f1)
55 echo $(( $(blockdev --getra $device) * 512 ))
57 However there isn't a portable way to get the above.
58 In the future we could use the above method if available
59 and default to io_blksize() if not.
61 enum { IO_BUFSIZE = 32*1024 };
62 static inline size_t
63 io_blksize (struct stat sb)
65 return MAX (IO_BUFSIZE, ST_BLKSIZE (sb));