How can we afford to grow the pie?

Write-Read-Verify on FreeBSD 13 with camcontrol instead of hdparm -R

Originally written .
Last updated .
See revision history below.

Hard disk drives (HDDs) can only really catch bad disk sectors during read-time and not during write-time, according to [source 2]. Furthermore, catching bad disk sectors is more easily corrected, if the disk controller still knows what data should go into the broken sector.

ATA8 feature write-read-verify (WRV) seems to offer a solution on the HDDs that support it. The disk controller reads sectors back that were just written and compares them to the write cache. It still knows what data it should be seeing and can compare to what it is actually seeing. The price is higher latency, sometimes even double the latency. The upside is that S.M.A.R.T. error counts and OpenZFS read-error accounting might be triggered early. On the whole, this seems to eliminate fragility in long-term data storage.

Commands and arguments of interest

Assumptions: SATA hard disk drive (HDD) on FreeBSD 13 named ada0. Sufficient privileges like root privileges must be available. For SAS or SCSI drives instead of SATA, see [source 3], instead. For Linux instead of FreeBSD, see hdparm(1) with option -R, instead.


To activate desirable write-read-verify (WRV) level 0 run the following snippet at the command line:

camcontrol cmd ada0 -a "EF 0b 00 00 00 00 00 00 00 00 00 00" -v ;

To activate write-read-verify (WRV) level 2 run the following snippet at the command line:

camcontrol cmd ada0 -a "EF 0b 02 00 00 00 00 00 00 00 00 00" -v ;

To deactivate write-read-verify (WRV) run the following snippet at the command line:

camcontrol cmd ada0 -a "EF 8b 00 00 00 00 00 00 00 00 00 00" -v ;

To read, check availability of and validate the setting of SATA feature write-read-verify (WRV) run one of the following snippets at the command line:

  1. camcontrol identify ada0 ;
  2. smartctl --identify=wb /dev/ada0 ;
and look for the line beginning with string "write-read-verify".

Sources

  1. https://unix.stackexchange.com/questions/364468/how-can-i-do-disk-surface-scanning-and-fix-reallocate-bad-sectors-in-linux-from
  2. https://serverfault.com/questions/104417/how-do-i-easily-repair-a-single-unreadable-block-on-a-linux-disk/431051#431051
  3. https://altechnative.net/enabling-write-read-verify-feature-on-disks/
  4. https://wiki.osdev.org/ATA_Command_Matrix
  5. https://forums.freebsd.org/threads/camcontrol-error-sending-command.35548/
  6. https://cgit.freebsd.org/src/tree/sys/sys/ata.h
  7. https://cgit.freebsd.org/src/tree/sbin/camcontrol/camcontrol.c?id=98d03dca9ac8e3eb5857c72768e200e2bb0c3800
  8. https://cgit.freebsd.org/src/tree/sys/cam/ata/ata_all.c
  9. man 8 camcontrol (search for string "cmd")
  10. https://www.pcreview.co.uk/threads/write-read-verify-performance-penalty.3886107/

Revision history

Revision history
DateNotes
Add smartctl --identify=wb call and reference to ATA8 standard.
Original writeup.