Compare FIFO, LRU and Optimal page replacement.
MediumConceptPage Replacement & Thrashing
Answer
When a page fault occurs and no frame is free, the OS must evict (remove) a page from RAM. The page-replacement algorithm chooses which one.
- FIFO (First-In, First-Out): evict the page that has been in memory the longest. It is simple (a queue), but it may evict a heavily used page, and it suffers from Belady's anomaly.
- LRU (Least Recently Used): evict the page that has not been used for the longest time, using the recent past to predict the future. It performs close to optimal but is costly to track exactly on every memory access.
- Optimal (OPT): evict the page that will not be used for the longest time in the future. It gives the fewest possible faults but needs knowledge of the future, so it serves only as a benchmark.
Example: reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3 with 3 empty frames. The first four references fault in every algorithm (7, 0 and 1 fill the frames, and 2 evicts 7).
| Algorithm | Faults | Key decision |
|---|---|---|
| FIFO | 9 | on 3, evicts 0 (the oldest), which is needed immediately |
| LRU | 8 | on 3, evicts 1 and keeps the recently used 0 |
| Optimal | 6 | on 4, evicts 0, which is never used again |
More in Page Replacement & Thrashing
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Compare FIFO, LRU and Optimal page replacement. | Concept | Medium | Read the answer to Compare FIFO, LRU and Optimal page replacement. | |||
| 2 | What is Belady's anomaly? | Concept | Medium | Read the answer to What is Belady's anomaly? | |||
| 3 | Why is exact LRU expensive, and how does the clock algorithm approximate it? | Concept | Hard | Read the answer to Why is exact LRU expensive, and how does the clock algorithm approximate it? | |||
| 4 | What is thrashing, why does it happen, and how can it be prevented? | Concept | Hard | Read the answer to What is thrashing, why does it happen, and how can it be prevented? |