# Optimum Block Size when dd from a hard drive to another



## overmind (Feb 23, 2010)

Hello

If I want to move FreeBSD to a new hard drive with:


```
dd if=/dev/ad0 of=/dev/ad1 bs=1M
```

What is the optimum size for "bs" ?

If I do not use bs, and leave it default then bs will be 512 bytes and it takes forever. I've used bs=20M but I want to know what is the optimum size for bs when dd-ing from a sata drive to another and also the optimum size when dd-ing from a usb stick to another.

(I'm not interested in other ways to move data to a new hard drive, I'm only interested in cloning.)

thanks and best regards,


----------



## gordon@ (Feb 23, 2010)

I think you'll need to experiment to find the ideal size. I suspect that any sufficient blocksize that takes advantage of a HDD buffer will be "big enough."

My guess would be to use something like 16M or 32M.


----------



## fallen_fbsd (Feb 24, 2010)

My guess is also 32M on modern disks. More can be degradation.


----------



## lme@ (Feb 24, 2010)

And what about USB-Sticks?


----------



## overmind (Feb 24, 2010)

lme@ said:
			
		

> And what about USB-Sticks?



For USB Stick I've used bs=1M, still I don't know which is right value. I guess it depends on if the stick is detected as USB1 or USB2. Anyway, using bs=1M instead of leaving it default (512bytes) improves speed alot.


----------



## Ruler2112 (Feb 24, 2010)

Definitely stick with a power of 2 as a block size for optimal transfer rates.  I'd guess a setting equal to the internal cache size of the drive, but that's just a gut feeling supported by nothing.

If you're serious about finding the optimal rate for a given machine, create an image of a few hundred meg from a CD or something on your drive, copy it a few times, reboot (an important step to eliminate drive caching from the equation), and then [cmd=]dd if=/path/to/filecreated.iso of=/second/drive bs=nM[/cmd] and vary n by factors of 2.  Record the results and you'll soon know the optimal block size.

Note that the vfs.read_max kernel parameter can have a significant impact on disk performance as well, which means that you should find the ideal setting for this parameter before testing the block size.  Remember to use fresh image files (that haven't been read or written in the present boot) or reboot for each test to ensure consistent results.

I've often wondered what I should use as a block size when cloning drives for best performance.  Unfortunately, it's not a simple answer and varies greatly with the specific hardware involved.


----------



## Carpetsmoker (Feb 24, 2010)

I've had good results with a bs of 16M, I get transfer speeds of about 100MB/s as measured by iostat.


----------



## mamalos (Feb 25, 2010)

The fastest results I ever had were always with bs=512k. You should try all of them by letting dd run for a few seconds and then compare the outcome


----------



## overmind (Feb 25, 2010)

and default bs size is 512 bytes and not 512k right?


----------



## mamalos (Feb 25, 2010)

so says the man page.


----------



## sampablokuper (Apr 19, 2012)

I wrote dd-opt, a small utility with the sole function of helping to find the optimal setting for the bs parameter.

Since I'm not a FreeBSD user myself, I'd welcome people trying it out on FreeBSD and submitting patches/refinements/suggestions/etc.


----------



## rfg (Mar 28, 2013)

Where is the sources tarball for that?

I looked but could not find it.


----------



## wblock@ (Mar 28, 2013)

Click on the "Zip" button on the github page.

Notes:

1. This thread is over a year old.
2. http://forums.freebsd.org/showpost.php?p=115526&postcount=9


----------



## rfg (Mar 29, 2013)

> 1. This thread is over a year old.



I am in the habit of arriving fashionably late to every party.

Sorry.


----------

