我不时被告知要提高“ dd”的速度,我应该仔细选择合适的“块大小”。
即使在此处,在ServerFault上,其他人也写道:“ ...最佳块大小取决于硬件... ” (固有)或“ ...最佳大小将取决于您的系统总线,硬盘驱动器控制器,特定驱动器本身,以及每个驱动程序的驱动程序... “ (chris-s)
由于我的感觉有些不同(顺便说一句:我坚信,对bs参数进行深度调整所需的时间比所节省的时间要长得多,并且默认值是合理的),今天我就去了通过一些肮脏的基准测试。
为了降低外部影响,我决定阅读:
- 从外部MMC卡
- 从内部分区
和:
- 带有相关的文件系统
- 将输出发送到/ dev / null以避免与“写入速度”有关的问题;
- 至少在涉及HDD时避免一些HDD缓存的基本问题。
在下表中,我报告了我的发现,读取了1GB的数据,其中包含不同的“ bs”值(您可以在此消息末尾找到原始数字):
基本上结果是:
MMC:bs = 4(是!4个字节)时,我达到了12MB / s的吞吐量。距离bs = 5及以上的最大值14.2 / 14.3不太远。
硬盘:bs = 10时达到30 MB / s。肯定比默认bs = 512时的95.3 MB低,但是...也很重要。
同样,很明显,CPU的系统时间与bs值成反比(但这听起来很合理,因为bs越低,dd产生的系统调用次数就越高)。
综上所述,现在的问题是:有人可以解释(内核黑客吗?)这种吞吐量涉及的主要组件/系统是什么,是否真的值得努力指定比默认值高的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,0 GB) copiati, 72,7795 s, 14,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,0 GB) copiati, 72,867 s, 14,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,0 GB) copiati, 70,1662 s, 14,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,0 GB) copiati, 70,415 s, 14,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,0 GB) copiati, 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,0 GB) copiati, 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,0 GB) copiati, 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,0 GB) copiati, 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,0 GB) copiati, 164,072 s, 6,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,0 GB) copiati, 81,471 s, 12,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,0 GB) copiati, 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,0 GB) copiati, 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,0 GB) copiati, 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,0 GB) copiati, 10,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,0 GB) copiati, 10,7391 s, 97,6 MB/s
real 0m10.792s
user 0m0.008s
sys 0m1.144s
bs
尺寸暗算速度,而不是在一个单一的问题,15个代码块。占用更少的空间,并且无限快地阅读。一张照片确实是值得thoursand话。
bs=8k count=512K
否则bs=1M count=4K
我不记得2在65536
bs=auto
功能,dd
该功能可以检测并使用设备中的最佳bs参数。