# How can I send command to hard disk directly



## coopci (Mar 23, 2009)

Is it possible to send ata commands to a hard disk. I know atacontrol can spindown a disk. But how do I enable/disable write-caching just like "hdparm -W" in linux?


----------



## trev (Mar 23, 2009)

Without write caching, you pay one disk rotation for each sequential write. In workloads with a moderate to high sequential write component, this is an extreme penalty. Also, with caching enabled, the disk does a fair amount of reordering to optimize the total seek and rotational cost of the writes. You give this up when disabling the write cache.

The FreeBSD Handbook also states:

"FreeBSD 4.3 flirted with turning off IDE write caching. This reduced write bandwidth to IDE disks but was considered necessary due to serious data consistency issues introduced by hard drive vendors. The problem is that IDE drives lie about when a write completes. With IDE write caching turned on, IDE hard drives not only write data to disk out of order, but will sometimes delay writing some blocks indefinitely when under heavy disk loads. A crash or power failure may cause serious file system corruption. FreeBSD's default was changed to be safe. Unfortunately, the result was such a huge performance loss that we changed write caching back to on by default after the release."

If after all that, you still want to disable it, then there is a simple sysctl variable to do it. 


```
man ata
```

will reveal all.


----------



## phoenix (Mar 23, 2009)

Write-cache on ATA devices is controlled by sysctl, and can be set at boot via /etc/sysctl.conf, or at runtime via the sysctl command.  The sysctl you want to use is *hw.ata.wc*.  Setting it to 1 enables the write-cache for all ATA disks, and setting it to 0 disables the write-cache for all ATA disks.

Note:  disabling the cache will seriously hamper performance for ATA disks.


----------

