即使在这里,在ServerFault,其他人wrote“……最佳块大小取决于硬件…”(iain)或“……完美的大小将取决于您的系统总线,硬盘控制器,特定的驱动器本身,以及每个人的驱动因素……“(chris-s)
因为我的感觉有点不同(顺便说一下:我认为深度调整bs参数所需的时间远远高于收到的增益,就节省时间而言,默认是合理的),今天我就去了通过一些快速和肮脏的基准.
为了降低外部影响,我决定阅读:
>来自外部MMC卡
>来自内部分区
和:
>与相关的文件系统umounted
>将输出发送到/ dev / null以避免与“写入速度”相关的问题;
>避免HDD缓存的一些基本问题,至少在涉及HDD时.
在下表中,我已经报告了我的发现,用不同的“bs”值读取1GB的数据(您可以在此消息的末尾找到原始数字):
基本上它出来了:
> MMC:bs = 4(是!4字节),达到了12MB / s的吞吐量.我从bs = 5及以上得到的最大值为14.2 / 14.3;
> HDD:bs = 10我达到30 MB / s.肯定低于95.3 MB,默认bs = 512,但……也很重要.
此外,很明显cpu系统时间与bs值成反比(但这听起来很合理,因为bs越低,dd产生的sys调用次数越多).
说完以上所有内容,现在问题是:有人可以解释(内核黑客吗?)这种吞吐量中涉及的主要组件/系统是什么?如果真的值得指定高于默认值的bs?
MMC案例 – 原始数字
BS = 1M
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=1M count=1000 1000+0 record dentro 1000+0 record fuori 1048576000 byte (1,0 GB) copiati,74,1239 s,14,1 MB/s real 1m14.126s user 0m0.008s sys 0m1.588s
BS = 1K
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=1k count=1000000 1000000+0 record dentro 1000000+0 record fuori 1024000000 byte (1,72,7795 s,1 MB/s real 1m12.782s user 0m0.244s sys 0m2.092s
BS = 512
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=512 count=2000000 2000000+0 record dentro 2000000+0 record fuori 1024000000 byte (1,867 s,1 MB/s real 1m12.869s user 0m0.324s sys 0m2.620s
BS = 10
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=10 count=100000000 100000000+0 record dentro 100000000+0 record fuori 1000000000 byte (1,70,1662 s,3 MB/s real 1m10.169s user 0m6.272s sys 0m28.712s
BS = 5
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=5 count=200000000 200000000+0 record dentro 200000000+0 record fuori 1000000000 byte (1,415 s,2 MB/s real 1m10.417s user 0m11.604s sys 0m55.984s
BS = 4
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=4 count=250000000 250000000+0 record dentro 250000000+0 record fuori 1000000000 byte (1,80,9114 s,12,4 MB/s real 1m20.914s user 0m14.436s sys 1m6.236s
BS = 2
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=2 count=500000000 500000000+0 record dentro 500000000+0 record fuori 1000000000 byte (1,161,974 s,6,2 MB/s real 2m41.976s user 0m28.220s sys 2m13.292s
BS = 1
root@iMac-Chiara:/tmp# time dd if=/dev/sdc of=/dev/null bs=1 count=1000000000 1000000000+0 record dentro 1000000000+0 record fuori 1000000000 byte (1,325,316 s,3,1 MB/s real 5m25.318s user 0m56.212s sys 4m28.176s
硬盘盒 – 原始数字
BS = 1
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=1 count=1000000000 1000000000+0 record dentro 1000000000+0 record fuori 1000000000 byte (1,341,461 s,2,9 MB/s real 5m41.463s user 0m56.000s sys 4m44.340s
BS = 2
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=2 count=500000000 500000000+0 record dentro 500000000+0 record fuori 1000000000 byte (1,164,072 s,1 MB/s real 2m44.074s user 0m28.584s sys 2m14.628s
BS = 4
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=4 count=250000000 250000000+0 record dentro 250000000+0 record fuori 1000000000 byte (1,81,471 s,3 MB/s real 1m21.473s user 0m14.824s sys 1m6.416s
BS = 5
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=5 count=200000000 200000000+0 record dentro 200000000+0 record fuori 1000000000 byte (1,66,0327 s,15,1 MB/s real 1m6.035s user 0m11.176s sys 0m54.668s
BS = 10
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=10 count=100000000 100000000+0 record dentro 100000000+0 record fuori 1000000000 byte (1,33,4151 s,29,9 MB/s real 0m33.417s user 0m5.692s sys 0m27.624s
bs = 512(抵消读取,以避免缓存)
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=512 count=2000000 skip=6000000 2000000+0 record dentro 2000000+0 record fuori 1024000000 byte (1,10,7437 s,95,3 MB/s real 0m10.746s user 0m0.360s sys 0m2.428s
bs = 1k(抵消读取,以避免缓存)
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=1k count=1000000 skip=6000000 1000000+0 record dentro 1000000+0 record fuori 1024000000 byte (1,6561 s,96,1 MB/s real 0m10.658s user 0m0.164s sys 0m1.772s
bs = 1k(抵消读取,以避免缓存)
root@iMac-Chiara:/tmp# time dd if=/dev/sda3 of=/dev/null bs=1M count=1000 skip=7000 1000+0 record dentro 1000+0 record fuori 1048576000 byte (1,7391 s,97,6 MB/s real 0m10.792s user 0m0.008s sys 0m1.144s
解决方法
我知道当我复制硬盘时,我通过指定bs = 1M而不是使用bs = 4k或默认值来获得更快的速率.我说速度提高了30%到300%.除非你每天都在做,否则没有必要把它调到绝对最佳状态.但是选择比默认值更好的东西可以缩短执行时间.
当你真正使用它时尝试一些不同的数字并向dd进程发送一个SIGUSR1信号,让它发出一个状态报告,这样你就可以看到它是怎么回事.
✗ killall -SIGUSR1 dd 1811+1 records in 1811+1 records out 1899528192 bytes (1.9 GB,1.8 GiB) copied,468.633 s,4.1 MB/s