CS FundamentalsVery hardProduct company interview · GATE level

Reference string: 2, 7, 2, 4, 1, 7, 3, 2, 4, 5, 1, 2, 7, 3, 5, 2. With 4 frames, initially empty, how many page faults do FIFO, LRU and Optimal replacement cause, respectively?

  1. A. FIFO 8, LRU 10, Optimal 7
  2. B. FIFO 12, LRU 8, Optimal 7
  3. C. FIFO 8, LRU 12, Optimal 7
  4. D. FIFO 8, LRU 12, Optimal 6

Correct answer: C. FIFO 8, LRU 12, Optimal 7

Simulate each policy. FIFO: faults on 2, 7, 4, 1 (fill), 3 (evicts 2), 2 (evicts 7), 5 (evicts 4), 7 (evicts 1) - all other references hit, total 8. LRU keeps evicting exactly the page that comes back next on this string: the first 3 evicts 2, which is the very next reference; that 2 evicts 4, which is needed immediately after - 12 faults in all. Optimal faults 7 times: the 6 distinct pages each cost one compulsory miss, plus one re-load of 7. The trap is to assume LRU always beats FIFO; it is a stack algorithm, so it never shows Belady's anomaly, but it can lose to FIFO on a particular string.

More Operating Systems questions

Exams that ask this topic