Question 1Multiple choiceVirtual memory & page replacement
A process is allocated 3 page frames, all initially empty, and generates the page-reference string 1, 3, 2, 1, 4, 3, 5, 1, 2, 3. How many page faults occur under the LRU (least recently used) replacement policy? Count the initial loads as faults.
- A.
5
- B.
6
- C.
8
- D.
9
Worked solution
LRU evicts the page whose most recent use is furthest in the past. Track the frames with the least recently used page on the left; a hit moves that page to the most-recent end.
| Reference | Frames (LRU → MRU) | Result |
|---|---|---|
| 1 | 1 | fault |
| 3 | 1, 3 | fault |
| 2 | 1, 3, 2 | fault |
| 1 | 3, 2, 1 | hit |
| 4 | 2, 1, 4 | fault (evict 3) |
| 3 | 1, 4, 3 | fault (evict 2) |
| 5 | 4, 3, 5 | fault (evict 1) |
| 1 | 3, 5, 1 | fault (evict 4) |
| 2 | 5, 1, 2 | fault (evict 3) |
| 3 | 1, 2, 3 | fault (evict 5) |
That is 9 faults: the three compulsory loads plus six replacements. Only the second reference to page 1 is a hit; every later reference arrives just after its page was evicted, which is the worst pattern for LRU.
Option C (8) is the tempting answer because it is the FIFO count for the same string: FIFO keeps page 3 (loaded second) long enough to score a hit on the sixth reference, so FIFO beats LRU here, a reminder that LRU is not always better. Option B (6) is the optimal (Belady) count, the lower bound that no online policy can beat on this string. Option A (5) is merely the number of distinct pages, which would be the fault count only if the process had enough frames to hold all of them.
9 page faults (option D).