First-In-First-Out Algorithm (FIFO)
The simplest page-replacement algorithm is a first-in, first-out (FIFO) algorithm.
FIFO operates on the principle of evicting the oldest page in memory.
It maintains a queue of pages and replaces the page that entered the
memory earliest, if a new page needs to be brought in.
Advantages
- Easy to understand
- Easy to implement
Detriments
- performance is not always good (e.g. heavily used global variable in first page)
Second Chance Algorithm (SC)
The underlying principle of the Second Chance algorithm is still FIFO replacement.
When a page is selected for eviction however, the Reference Bit is inspected.
The Reference Bit is a bit for a page that is set to 1 by the hardware whenever a page is referenced.
If the value is 0 the page gets replaced, when the value is 1 on the other side,
the page receives a "second chance". Its Reference Bit gets cleared and the next page will be evaluated.
Advantages
- better performance than FIFO
- easier to implement than LRU
Detriments
- degenerates to FIFO replacement if all bits are set
- requires hardware assistance in the form of reference bits
Least Recently Used Algorithm (LRU)
Least Recently Used Algorithm is an approach to imitate the Optimal Algorithm without relying on information for the future.
LRU replaces the least recently used page. It relies on the principle
that pages used in the past are less likely to be used again soon,
making them candidates for replacement.
Advantages
- good performance
- can be implemented on real hardware
Detriments
- harder to implement
- keeping track of page usages requires computational afford or hardware assistance
Optimal Algorithm (OPT)
OPT or MIN, an idealistic algorithm, removes the page that won't be used for
the longest duration in the future. It assumes perfect knowledge of
future references, making it a benchmark for comparison, since it causes the lowest possible number of page faults.
Advantages
- easy to understand
- best performance (least page faults)
- benchmark for other algorithms
Detriments
- impossible to implement on real system (would require knowledge of the future)