FIFO Page Replacement
FIFO evicts the page that has been in memory the longest. It is easy to implement and surprisingly capable of making the wrong decision.
In plain English
FIFO evicts the page that has been on the desk the longest, like clearing the oldest note first.
By the end you will be able to
- Trace FIFO replacement on a reference string.
- Count page faults and hits.
- Explain Belady's anomaly.
- Know FIFO's strengths and weaknesses.
The algorithm
Keep pages in a queue in arrival order. On a fault with no free frame, remove the page at the front, load the new page, and put it at the back. On a hit, the queue order does not change. FIFO ignores how recently or how often a page was used.
on fault:
if free_frame: frame = free_frame
else: frame = queue.pop_front()
load(page, frame)
queue.push_back(page)Worked reference string
Use three frames and the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. The first three references fault and fill the frames. Reference 4 evicts 1. Reference 1 evicts 2. Reference 2 evicts 3. Reference 5 evicts 4. References 1 and 2 hit. Reference 3 evicts 1. Reference 4 evicts 2, and reference 5 hits. FIFO produces 9 faults.
ref: 1 2 3 4 1 2 5 1 2 3 4 5
faults: F F F F F F F . . F F .
frames after each step are in the lab traceBelady's anomaly
Normally more frames should mean fewer faults. FIFO can violate this: for some reference strings, increasing the number of frames increases the number of page faults. This is Belady's anomaly. It happens because FIFO does not respect the stack property that LRU has. If an algorithm is a stack algorithm, adding frames can never increase faults.
Watch it happen
Step through the worked example. Play it, pause it, or move one step at a time.
step-by-step
Step 1 of 12
Reference 1 · fault
Reference 1: miss. A free frame is available.
Key takeaways
- FIFO evicts the oldest resident page.
- A hit does not change the queue order.
- FIFO is simple but ignores usage recency.
- FIFO can suffer Belady's anomaly.
- Stack algorithms such as LRU do not.
Common pitfalls
- Moving a page to the back on a hit; FIFO does not do that.
- Counting a hit as a fault.
- Assuming more frames always reduce FIFO faults.
Kernel notes
- Trace the frame queue after every reference.
- Count faults and hits separately.
- Explain Belady's anomaly with a concrete reference string.
Quick check
1. Which page does FIFO evict?
2. What is Belady's anomaly?