Page replacement (source code)

= Page replacement

Choosing a resident <memory page> to evict when another <memory page> needs an occupied <page frame>. An unused <page frame> needs no eviction. A <dirty memory page> requires preservation before reuse, accounted for separately as <page writeback>. A <page replacement> policy balances likely future reuse against the overhead of tracking past <memory references>.

The opportunity comes from <temporal locality>: retaining a recently accessed <memory page> can spare a later nonresident <page fault>. <Spatial locality> helps consecutive accesses reuse the same <memory page> until they cross its boundary. A <working set> describes recent demand, while the <resident set> describes what is actually present. A small active footprint can fit in the available <page frames> even when the whole <address space> cannot. These are useful workload tendencies, not guarantees about future <memory references>.<Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others/Beyond Physical Memory: Policies>[Section 22.5, pp. 7–8, and the Types of Locality aside on p. 8: recent use motivates retention, but locality is a heuristic]{ref}

The <page-reference trace> below uses the counterexample discussed in <Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others> (chapter 22, p. 5) and makes the decisions explicit. <FIFO page replacement> ranks arrival time, <LRU replacement> ranks last access, <CLOCK page replacement> samples recent use, and <optimal page replacement> knows the remaining <sequence> in advance. Count misses first; <page-replacement cost accounting> separately counts <page writeback> and explains why fewer misses need not mean less total service time.

// Destination: computer-science.bigb