Question

Consider a computer system with ten physical page frames. The system is provided with an access sequence (a1,a2,…,a20,a1,a2,…,a20)(a_1, a_2, \dots, a_{20}, a_1, a_2, \dots, a_{20}), where each aia_i is a distinct virtual page number. The difference in the number of page faults between the last-in-first-out page replacement policy and the optimal page replacement policy is _____.

Official answer and solution
Official answer
1
From
Official GATE 2016 answer key

Solution

Trace page replacements for both LIFO and Optimal policies on the given 40-access reference string with 10 physical frames.

Reference sequence: S=(a1,a2,…,a20,a1,a2,…,a20)S = (a_1, a_2, \dots, a_{20}, a_1, a_2, \dots, a_{20}) of length 40, with 1010 page frames.
All aia_i (1≤i≤201 \le i \le 20) are distinct pages.

  1. Last-In-First-Out (LIFO) Policy:
  • First half (a1a_1 to a20a_{20}):
    • a1,…,a10a_1, \dots, a_{10} fill the 10 empty frames   ⟹  10\implies 10 faults. Frames hold: {a1,a2,…,a10}\{a_1, a_2, \dots, a_{10}\}, with a10a_{10} as the latest loaded page.
    • a11a_{11} faults, replacing the most recently loaded page a10a_{10}. Frame contents: {a1,…,a9,a11}\{a_1, \dots, a_9, a_{11}\}.
    • For each subsequent page a12,…,a20a_{12}, \dots, a_{20}, each page replaces the single frame slot occupied by the most recently loaded page. Each of a11,…,a20a_{11}, \dots, a_{20} causes a fault (1010 faults).
    • At the end of the first half, frames hold {a1,a2,…,a9,a20}\{a_1, a_2, \dots, a_9, a_{20}\}. Total faults so far =10+10=20= 10 + 10 = 20.
  • Second half (a1a_1 to a20a_{20}):
    • Accesses a1,a2,…,a9a_1, a_2, \dots, a_9 are all hits since they remained in frames 11 through 99 (00 faults).
    • Access a10a_{10} is not present   ⟹  \implies fault. It replaces the most recently loaded page a20a_{20}.
    • Accesses a11,…,a19a_{11}, \dots, a_{19} fault successively, each replacing the single volatile frame slot (99 faults).
    • Access a20a_{20} faults, replacing a19a_{19} (11 fault).
    • Second half faults =1+9+1=11= 1 + 9 + 1 = 11 faults.
  • Total LIFO page faults =20+11=31= 20 + 11 = 31.
  1. Optimal (OPT) Policy:
  • There are 20 distinct virtual pages and only 10 frames available.
  • During the first half, all 20 distinct pages are referenced for the first time, causing at least 20 cold misses.
  • The 10 frames can hold at most 10 distinct pages between the first and second passes.
  • In the second pass, at most 10 pages can hit (specifically, the 10 pages chosen to be retained in memory). The remaining 10 pages must fault.
  • Thus, the theoretical minimum number of page faults for any policy is 20+10=3020 + 10 = 30.
  • OPT achieves this bound by retaining the first 10 pages {a1,…,a10}\{a_1, \dots, a_{10}\} (which will be accessed first in the second pass at positions 21 to 30) and immediately evicting pages a11,…,a20a_{11}, \dots, a_{20} as they arrive, ensuring 10 hits on a1,…,a10a_1, \dots, a_{10} during the second pass.
  • Total OPT page faults =30= 30.

Calculate the difference:

Difference=FaultsLIFO−FaultsOPT=31−30=1\text{Difference} = \text{Faults}_{\text{LIFO}} - \text{Faults}_{\text{OPT}} = 31 - 30 = 1
Final answer

1

Common trap

Assuming that LIFO replaces the oldest page (which is FIFO), rather than the newest page, leading to an incorrect count of hits.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 1
Question
59 of 65, printed as CS Q.49
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.