How to disable hard disk write cache?

Xu Zhe xzpeter at gmail.com
Wed Sep 17 03:04:49 UTC 2014


于 14-9-16 22:09, Xin Li 写道:
> On 9/16/14 5:36 PM, Xu Zhe wrote:
>> > Hi, all,
>> > 
>> > Does anyone knows how to disable write cache of hard disk?
>> > 
>> > I have found some hints here at Freebsd website:
>> > 
>> > https://www.freebsd.org/doc/handbook/configtuning-disk.html
>> > 
>> > However, this seems only work for ATA devices, what about SAS/NLSAS
>> > devices (Meanwhile, it seems that there is no such sysctl in latest
>> > Freebsd release, which is 10.0)?
>> > 
>> > Any hints are welcomed!
> Why do you want to disable write cache in the first place?  It's not
> needed for most configurations nowadays.
>
> Modern SATA/SAS/SCSI devices usually comes with the capability of
> tagged commands, allowing the OS to know when a write buffer is on
> stable storage.  With this, file systems can easily implement the
> right semantics and recover from e.g. a power outage, etc.
>
> Cheers,
Hi, Xin,

Thanks for the reply.

My final goal is not to disable write cache. I just want to do a simple test
to see how would the IOPS drop when write cache disabled (I suppose without
disk write cache, the value should be the same as IOPS of random read, both
using O_DIRECT flag to avoid system cache, etc.).

Meanwhile, what I really want to know is that, how could I make sure IO is
persistent as long as I got reply from hard disk? Since I suppose all file
systems require this assumption to achieve self consistency.

I have googled about the "tagged command" but only found something related to
TCQ, which mainly talks about the queueing but not anything related to cache
sync. Any more hints?

I saw some pages that mentioned about SATA FUA command support on Linux (Which
I guess is what I am looking for):

https://www.kernel.org/doc/Documentation/block/writeback_cache_control.txt

However, I have not found useful information related to Freebsd. :(

Peter


More information about the freebsd-scsi mailing list