When physical memory is full and a Page Fault occurs, the operating system must select a "victim" page to evict from RAM and write to the disk. The goal of a page-replacement algorithm is to minimize the total number of page faults.
A bad algorithm will evict a page that the CPU needs immediately in the very next instruction, causing another expensive page fault.
The simplest page-replacement algorithm is FIFO.
Intuitively, you would expect that giving an algorithm more physical RAM frames would decrease the number of page faults. FIFO suffers from Belady's Anomaly: for some access patterns, increasing the number of page frames actually increases the number of page faults.
The Optimal algorithm has the lowest possible page-fault rate of all algorithms and will never suffer from Belady's anomaly.
Since we cannot predict the future (OPT), we can look at the past. LRU assumes that pages that have been used heavily in the recent past will likely be used heavily in the near future.
Because true LRU is too slow to execute on every single memory access, modern operating systems use approximations.
Most computer hardware provides a single Reference Bit for each page table entry. The bit starts at 0. Whenever a page is read or written to, the hardware automatically sets its reference bit to 1.
The Clock Algorithm:
0 (it hasn't been used recently), it is evicted.1 (it has been used recently), the OS gives it a "second chance", sets the bit to 0, and moves the hand to the next page.