Description of the hard disk cache

19 April 2007 by Snakefoot | Comment » | Trackback Off
The hard disk is extremely slow compared to physical memory (RAM), but provides lots of storage capacity. Disk caching can be used to speed up the harddisk performance. The disk cache uses RAM to provide quick access to frequently accessed data.

There are different levels of disk caching:
  • Hard disk Cache - Cache is located on the hard disk device and works only with sectors. It allows continuous reading from the disk even if the transfer-bus is busy.
  • Disk controller Cache - Cache is located on the controller card and works only with sectors. It allows reading from disk without using the transfer-bus to contact the hard disk.
  • Operating System Cache - Using RAM as hard disk cache and works on a file level. It allows file access without using the system-bus to contact the disk controller.
  • Vista Readyboost - Cache is placed on high speed USB flash drives, which allows faster seek times and higher constant transfer rate than the HDD. Can deliver a very large and fast hard disk cache, though still slower than RAM.
There are usually two types of disk caching:
  • Read Cache - Allows the hard disk to read data ahead in the background, so the application doesn't have to block while waiting for the data to be read, but gets the data delivered from the cache instead.
  • Write Cache - Allows the hard disk to lazy write data in the background, so the application doesn't have to block while waiting for the data to be written, but enters the cache where it is later written to the hard disk.
How does write caching work?
Disk caching greatly improves disk performance, but there is a drawback to Write caching, as anything written to the cache, which haven't been flushed to the disk will be lost when the power is lost. Most applications are aware of this behavior, and the operating system provides the ability to perform a direct write or flushed write. Write flushing means that the application will wait for the data to be written to disk before continuing, instead of just writing to the cache which completes right away.

Windows 3.11 had a flaw in its flush operation, so it actually just performed a lazy write to the cache when an application performed a flushed write. Several applications was created which was littered with flushed writes, because it performed so well. These applications performed miserable when used on Windows 95, which didn't have this flaw when performing flushed write, and naturally was much slower than just writing to the cache. One could activate the old buggy behavior by with the option to "Disable Synchronous Buffer Commits", which was hidden away in the troubleshooting section.

Later as server environments have become more and more stable with duplicate power supplies and UPS equipment, then the idea of actually ignoring the flush request has become a wish for those where high disk performance is critical. The Windows operating system can convert the following requests to normal I/O requests so the cache buffers are not flushed:
  • Write Through - Performs a write to disk without using the cache. Activated by calling the Windows API WriteFile() with FILE_FLAG_WRITE_THROUGH. Sends a Forced Unit Access (FUA) command to the storage device.
  • Flush Buffers - Tells the disk to flush everything it has in cache. Activated by calling FlushFileBuffers(). Sends a Synchronize Cache (SCSI) or Flush Cache (IDE/ATAPI) command to the storage device.
When to enable write caching?
The promise of increased performance is always nice, but when the price is the risk of dataloss, then one should be very carefull with changing the behavior of these disk requests.

It is not recommended to enable write caching on standard desktop/laptop machine, which can shutdown unexpectedly or freeze/crash because of a software/hardware error.

It is also not recommended to enable write caching when running a Database Management System (DBMS), as these requests are used to create stable commit checkpoints before beginning on a new transaction.

But if having a seperate harddisk for the pagefile or other temporary files, then there can be a performance boost with no cost.
How to configure write caching?
  • Windows 2000 SP3 / XP SP2 - Requires the utility Dskcache.exe to enable Power Protected write cache. More Info MS KB Q811392, MS KB Q332023
  • Windows 2003 / Vista - The option with the misleading name "Enable Advanced Performance", which can be found on the "Policies"-tab for each hard disk device in the "Device Manager" (Have to activate "Optimize for performance" and "Enable write caching on the disk").
  • Windows 7 - The option is called "Turn off Windows write-cache buffer flushing on the device.", which can be found on the "Policies"-tab for each hard disk device in the "Device Manager" (Have to activate "Enable write caching on the device")
More Info MS KB Q324446
More Info Microsoft - Windows Confidential: The Power of Bugs

Related Configure IDE ATA hard disk for best performance

Updated: 10 September 2009

Comments:

