Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q49 — Memory Management and Virtual Memory

Explain with AI
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},....,a_{20}, a_{1}, a_{2},...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_________.
View worked solution

Answer: 1

We are given 1010 physical page frames and an access sequence of length 4040:

(a1,a2,…,a20,a1,a2,…,a20)(a_{1}, a_{2}, \dots, a_{20}, a_{1}, a_{2}, \dots, a_{20})

1. Last-In-First-Out (LIFO) Policy:

  • First 10 accesses (a1a_1 to a10a_{10}): 1010 page faults. Frames contain {a1,a2,…,a10}\{a_1, a_2, \dots, a_{10}\}.
  • Next 10 accesses (a11a_{11} to a20a_{20}): 1010 page faults. Each new page replaces the most recently loaded page in the 10th10^{\text{th}} frame. After a20a_{20}, the frames contain {a1,a2,…,a9,a20}\{a_1, a_2, \dots, a_9, a_{20}\}.
  • Second half (a1a_1 to a20a_{20}):
    • a1a_1 to a9a_9 are hits (00 faults).
    • a10a_{10} causes a page fault and replaces a20a_{20}.
    • a11a_{11} to a20a_{20} each cause a page fault, sequentially replacing the page in the 10th10^{\text{th}} frame (1111 faults total for a10…a20a_{10} \dots a_{20}).

Total LIFO page faults = 10+10+11=3110 + 10 + 11 = 31.

2. Optimal Page Replacement Policy:

  • First 10 accesses (a1a_1 to a10a_{10}): 1010 page faults. Frames contain {a1,a2,…,a10}\{a_1, a_2, \dots, a_{10}\}.
  • Next 10 accesses (a11a_{11} to a20a_{20}): 1010 page faults. To minimize future faults, we replace the page whose next reference is furthest in the future:
    • a11a_{11} replaces a10a_{10} (since a10a_{10} is needed at step 3030, while a1…a9a_1 \dots a_9 are needed earlier).
    • a12a_{12} replaces a11a_{11}, and so on, up to a20a_{20} replacing a19a_{19}.
    • Frames after the first half: {a1,a2,…,a9,a20}\{a_1, a_2, \dots, a_9, a_{20}\}.
  • Second half (a1a_1 to a20a_{20}):
    • a1a_1 to a9a_9 are hits (00 faults).
    • a10a_{10} to a19a_{19} cause 1010 page faults. We can replace any of the pages a1…a9a_1 \dots a_9 as they are not needed anymore, keeping a20a_{20} in memory.
    • a20a_{20} is a hit (00 faults).

Total Optimal page faults = 10+10+10=3010 + 10 + 10 = 30.

The difference in the number of page faults is 31−30=131 - 30 = 1.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Memory Management and Virtual Memory questions