dd:如何计算最佳块大小? [英] dd: How to calculate optimal blocksize?
问题描述
运行dd
时如何计算最佳块大小?我已经对其进行了一些研究,但没有发现任何暗示如何实现此目标的信息.
How do you calculate the optimal blocksize when running a dd
? I've researched it a bit and I've not found anything suggesting how this would be accomplished.
我的印象是更大的块大小会导致更快的dd
...是真的吗?
I am under the impression that a larger blocksize would result in a quicker dd
... is this true?
我要dd
在运行带有4GB DDR3 1333mhz RAM的Intel Core i3的盒子上以7200rpm运行的两个相同的500gb Hitachi HDD,因此,我试图找出要使用的块大小. (我要从闪存驱动器启动Ubuntu 10.10 x86,然后从中运行它.)
I'm about to dd
two identical 500gb Hitachi HDDs that run at 7200rpm on a box running an Intel Core i3 with 4GB DDR3 1333mhz RAM, so I'm trying to figure out what blocksize to use. (I'm going to be booting Ubuntu 10.10 x86 from a flash drive, and running it from that.)
推荐答案
最佳块大小取决于各种因素,包括操作系统(及其版本)以及所涉及的各种硬件总线和磁盘.几个类似Unix的系统(包括Linux和至少某些BSD版本)定义了struct stat
中的st_blksize
成员,该成员给出了内核认为的最佳块大小:
The optimal block size depends on various factors, including the operating system (and its version), and the various hardware buses and disks involved. Several Unix-like systems (including Linux and at least some flavors of BSD) define the st_blksize
member in the struct stat
that gives what the kernel thinks is the optimal block size:
#include <sys/stat.h>
#include <stdio.h>
int main(void)
{
struct stat stats;
if (!stat("/", &stats))
{
printf("%u\n", stats.st_blksize);
}
}
最好的方法可能是进行实验:复制一个具有各种块大小和时间的千兆字节. (请记住在每次运行之前清除内核缓冲区高速缓存:echo 3 > /proc/sys/vm/drop_caches
).
The best way may be to experiment: copy a gigabyte with various block sizes and time that. (Remember to clear kernel buffer caches before each run: echo 3 > /proc/sys/vm/drop_caches
).
但是,根据经验,我发现足够大的块大小可以使dd
发挥出色,例如64 KiB和1 MiB之间的差异较小,而4 KiB与64 KiB. (尽管,自从我这样做以来已经有一段时间了.我现在默认情况下使用兆字节,或者只是让dd
选择大小.)
However, as a rule of thumb, I've found that a large enough block size lets dd
do a good job, and the differences between, say, 64 KiB and 1 MiB are minor, compared to 4 KiB versus 64 KiB. (Though, admittedly, it's been a while since I did that. I use a mebibyte by default now, or just let dd
pick the size.)
这篇关于dd:如何计算最佳块大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!