我也google了一下,找到一篇比较透彻的.
Write Caching
Caching reads from the hard disk and caching writes to the hard disk are similar insome ways, but very different in others. They are the same in their overall objective: todecouple the fast PC from the slow mechanics of the hard disk. The key difference is thata write involves a
change to the hard disk, while a read does not.
With no write caching, every write to the hard disk involves a performance hit whilethe system waits for the hard disk to access the correct location on the hard disk andwrite the data. As mentioned in
the generaldiscussion of the cache circuitry and operation, this takes at least 10 millisecondson most drives, which is a long time in the computer world and really slows downperformance as the system waits for the
[color=blue ! important][color=blue ! important]hard [color=blue ! important]disk. This mode of operation is called
write-throughcaching. (The contents of the area written actually are put into the cache in case itneeds to be
read again later, but the write to the disk always occurs at the sametime.)
When write caching is enabled, when the system sends a write to the hard disk, thelogic circuit records the write in its much faster cache, and then immediately sends backan acknowledgement to the
[color=blue ! important][color=blue ! important]operating [color=blue ! important]system saying, in essence, "all done!" Therest of the system can then proceed on its merry way without having to sit around waitingfor the actuator to position and the disk to spin, and so on. This is called
write-backcaching, because the data is stored in the cache and only "written back" to theplatters later on.
Write-back functionality of course improves performance. There's a catch however. Thedrive sends back saying "all done" when it really isn't done--the data isn't onthe disk at all, it's only in the cache. The hard disk's logic circuits begin to write thedata to the disk, but of course this takes some time. The hard disk is using a variant ofthat old "the check is in the mail" trick you might hear when you call someoneto remind them of that loan they were supposed to pay back three weeks ago. :^)
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 goesout, its contents are lost. If there were any pending writes in the cache that were notwritten to the disk yet, they are gone forever. Worse, the rest of the system has no wayto know this, because when it is told by the hard disk "all done", it can'treally know what that means. So not only is some data lost, the system doesn't even knowwhich data, or even that it happened. The end result can be file consistency problems,operating system corruption, and so on. (Of course, this problem doesn't affect cachedreads at all. They can be discarded at any time.)
Due to this risk, in some situations write caching is not used at all. This isespecially true for applications where high data integrity is critical. Due to theimprovement in performance that write caching offers, however, it is increasingly beingused despite the risk, and the risk is being mitigated through the use of additionaltechnology. The most common technique is simply ensuring that the power does not go off!In high-end server environments, with their
uninterruptiblepower supplies and even
redundant powersupplies, having unfilled cached writes is much less of a concern. For added peace ofmind, better drives that employ write caching have a "write flush" feature thattells the drive to immediately write to disk any pending writes in its cache. This is acommand that would commonly be sent before the UPS batteries ran out if a powerinterruption was detected by the system, or just before the system was to be shut down forany other reason.