Jan Panteltje wrote:
> On a sunny day (21 Jul 2018 13:11:58 +0100 (BST)) it happened Theo
> wrote in
> :
>
> >(you can do without the 'bs' blocksize setting, but the copy will go a lot
> >more slowly as it'll copy one byte at a time)
>
> Actually 512 bytes at the time,
> and that is often the exact sector size of SDcards,
> so normally no need to specify a bigger blocksize.
> Try it, makes no difference whatsoever, except for reporting perhaps.
> What does make a difference is fast cards, and a fast card reader.
Block size does matter, sometimes rather a lot.
There are two components to this: the syscall overhead and write
amplification. Syscall overhead is the number of times it has to shuttle
back and forth between userland and kernel. On this Mac:
$ dd if=/dev/zero of=/dev/null bs=1m count=1024
1024+0 records in
1024+0 records out
1073741824 bytes transferred in 0.041791 secs (25693158687 bytes/sec)
$ dd if=/dev/zero of=/dev/null bs=1 count=1g
1073741824+0 records in
1073741824+0 records out
1073741824 bytes transferred in 1781.858768 secs (602596 bytes/sec)
(the fans also went up to turbo for that time)
$ dd if=/dev/zero of=/dev/null count=2m
2097152+0 records in
2097152+0 records out
1073741824 bytes transferred in 3.446420 secs (311552811 bytes/sec)
- so if you're copying to an SSD it would make a difference.
(but less so on a Pi, due to its woeful I/O)
However, there's another issue which is write amplification. If you're
using an unbuffered write, which is what /dev/rdisk on Mac is, you'll be
transmitting those 512 byte writes through to the SD card. The SD card
erase block size is probably somewhere 128KB-1MB. If you write a 512 byte
block, what's actually happening is it might read 1MB into a buffer,
overwrite 512 bytes, then write 1MB back to a new block in the flash. So
every 512 byte write amplifies to 1MB. Good SD cards hold some buffering so
they can coalesce such writes but such buffering is costly for the
microcontrollers in the card, so nasty SD cards just write the block back,
doing vastly more work than they needed.
I have here such a nasty 2GB SD card, and I get:
$ sudo dd if=/dev/zero of=/dev/rdisk2 bs=1m
dd: /dev/rdisk2: Input/output error
1929+0 records in
1928+0 records out
2021654528 bytes transferred in 268.585332 secs (7527047 bytes/sec)
$ sudo dd if=/dev/zero of=/dev/rdisk2
dd: /dev/rdisk2: Input/output error
3948545+0 records in
3948544+0 records out
2021654528 bytes transferred in 14503.783763 secs (139388 bytes/sec)
- a factor of 54 slower. By this I would assume that each write is
amplified (roughly) 54 times, and deduce this (small) SD card has a flash
block size of 32KiB.
In case you think the fault is using unbuffered mode, we can run the same
test in buffered mode. It's better than 512 byte blocks unbuffered, but
much worse than 1M unbuffered.
$ sudo dd if=/dev/zero of=/dev/disk2 bs=1m
dd: /dev/disk2: end of device
1929+0 records in
1928+1 records out
2021658624 bytes transferred in 2222.524882 secs (909622 bytes/sec)
$ sudo dd if=/dev/zero of=/dev/disk2
dd: /dev/disk2: end of device
3948545+0 records in
3948544+0 records out
2021654528 bytes transferred in 2711.264947 secs (745650 bytes/sec)
Theo
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|