...

/

The Linux Virtual Memory System: The Page Cache

The Linux Virtual Memory System: The Page Cache

In this lesson, you'll learn how the Linux​ page cache stores data and uses the 2Q replacement policy to free up space.

To reduce costs of accessing persistent storage (the focus of the third part of this course), most systems use aggressive caching subsystems to keep popular data items in memory. Linux, in this regard, is no different than traditional operating systems.

How linux page cache works

The Linux page cache is unified, keeping pages in memory from three primary sources: memory-mapped files, file data and metadata from devices (usually accessed by directing read() and write() calls to the file system), and heap and stack pages that comprise each process (sometimes called anonymous memory, because there is no named file underneath of it, but rather swap space). These entities are kept in a page cache hash table, allowing for quick lookup when said data is needed.

The page cache tracks if entries are clean (read but not updated) or dirty (a.k.a., modified). Dirty data is periodically written to the backing store (i.e., to a specific file for file data, or to swap space for anonymous regions) by background threads (called pdflush ...