Question
Consider a computer system with ten physical page frames. The system is provided with an access sequence , where each 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: of length 40, with page frames.
All () are distinct pages.
- Last-In-First-Out (LIFO) Policy:
- First half ( to ):
- fill the 10 empty frames faults. Frames hold: , with as the latest loaded page.
- faults, replacing the most recently loaded page . Frame contents: .
- For each subsequent page , each page replaces the single frame slot occupied by the most recently loaded page. Each of causes a fault ( faults).
- At the end of the first half, frames hold . Total faults so far .
- Second half ( to ):
- Accesses are all hits since they remained in frames through ( faults).
- Access is not present fault. It replaces the most recently loaded page .
- Accesses fault successively, each replacing the single volatile frame slot ( faults).
- Access faults, replacing ( fault).
- Second half faults faults.
- Total LIFO page faults .
- 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 .
- OPT achieves this bound by retaining the first 10 pages (which will be accessed first in the second pass at positions 21 to 30) and immediately evicting pages as they arrive, ensuring 10 hits on during the second pass.
- Total OPT page faults .
Calculate the difference:
1
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.