Page cache
Transparent cache for disk pages in main memory.
A page cache, also known as a disk cache, is a hidden memory buffer that stores data from a hard drive or solid-state drive. The operating system fills this cache using spare main memory (RAM), which speeds up access to cached content and boosts overall system performance. This mechanism is built into kernels that manage memory through paging, and applications usually don’t need to know it exists.
By default, any physical memory not directly assigned to applications is used for the page cache. Since this memory would otherwise sit idle and can be reclaimed whenever an application needs it, there’s generally no performance downside, and the OS may even count it as “free” or “available” memory. Because reading from or writing to a hard drive is much slower than accessing RAM—especially for random data, which requires mechanical seeks—having more RAM allows more data to be cached, improving speed. Hardware-based disk caching (like a disk buffer on the drive itself or RAM in a disk array controller) is separate and should not be confused with the page cache. The operating system may also use some main memory as a filesystem write buffer, sometimes called a page buffer.
Pages in the cache that have been changed after loading are called dirty pages. Non-dirty pages already have identical copies on the disk, so discarding them to free up space is much faster than paging out application memory. This is often preferred over flushing dirty pages to disk first. Executable files (applications and libraries) are typically accessed through the page cache and mapped into process memory using virtual memory (via the `mmap` system call on Unix-like systems). This allows separate processes to share the same binary data, and unused parts of those binaries can eventually be removed from main memory, saving space.
Because cached pages can be easily evicted and reused, some operating systems—notably Windows NT—report page cache usage as “available” memory, even though it’s actually allocated to disk pages. This has caused confusion about how Windows uses its page cache.
The page cache also helps with writing to disk. When data is written, the system checks if the relevant page is already in the cache. If it is, the write happens directly to that page in RAM.
Lore & Background
The page cache is maintained by the operating system using physical memory not directly allocated to applications. Since such memory would otherwise be idle and is easily reclaimed when applications request it, there is generally no associated performance penalty, and the operating system might even report such memory as 'free' or 'available'. Pages in the page cache that have been modified after being brought in are called dirty pages. Non-dirty pages have identical copies in secondary storage, so discarding and reusing their space is quicker than paging out application memory and is often preferred over flushing dirty pages.
Executable binaries, such as applications and libraries, are typically accessed through the page cache and mapped to individual process spaces using virtual memory (via the mmap system call on Unix-like operating systems). This allows binary files to be shared between separate processes and unused parts of binaries to be flushed out of main memory eventually, leading to memory conservation. Some operating systems, notably Windows NT, report page cache usage as 'available' memory while the memory is actually allocated to disk pages, which has led to some confusion about utilization of the page cache in Windows.
The page cache also aids in writing to disk. When a file write occurs, the cached page for the particular block is looked up; if found, the write is done to that page in main memory. If not found and the write falls perfectly on page size boundaries, the page is allocated and immediately marked dirty without being read from disk. Otherwise, pages are fetched from disk and modifications are done. Not all cached pages can be written to, as program code is often mapped as read-only or copy-on-write; in the latter case, modifications to code are visible only to the process itself and are not written to disk.
Reader's Guide
The page cache is a fundamental component of modern operating systems, bridging the speed gap between main memory and secondary storage. By caching disk pages in otherwise unused RAM, it significantly improves access times for frequently used data and executable binaries, while remaining transparent to applications. Its design allows memory to be reclaimed quickly when needed, avoiding performance penalties. The page cache also facilitates efficient disk writes by buffering modifications in memory and marking pages as dirty before flushing them to disk. This mechanism is distinct from hardware disk caches (such as disk buffers or array controller caches), which use dedicated RAM or NVRAM. The page cache's role in sharing executable binaries across processes and enabling memory conservation through eviction of unused pages has made it a standard feature in kernels with paging memory management. However, its implementation has also introduced security concerns, as demonstrated by side-channel attacks that exploit cache presence monitoring to bypass privilege separation and exfiltrate data about other processes.
Did You Know?
- The page cache is sometimes also called a disk cache.
- Dirty pages in the page cache have been modified after being brought in and must be flushed to disk before they can be freed.
- Executable binaries are typically accessed through the page cache and mapped to process spaces using virtual memory.
- In 2019, security researchers demonstrated side-channel attacks against the page cache that can bypass privilege separation.
More in Computer Storage, Part 3 1-24
Spotted an error? Know more?
Reader corrections go straight into our review queue. Suggest an edit · How this site is sourced
