brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dd conv=fdatasync gives a write speed that includes the disk, not just the cache

Disk
~/tips/tip-dd-conv-fdatasync-write-speed

dd if=/dev/zero of=test.bin bs=1M count=1024 conv=fdatasync

Writes a test file and only reports the speed after the data has reached the disk.

A quick write test with dd has a trap. Linux caches writes in memory, so dd can report a speed that is mostly RAM. One operand fixes that.

dd if=/dev/zero of=test.bin bs=1M count=1024 conv=fdatasync
rm test.bin

The GNU manual says conv=fdatasync synchronizes the output data just before finishing, and that this forces a physical write, so the data is preserved even if power is lost. dd only prints its final line after that sync, so the time it reports includes getting the data onto the disk.

With count=64 instead of 1024, coreutils 9.4 printed this on a virtual machine:

64+0 records in
64+0 records out
67108864 bytes (67 MB, 64 MiB) copied, 0.0846841 s, 792 MB/s

That number says something about that virtual disk only, so don’t compare it with another machine. Put the file on the disk you want to measure, for example a path on the array or the cache of a server, and delete it afterwards. A few seconds of writing give a steadier number than a fraction of a second, so I’d start with a count of 1024 or more.

There are two nearby options in the manual. conv=fsync also syncs metadata. oflag=dsync forces a physical write on every single write, which is much stricter and normally much slower, so use it when you care about small synchronous writes.

One caveat: of= is the file dd overwrites. Point it at a new file name in the folder you want to test, never at a device you did not mean to write to.

Further reading: GNU coreutils: dd invocation

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (45) All topics

Link