12

As in the Windows 7 Disk Policy Options:

[x] Enable Write Caching on the device
[ ] Turn off Windows write-cache buffer flushing on the device 

Is the first the cache on the physical disk, and the second the windows cache?

(I've googled, but didn't find a clear answer).

RTOSkit
  • 578
  • 6
  • 16
peterchen
  • 1,704
  • 5
  • 21
  • 27

4 Answers4

12

See "more information" section from http://support.microsoft.com/kb/332023:

Many disk devices provide enhanced performance through the use of an onboard cache, which provides read-ahead caching for data that is being read from the disk, and write-behind caching (or delayed writes or "lazy" writes) for data that is being written to disk. In some cases, it is important for data to be written to the physical disk immediately, and not retained in the disk's onboard write cache to be written later during an otherwise idle moment. This prevents loss or corruption of this data if the disk or controller (wherever the write cache is implemented) suddenly loses power

Write caching improves disk performance greatly, so leave it on for internal hard drives.

Windows turns write caching Off for flash drives and other usb hard drives by default, normally you do not have to ever modify these settings, Windows takes care of it for you.

sblair
  • 12,617
  • 6
  • 48
  • 77
Moab
  • 58,044
  • 21
  • 113
  • 176
  • 5
    as Moab said. The only reason you may want to consider turning off Write Caching on internal hard disks is if you frequently experience brown-outs or black-outs. but if that is the case then i recommend you invest in a decent UPS and leave write caching on – Xantec Nov 26 '10 at 16:31
  • 1
    Thanks for the link! If I understand it correctly, it means "don't flush even if the software says so". I was mostly curious about the second option, testing build speeds on SSD vs. HDD. Power grid problems are rarity-rare here indeed *pat-pats german engineering*. – peterchen Nov 28 '10 at 09:10
  • 1
    This answer doesn't help me understand the difference between the two settings. If you flush the cache on every write, then you are not caching - in what way is write caching enabled (first check box)? It seems more likely that flushing occurs periodically when the second check box is disabled, or something similar. – Sam Brightman Sep 20 '15 at 11:31
  • 3
    @SamBrightman: as much as *I* understand: The first setting enables the windows cache - if an applications writes to a file, it's not immediately passed on to the disk. An application may call "flush" to force things to be written physically. The second option says: when the application says "flush", Windows will still flush its own cache to the device, but will not tell the device to flush its own internal cache. This neuters the "flush" command (as the application thinks data is safe on disk). Acceptable only if data permanence is not a priority. – peterchen Sep 21 '15 at 10:14
2

I always turn write-behind caching off, all the time, every time. It was a bad idea from the start. I explain it this way: If you click "Save" on your word processing document, and the power fails, with write-behind caching off, your document will not be saved (until autosave kicks in). Turning off write-behind caching forces it to actually write your file to the disk when you click save. The same applies to power outages, BSOD's, program crashes, etc.

CodeLurker
  • 21
  • 1
  • 1
    To round you answer out perhaps you could include how you disable it. Also cite some sources that back up your position. – slm Jan 07 '13 at 04:26
  • 3
    But why does this make a difference? You have precisely the same problem if the power goes out before you click "Save" at all. – David Schwartz Feb 03 '13 at 00:30
  • @DavidSchwartz, the difference is that with caching off, the files is written to disk as soon as you click `[Save]`, so if the power goes out a second later, the file is still there, but with it on, the file is may not be written for a few seconds or minutes, during which time the power could go out, and the file would be lost. – Synetech Sep 16 '13 at 18:44
  • 1
    @CodeLurker, the performance benefits of caching are enough that it is generally worth the rare risk of power loss. Obviously the circumstances will dictate whether it should be used or not such whether power is reliable or not, what types of files are predominantly used, and so on. – Synetech Sep 16 '13 at 18:46
  • 2
    @Synetech That's basically no difference. There's a window in which you can lose data either way, and most of that window is before you click "Save". – David Schwartz Sep 16 '13 at 19:54
  • 4
    You could also lose your data by getting crushed by a falling asteroid a split second before clicking `[Save]`. By your reckoning, you may as well not even bother using a computer at all since it is inevitable to lose your data. ◔_◔ – Synetech Sep 17 '13 at 13:52
0

Both settings relate to the internal disk cache. The first one enables/disables the write cache. The second one is much more interesting and apparently has a slightly different effect on different ATA/ATAPI controllers. Once upon a time I ran an analyzer to intercept Intel Serial ATA Storage Controller commands with default Windows drivers and SATA HDD. With this option enabled, even when Windows flush caches (FlushFileBuffers, CcFlushCache and others), there were no IRB_FUNCTION_ATA_FLUSH and IRB_FUNCTION_ADAPTER_FLUSH commands in the logs, which tells the disk to clear its internal buffer. When the option was disabled, these commands were sent periodically. AMD SATA with native/non-native drivers behaved a little differently. And there are different registry settings. But the fact is that this setting greatly reduces the number of flushes. Also, with any settings, flushing commands are sent before power change and before shutdown.

0

Based on an Old New Thing blog post it sounds like the first one is OS caching and the second one is an override for disk internal caching during flush only.

For normal writes with no flush, the disk internal cache will be used regardless of the second setting. However, for sync/flush events the default behaviour is to ensure that flushing the OS cache actually gets the data onto the media: tell the drive explicitly flush the internal cache too.

It's not clear to me whether turning off the first setting would do this disk flush on every write, or even disable the on-disk cache as well as disabling the OS cache.

Sam Brightman
  • 717
  • 9
  • 24