dd writing on USB flash drive causes massive reads
I am currently restoring a usb stick with a dd image, I have previously created. However is noticed very poor write speed around ~7 MB/s although the stick is usually much faster.
After looking around a little, I noticed that a lot of data is being read from the USB drive which explains the poor write performance. Nothing but dd is accessing the device at that time.
Edited atop
line:
sdd: busy 101% | read 18020 | write 613 | MBr/s 7.04 | MBw/s 7.1
I noticed a similar behavior when writing directly to my md array using dd. However when writing to a mounted filesystem with dd, this does not happen.
So my question is why is read from the usb stick when writing directly to the block device and whether this can be prevented to improve write performance?
For me, dd
uses the page cache by default. I think this is normal on systems with page cache. Page cache needs the storage device to be read though, which can cause slow write speed.
For me there are 3 ways of getting around this and getting full speed:
- Set
dd
block size to 4096 or a multiple. (no reads) - Set
dd
block size to a sufficiently large number. For me this was about 1 million and above. I got full speed at about 1 million. (very few reads) - Don't use page cache by giving
dd
parameteroflags=direct
. Setdd
block size to a sufficiently large multiple of 512. For me this was aboutbs=120k
and above. (no reads)
Something to note, on my system block size for all storage devices and page size are 4096 bytes. Found with:
blockdev --getbsz /dev/sd?
getconf PAGESIZE
Also sector size is 512 bytes.
fdisk
and maybe parted
can tell you sector size.