How to disable hard disk write cache?

Xin Li delphij at delphij.net
Sun Sep 21 09:16:01 UTC 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 9/17/14 11:04 AM, Xu Zhe wrote:
> 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.

You should get consistent I/O results assuming you are doing the right
benchmark, which unfortunately not all benchmarks do.

Doing benchmarks without the on-device caches is interesting but IMHO
not very useful, because it's likely no practical application would do
that.  Traditionally, these write caches are disabled only when you
really care about data durability; with modern technologies, now you
can get affordable low latency and battery/supercapacitor backed
device, for example most enterprise grade SSDs, and use that as your
write-ahead journalling device to cover that gap.

In order to get more consistent results, you may choose a running data
set that is large enough to defeat the cache effect.  The size can be
chosen by doing a sequence of tests and gradually increase your
running set size, and eventually you would find an "inflicting point"
where performance would drop significantly.

Please note that typical hard drive do not offer consistent latency
when you operate on different areas of the drive, and the results
could vary because a lot of factors.  To do meaningful benchmarks,
these factors also need to be considered.

> 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?

Hrm I don't have much thing off hand, but these are defined by the
standards.  Alexander knows much more than I do in this area.

> 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.
> :(

Probably g_bio(9) but the documentation do not have much detail on
driver implementation, and callers of the API expects the driver to do
all the right things.  This is if you want to implement a file system,
where you would go.

But back to your question, if you want to know e.g., "how to disable
write cache on an AHCI connected drive", you would go to the
individual driver's manual, e.g. ada(4).

Cheers,
-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJUHpdOAAoJEJW2GBstM+nsRPwP/1FzatW89mmXIdGPYk9IZ+Bo
Qdlqvtxy0MCZOJQvug3jUKkiKGxr3+7boo1juQCKgMBqfJzPPhwAef3pRDteuPV4
VGTItEYAKWDo8JXnEl07ChAyxYMiCikiTkplaikOOa5gfmPdyPc9/a0myJ9WQDGk
v6D0flS6s4+ZSRolLAMvSRtzpIAnDUIrU4FjJX+D4Mygz1hrHoYigzic3AahCOIm
PhQe1nW6cPOjJASknFSFs450cDrQZ2QeVfH2Kr+K49ULdX+dn7ot3etJ4Fw+EBUN
m66yPpgjssj/LqXS3m7XLJJYOOBy5FAeBrVUKzGQ6FxkfoCG8+kkD7YsQ2CJZPkc
ILLIshVSL35OchuuMJpG9BGcr2BaaUQ23D4d72nIDm+ktsXiLkyD1XbZm7Ze+bR6
aW2KT3t8dU8NhJi8iyoWMS3bksh6lC5k07g8nqAsUNI+vAlKsnbT3cJJuowzbNLc
5Ai6L2+qFIst97BhTWxlpyBWkJM4K2lzB3AhZyc0Y4uXYni4Uj2DPSrC8dxOrp36
rH3SPACSnRP2cyChWQ+vV3l/uNsWM9snqVFAXPrSjmdN0fzN2KzfxnUiK0PtaFyR
DoZcwM590GWYianbmzHFPiVCrsqjS6y2z4GK1SVUEfa9VM2qahWUSHFNap1DC3W6
ab4I5sE2eO3BknRXpoMg
=tb5a
-----END PGP SIGNATURE-----


More information about the freebsd-scsi mailing list