Comment by Doolittle - 21 May 2007 @ 7:04 Reply

Hi got another question If I may.

I did a bit of hunting around for info on the Dskcache utility. I downloaded and applied the hotfix that enables Xp to use the utility.
Having trouble finding the file, only option seems to be MS support and it is highly confusing and involves using one of 2 free support questions as far as I can tell.

If you have the file could you give me a link to download or even Email to me?

** Email address removed by moderator **

Pagefile is working like a charm now, (always was I know, but I couldnt see it) I set up a windows controlled pagefile on C:\ the tool you advised me to use tells me it is using just 6 megs of 3 Gb even when I heavily load Ram, so I am happy now.

All the best

Chris

Comment by snakefoot - 21 May 2007 @ 10:25 Reply

Doolittle
If you have the file could you give me a link to download or even Email to me?

I really don’t recommend that you disable the commit-functionality of your disk-system. It will most likely cause you more headache with data-loss than actual performance.

Have found a Windows 2000 hotifx which contains this utility. Can be found at thehotfixshare.net (Windows2000-KB811392-x86-ENU.exe). It should work on Windows XP too (Open it like a compressed file and extract Dskcache.exe).

Pagefile is working like a charm now, (always was I know, but I couldnt see it) I set up a windows controlled pagefile on C:\ the tool you advised me to use tells me it is using just 6 megs of 3 Gb even when I heavily load Ram, so I am happy now.

Glad to hear that the near optimal solution was actually the easy solution.

Comment by Paul Denton - 10 August 2007 @ 13:57 Reply

I’ve been using the “Power Protect”-feature for over a year now without any issues whatsoever. It improves performance by approx. 5% (tested with PCMark05). As long as you have a stable system (and working backups :-)), then there’s no reason to leave the feature disabled IMO.

Comment by Snakefoot - 12 August 2007 @ 18:48 Reply

Paul Denton
As long as you have a stable system (and working backups :-)), then there’s no reason to leave the feature disabled IMO.

Yes this option is useful for certain systems, but it changes the default behavior of the disk system, and for most users this is not something to change blindly, which is why I’m not recommending it.

Comment by PC Tweaks - 28 October 2007 @ 21:08 Reply

The post written by you is quite educating. Thanks.
Sometime back I have written a post regarding improving hard disk speed performance it is based on my own experiment.
You might want to have a look and comment on it.
Thanks in advance. :)

Comment by snakefoot - 29 October 2007 @ 19:38 Reply

PC Tweaks
I have written a post regarding improving hard disk speed performance.
You might want to have a look and comment on it.

Glad you liked my post. I have made a comment on your site about it doesn’t make much sense to allocate memory for Interrupt Request (IRQ), as it is used to send signals during the data transfer not to hold the buffers used for the data transfer.

Also take a look at Why the System.ini Tweak Doesn’t Work

Comment by PC Tweaks - 30 October 2007 @ 21:29 Reply

Hello and thanks for commenting.

As far as I understand, you have the possibility to configure a special buffer whose task is to optimize the memory to better handle the interrupts. This tweak would definitely effective for those who have large amount of data stored on the disk.

I’m going to write another one to SPEED UP SURFING who are using modems, as it’s working great for me. Thanks. :)

Comment by Ricardo - 27 April 2011 @ 2:20 Reply

Good evening.
This thread is really helpfull,however I have a questions:

I have a 3ware 9690 with BBU raid controller running windows 7. I noticed wich write back cache option on software management is interconnected with write back cache under device management tag on windows and vice-versa. However, by default, the second option (turn off windows write cache) is disabled /unchecked.
My question is: Should I enable this option since I have a BBU and seems that this option could make sense just with BBU attached?
There are some relationship between this option and BBU since wich says “unless THIS DEVICE (supposedly raid controller) has a separate power supply”? Could this power supply means BBU?

So, if I check the additional box, didn’t I disable the write journaling of BBU?
I make this question because since I have done experiments with this setting, seems that this box checked does nothing on controller info and alarms ,like a “cache flush device” doesn’t appear…But may be I’m wrong…

Thanks very much,
Regards for all

Leave a comment


NB! Use the Forum for computer help and off-topic questions.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>