Daddy Bob

DADDY BOB'S COMPUTER Q & A

Hard Drive Caching

To download this article in
MS Word format, click HERE

By default, disk caching is turned on when most operating systems are installed. Caching occurs in both the reads from, and writes to the hard drive. These two caching events are similar in some ways, but very different in others. They are the same in their overall objective: to untie the fast PC from the slow mechanics of the hard disk. The key difference is that a write involves a change to the hard disk, while a read does not.

With no write caching enabled, every write to the hard disk involves a performance hit while the system waits for the hard disk to access the correct location on the hard disk and write the data. This can takes at least 10-100 milliseconds on the fastest drives, which is an eternity in the computer world and really slows down performance as the system waits for the hard disk. This mode of operation without a cache used is called write-through caching. The write to the disk occurs as soon as the hard drive is positioned to receive it. This time can be much longer on some hard drives.

When write caching is enabled, and the system sends a write to the hard disk, the logic circuit in the hard drive stores the data in its much faster cache memory, and then immediately sends back an acknowledgement to the operating system saying, "all done!" The rest of the system can then proceed on its other business without having to sit around waiting for the hard drive to position the read/write arm, the disk to spin, and so on. This is called write-back caching, because the data is stored in the cache and only "written back" to the drive later on.

Write-back functionality of course improves performance. There's a catch however. The drive tells a little white lie when it sends back "all done" because it really isn’t. The data isn't on the disk at all, it's only in the cache. The hard disk's logic circuits begin to write the data to the disk, but of course this takes some time. It is sort of the old “The checks in the mail” routine.

Now, this isn't really a problem most of the time, as long as the power stays on. Since cache memory is volatile, if the power goes out, its contents are lost. So, any data in the cache waiting to be written can be lost. Adding to the problem, the rest of the system has no way to know this, because it believed the hard drive when it said it was done. So not only is some data lost, the system doesn't even know which data, or even that it happened. The end result can be corrupt files, which in the worse case, can prevent the computer from booting back up when the power is restored.

At one time, write caching wasn’t used because of the possible of loosing data. But it is increasingly being used despite the risk, as the risk is being greatly reduced through the use of newer technology. The most common technique is simply ensuring that the power does not go off by using a UPS, Uninterruptible Power Supply.

For added peace of mind, most current drives have a "write flush" feature that tells the drive to immediately write to disk any data held in its cache. This is a command that is sent just before the system shuts down for any reason. The power supply normally takes the 120V household voltage, and reduces it to 5 and 12V for the hard drive. When the 120 power is interrupted, there is sufficient residual power stored in the power supply's filter capacitors to continue to supply the 5 and 12 volts to the hard drive for a long enough time for the cache to be flushed, and the data written to the hard drive.

To download this article in
MS Word format, click HERE

Disclaimer:

The materials in this site are provided "as is" and without warranties of any kind, either express or implied. To the fullest extent permissible pursuant to applicable law, I disclaim all warranties, express or implied, including, but not limited to, implied warranties of merchantability and fitness for a particular purpose. I do not warrant that the functions contained in the materials on this site will be uninterrupted or error-free, that defects will be corrected, or that any site or the servers that make such materials available are free of viruses, spyware, adware, or other harmful components, although all efforts have been made to assure that they are. I do not warrant or make any representations regarding the use or the results of the use of the materials on this site in terms of their correctness, accuracy, reliability, or otherwise. You assume the entire cost of all necessary servicing, repair, or correction. Applicable law may not allow the exclusion of implied warranties, so the above exclusion may not apply to you.