Most operating systems maintain a disk cache to speed accesses to disk and other storage. The disk cache is simply a region of RAM which stores the most recently accessed blocks from disk. Caching disk has two major benefits:
- Frequently-accessed, rarely-changed parts of disk (such as libraries and even executables) are likely to remain in cache, meaning that they need not be read from disk every time they are needed. Since reading from disk is much slower than accessing RAM, this has the effect of speeding up program loading and the like.
- Blocks that need to be written to disk can be buffered in the cache, and sorted by the kernel into an order that speeds up the actual writing to disk.
A drawback of caching disk writes is that a
function which requests a disk write will return before the data have actually been committed to the physical disk. This means that even after you think you've saved something, if the system
crashes or the
power fails, you may end up with
lost data or
disk corruption. The latter, at least, can be avoided with a
journaling filesystem.