root/src/filemanager/ioblksize.h

/* [previous][next][first][last][top][bottom][index][help]  */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. io_blksize

   1 /* I/O block size definitions for coreutils
   2    Copyright (C) 1989-2016 Free Software Foundation, Inc.
   3 
   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.
   8 
   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.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Include this file _after_ system headers if possible.  */
  18 
  19 /* sys/stat.h will already have been included by system.h. */
  20 #include "lib/stat-size.h"
  21 
  22 /* As of Feb 2024, 256KiB is determined to be the best blksize
  23    to minimize system call overhead across most systems.
  24    This can be tested with this script:
  25 
  26    for i in $(seq 0 10); do
  27      bs=$((1024*2**$i))
  28      printf "%7s=" $bs
  29      timeout --foreground -sINT 2 \
  30        dd bs=$bs if=/dev/zero of=/dev/null 2>&1 \
  31          | sed -n 's/.* \([0-9.]* [GM]B\/s\)/\1/p'
  32    done
  33 
  34    With the results shown for these systems:
  35    system #1: 1.7GHz pentium-m with 400MHz DDR2 RAM, arch=i686
  36    system #2: 2.1GHz i3-2310M with 1333MHz DDR3 RAM, arch=x86_64
  37    system #3: 3.2GHz i7-970 with 1333MHz DDR3, arch=x86_64
  38    system #4: 2.20GHz Xeon E5-2660 with 1333MHz DDR3, arch=x86_64
  39    system #5: 2.30GHz i7-3615QM with 1600MHz DDR3, arch=x86_64
  40    system #6: 1.30GHz i5-4250U with 1-channel 1600MHz DDR3, arch=x86_64
  41    system #7: 3.55GHz IBM,8231-E2B with 1066MHz DDR3, POWER7 revision 2.1
  42    system #8: 2.60GHz i7-5600U with 1600MHz DDR3, arch=x86_64
  43    system #9: 3.80GHz IBM,02CY649 with 2666MHz DDR4, POWER9 revision 2.3
  44    system 10: 2.95GHz IBM,9043-MRX, POWER10 revision 2.0
  45    system 11: 3.23Ghz Apple M1 with 2666MHz DDR4, arch=arm64
  46 
  47                 per-system transfer rate (GB/s)
  48    blksize   #1    #2    #3    #4    #5    #6    #7    #8    #9     10    11
  49    ------------------------------------------------------------------------
  50       1024  .73   1.7   2.6   .64   1.0   2.5   1.3    .9   1.2    2.5   2.0
  51       2048  1.3   3.0   4.4   1.2   2.0   4.4   2.5   1.7   2.3    4.9   3.8
  52       4096  2.4   5.1   6.5   2.3   3.7   7.4   4.8   3.1   4.6    9.6   6.9
  53       8192  3.5   7.3   8.5   4.0   6.0  10.4   9.2   5.6   9.1   18.4  12.3
  54      16384  3.9   9.4  10.1   6.3   8.3  13.3  16.8   8.6  17.3   33.6  19.8
  55      32768  5.2   9.9  11.1   8.1  10.7  13.2  28.0  11.4  32.2   59.2  27.0
  56      65536  5.3  11.2  12.0  10.6  12.8  16.1  41.4  14.9  56.9   95.4  34.1
  57     131072  5.5  11.8  12.3  12.1  14.0  16.7  54.8  17.1  86.5  125.0  38.2
  58  -> 262144  5.7  11.6  12.5  12.3  14.7  16.4  40.0  18.0 113.0  148.0  41.3 <-
  59     524288  5.7  11.4  12.5  12.1  14.7  15.5  34.5  18.0 104.0  153.0  43.1
  60    1048576  5.8  11.4  12.6  12.2  14.9  15.7  36.5  18.2  87.9  114.0  44.8
  61 
  62 
  63    Note that this is to minimize system call overhead.
  64    Other values may be appropriate to minimize file system
  65    or disk overhead.  For example on my current GNU/Linux system
  66    the readahead setting is 128KiB which was read using:
  67 
  68    file="."
  69    device=$(df --output=source --local "$file" | tail -n1)
  70    echo $(( $(blockdev --getra $device) * 512 ))
  71 
  72    However there isn't a portable way to get the above.
  73    In the future we could use the above method if available
  74    and default to io_blksize() if not.
  75  */
  76 
  77 enum
  78 {
  79     IO_BUFSIZE = 256 * 1024
  80 };
  81 
  82 static inline size_t
  83 io_blksize (struct stat sb)
     /* [previous][next][first][last][top][bottom][index][help]  */
  84 {
  85     size_t blksize = ST_BLKSIZE (sb);
  86 
  87     return MAX (IO_BUFSIZE, blksize);
  88 }

/* [previous][next][first][last][top][bottom][index][help]  */