OMV has flagged one of the hard drives in my Dell Optiplex SFF Plus 7010 due to some bad sectors. It’s a WD RED 4TB (WD40EFRX-68WT0N0), and in the process of investigating it, I realized that the write-cache had not been enabled!
root@omv:~# hdparm -W /dev/sda1
write-caching = 0 (off)
Let’s run some quick performance tests on my sda1 drive to check on the behaviour before and after!
Initial test:
root@omv:~# time dd if=/dev/sda1 of=testfile bs=4k count=262144 conv=fdatasync status=progress
924835840 bytes (925 MB, 882 MiB) copied, 6 s, 154 MB/s1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.92873 s, 155 MB/s
262144+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.26854 s, 148 MB/s
real 0m7.275s
user 0m0.187s
sys 0m1.719s
There are a few steps to enable the write-cache. First, we clear the Smart Command Transport (SCT) override, which usually disables the cache if the drive was ever connected to a RAID controller (like mine had been):
smartctl -s wcache-sct,ata,p /dev/sda1
Next, enable the write-cache and check the value:
root@omv:~# hdparm -W1 /dev/sda1 && hdparm -W /dev/sda1
write-caching = 1 (on)
Debian resets hdparm modifications upon reboot. To ensure the write cache stays enabled, update the local boot script or configuration file:
nano /etc/hdparm.conf
Add this code to the end of the file:
/dev/sda1 {write_cache = on}
Save and exit, then reboot.
After:
root@omv:~# time dd if=/dev/sda1 of=testfile bs=4k count=262144 conv=fdatasync status=progress
924835840 bytes (925 MB, 882 MiB) copied, 6 s, 154 MB/s1073741824 bytes (1.1 GB, 1.0 GiB) copied, 6.92873 s, 155 MB/s
262144+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.26854 s, 148 MB/s
real 0m7.275s
user 0m0.187s
sys 0m1.719s
Wait, that’s not any better! Let’s re-run the test:
root@omv:~# time dd if=/dev/sda1 of=testfile bs=4k count=262144 conv=fdatasync status=progress
262144+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.841775 s, 1.3 GB/s
real 0m0.897s
user 0m0.023s
sys 0m0.583s
Much better!