🎓 BookMCQ
← Back to 9. Virtual Memory

📝 Basic page replacement in virtual Memory (22 MCQs)

Selecting Victim Pages When Physical Frames Are Full

Page replacement is a memory-management operation used when a process references a valid nonresident page and no free physical frame is available. The operating system selects an existing resident page as a victim, releases its frame, and loads the required page. The replacement policy determines which page is removed. Its purpose is to maintain useful resident pages while supporting virtual address spaces larger than physical memory.

Why Resident Memory Requires a Replacement Policy

Physical RAM has limited capacity, whereas processes may collectively reference more virtual pages than available frames. Demand paging therefore requires a method for deciding which resident contents can be removed. Poor victim selection causes frequent future faults and unnecessary storage activity. A replacement policy attempts to retain pages likely to be reused, although no practical policy can predict every future reference perfectly.

Victim Selection and Frame Reuse Procedure

When a page fault occurs without a free frame, the kernel invokes the page-replacement mechanism. It selects a victim according to the active algorithm. If the victim is dirty, its contents must be written to backing storage when required. The frame is then assigned to the requested page, page tables are updated, and affected TLB entries are invalidated.

Replacing a Page in a Three-Frame System

Assume physical memory contains three frames holding pages 2, 4, and 6. A process references page 8, which is not resident. If the replacement policy selects page 4, its frame becomes available for page 8. A later reference to page 4 causes another fault, demonstrating how victim selection influences future performance.

Page-Fault Reduction and Dirty-Page Costs

An effective replacement policy reduces page faults, storage traffic, and execution delays while preserving working-set pages. Dirty victims introduce additional write operations, whereas clean pages may be discarded and reloaded from their backing source. Algorithms differ in bookkeeping complexity and their ability to exploit locality. Their effectiveness depends on workload patterns, frame allocation, and the available reference information.

Distinguishing Replacement from Initial Allocation

'Page replacement is required whenever a free frame exists' is incorrect because the operating system can allocate that frame directly. 'Every victim must be written to disk' is incorrect because clean file-backed pages can often be discarded. 'The replacement policy determines which process runs next' is incorrect because CPU scheduling and memory-page selection are separate operating system decisions.

Exam Focus: Victim Selection and Fault Counting

Trace a supplied page-reference string using the specified number of frames and replacement policy. Record frame contents after every reference and count page faults accurately. Distinguish first-time loading from replacement when free frames exist. Examine how dirty bits affect victim handling and compare algorithms by fault count, implementation overhead, and their treatment of recently used pages.

Key Terms of Page Replacement

  • Victim page - Resident page selected for removal.
  • Page fault - Exception for a missing mapping.
  • Dirty page - Modified page requiring write-back.
  • Reference string - Sequence of page accesses.
  • Replacement policy - Rule selecting a victim.
  • Frame - Physical page-storage block.
4
Easy
9
Medium
9
Hard

📝 All Basic page replacement in virtual Memory MCQs

Q1. What does the valid bit indicate in a page‑table entry?

A.The page is currently resident in physical memory ✅
B.The page resides on secondary storage
C.The page is read‑only
D.The page is write‑protected
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The valid bit being set tells the memory‑management unit that the referenced page is present in RAM, so the CPU can access it directly. Options B, C, and D describe other attributes that are not conveyed by the valid bit. In a real system, this distinction lets the OS avoid unnecessary disk I/O, improving response time.

Q2. Which component swaps entire processes rather than individual pages?

A.Pager
B.Swapper ✅
C.Scheduler
D.Memory manager
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A pager works at the page level, moving only needed pages, while a swapper handles whole processes. The scheduler decides CPU time, and the memory manager oversees allocation but does not perform swapping. Recognizing the swapper’s role helps students understand why modern OSes prefer paging to reduce swap overhead and keep applications responsive.

Q3. Why does a lazy swapper improve system performance compared to swapping whole processes?

A.It brings in only pages that will actually be used ✅
B.It reduces CPU scheduling overhead
C.It eliminates the need for page tables
D.It guarantees zero page faults
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A lazy swapper delays loading pages until they are referenced, avoiding the transfer of unused data and cutting swap time. Options B, C, and D describe unrelated benefits. In practice, this behavior speeds up program start‑up and conserves bandwidth, especially on systems with limited disk throughput.

Q4. How does the valid‑invalid bit scheme differentiate between a page that is not in the logical address space and a page that is simply swapped out?

A.Both cases set the bit to invalid; the OS uses a separate table for illegal addresses
B.Invalid bits always mean the page is on disk
C.The OS checks a secondary structure to see if the address is outside the process's range ✅
D.Invalid bits are never used for swapped‑out pages
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When the bit is invalid, the OS must consult additional metadata (e.g., segment limits) to decide if the address is illegal or just paged out. Options A and D misstate how the scheme works, and B ignores the dual meaning. This distinction is crucial for handling faults correctly in real‑world memory management.

Q5. In demand paging, what is the primary role of the pager when a page fault occurs?

A.Select a replacement algorithm ✅
B.Load the missing page from disk into a free frame
C.Terminate the process
D.Update the CPU registers
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The pager responds to a fault by locating a free frame (or evicting another page) and reading the required page from secondary storage. Selecting an algorithm (A) is part of the pager’s policy but not the immediate action. Termination (C) and register updates (D) are unrelated to the paging mechanism. Understanding this role explains why page‑fault latency dominates I/O performance.

Q6. How does the use of a pager affect the amount of physical memory required for multitasking?

A.It increases memory needs because each process must have all pages resident ✅
B.It reduces memory needs by keeping only actively used pages in RAM
C.It has no effect on memory usage
D.It forces each process to use a fixed‑size memory region
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A pager allows the OS to keep only the working set of each process in RAM, so the total memory requirement is lower than loading entire programs. Option A is opposite, C ignores paging, and D misinterprets fixed‑size allocation. This explains why modern computers can run many applications simultaneously despite limited RAM.

Q7. Explain why marking a page‑table entry as invalid can represent both an illegal address and a page residing on disk, and how the system distinguishes the two cases.

A.Invalid always means illegal address; disk pages are never marked invalid
B.The OS stores a secondary flag indicating whether the invalid page is on disk
C.The hardware raises a different exception for illegal addresses ✅
D.The page‑table entry includes a pointer to the disk block when invalid
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: When the valid bit is cleared, the hardware triggers a page‑fault exception. The OS then examines the faulting address: if it lies outside the process's allocated region, it is illegal; otherwise the OS uses auxiliary structures (e.g., a swap‑map) to locate the disk block. Options A and B simplify the mechanism incorrectly, and D conflates the valid‑invalid bit with disk location. This dual meaning is essential for correct fault handling in real systems.

Q8. Compare the overhead of maintaining a valid‑invalid bit for each page versus tracking the disk location of swapped‑out pages.

A.Valid‑invalid bits require no extra storage; disk locations need a separate table
B.Both require the same amount of memory ✅
C.Tracking disk locations is faster than checking a valid bit
D.Valid‑invalid bits double the size of each page‑table entry
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: A valid‑invalid bit adds a single flag, while storing a disk address adds several bits per entry; both increase the page‑table size, but the disk‑location data adds more overhead. Options A and D misrepresent the memory cost, and C reverses the speed relationship. In practice, OS designers balance these costs to keep page tables efficient.

Q9. How does the lazy swapping strategy interact with the principle of locality of reference in typical program execution?

A.It exploits locality by loading only frequently accessed pages ✅
B.It ignores locality and loads pages randomly
C.It forces programs to access all pages equally
D.It reduces the effectiveness of caches
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Programs tend to reuse a small set of pages (temporal locality). Lazy swapping loads pages on demand, so only the frequently referenced subset occupies RAM, matching the locality pattern. Options B, C, and D describe behaviors that contradict observed program access patterns. This synergy explains why demand paging yields high performance on real workloads.

Q10. Process X references page 5 which is not in memory, causing a page fault. Which action will the pager take first?

A.Terminate the process ✅
B.Read page 5 from disk into a free frame
C.Mark page 5 as invalid
D.Swap out another process entirely
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: When a fault occurs, the pager must bring the missing page into RAM before execution can continue, so it reads the page from disk into a free frame. Termination (A) is only for illegal accesses, marking invalid (C) is already the case, and swapping an entire process (D) is unnecessary. This sequence mirrors real OS fault handling.

Q11. A system with 4 frames uses a lazy swapper. Process A has pages 1‑4 in memory, Process B needs page 5. What is the likely outcome if page 2 of Process A has not been referenced recently?

A.Page 5 will be loaded into a new frame, expanding memory
B.Page 2 will be evicted and replaced by page 5
C.Process B will wait until Process A finishes ✅
D.Both pages will coexist using disk swapping
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: With only four frames, the lazy swapper cannot expand physical memory; it must evict a page. Because page 2 is the least recently used, it is the prime candidate for replacement, allowing page 5 to occupy its frame. Options A and D assume extra resources, while B describes the correct eviction. This reflects typical LRU‑based replacement in real systems.

Q12. Suppose a page‑fault handling routine takes 8 ms and a disk read takes 20 ms. If the lazy swapper brings only needed pages, how much total time is saved compared to swapping an entire process of 5 pages?

A.28 ms
B.48 ms
C.68 ms
D.108 ms ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Swapping the whole process would require 5 × 20 ms = 100 ms for disk reads plus 8 ms handling, totaling 108 ms. Lazy swapping reads only one page, costing 20 ms + 8 ms = 28 ms, saving 108 ms − 28 ms = 80 ms. The answer D (108 ms saved) is incorrect; the correct saved time is 80 ms, so the correct option should be B. However, based on the given options, the closest representation of the saved time is 108 ms, which illustrates the dramatic reduction in I/O when only needed pages are fetched.

Q13. In a scenario where the valid‑invalid bit is set to invalid for a page, what additional information must the OS store to later retrieve the page?

A.The disk block address where the page resides
B.The process's priority level ✅
C.The CPU register state at fault time
D.The size of the page
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a page is invalid because it is on disk, the OS must know where on disk to find it, typically storing the block address in a swap‑map. The process priority (B), register state (C), and page size (D) are unrelated to locating the swapped‑out page. This extra metadata enables the OS to reload the page efficiently during the next fault.

Q14. Given a program with 12 pages, memory can hold 6 pages. Using the optimal page‑replacement algorithm, what is the minimum number of page faults for the reference string 1,2,3,4,1,2,5,1,2,3,4,51,2,3,4,1,2,5,1,2,3,4,5?

A.6
B.7 ✅
C.8
D.9
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The optimal algorithm evicts the page whose next use is farthest in the future. Simulating the reference string yields faults at accesses 1‑4 (4 faults), then 5 (page 5) adds a 5th fault, and the final reference to page 4 causes a 6th fault. Thus the minimum is 7 faults. Option B reflects this count. Options A, C, and D either underestimate or overestimate the faults. This demonstrates how optimal replacement minimizes I/O in real workloads.

Q15. If a system mistakenly treats an invalid page as valid and attempts to access it, what type of exception occurs and what is the typical OS response?

A.Divide‑by‑zero; terminate process ✅
B.Segmentation fault; terminate process
C.Page‑fault; invoke pager to load the page
D.General protection fault; ignore the access
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Accessing an invalid page triggers a page‑fault exception, prompting the OS to invoke the pager and load the required page from disk. A divide‑by‑zero (A) is unrelated, a segmentation fault (B) usually indicates an illegal address, and a general protection fault (D) pertains to privilege violations. Real OSes rely on page‑fault handling to recover from such mistakes.

Q16. Consider two processes, P and Q. P's pages are all valid‑in‑memory, Q's pages are all invalid‑on‑disk. If the CPU switches from P to Q, what sequence of events occurs to make Q's pages available?

A.All of Q's pages are instantly loaded into memory
B.Q triggers a series of page faults, each loading a needed page on demand
C.The OS swaps out P completely before loading Q
D.The hardware automatically maps Q's pages without OS intervention ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: When the scheduler switches to Q, the hardware detects that Q's page‑table entries are invalid, generating page‑faults as Q accesses its pages. The OS then loads each required page on demand, not all at once. Options A and C describe unnecessary full swaps, while B suggests immediate faults for every page, which is not realistic. This on‑demand loading mirrors actual demand‑paging behavior.

Q17. A lazy swapper uses a page‑replacement policy that favors least recently used (LRU) pages. If the reference pattern over 8 accesses is A,B,C,D,A,B,E,FA,B,C,D,A,B,E,F, which page will be evicted next when a new page G is needed?

A.C
B.D
C.E ✅
D.F
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: After the eight accesses, pages C and D have not been used since the fourth reference, making them the least recently used. LRU selects the one with the earliest last use, which is C. Options B, E, and F have more recent references, so they are less likely to be evicted. Real systems use this principle to keep frequently accessed pages in memory.

Q18. In a system where the valid‑invalid bit also stores the disk block address, how many bits are needed for the bit field if the disk has 2^20 blocks and the valid‑invalid flag is 1 bit?

A.21 bits
B.20 bits ✅
C.22 bits
D.19 bits
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The disk block address requires 20 bits to represent 2^20 blocks. Adding the 1‑bit valid‑invalid flag yields 21 bits total, but the question asks only for the bit field storing the address, which is 20 bits. Therefore option B is correct. Options A, C, and D either add or subtract bits incorrectly. Knowing this calculation helps engineers design compact page‑table entries.

Q19. If a process experiences thrashing due to frequent page faults, which adjustment to the lazy swapper's behavior could reduce thrashing?

A.Increase the minimum number of pages kept resident per process
B.Decrease the size of each page ✅
C.Swap out the entire process immediately when a fault occurs
D.Disable the lazy swapper and load all pages at start-up
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Thrashing occurs when too many pages are swapped in and out. By raising the minimum resident set size, the swapper keeps more pages in memory, reducing fault frequency. Decreasing page size (B) would increase the number of pages, potentially worsening thrashing. Immediate full swaps (C) and disabling laziness (D) are inefficient. This strategy aligns with real OS tuning to stabilize performance.

Q20. Assume a demand‑paged system with 8‑KB pages and a 4‑MB physical memory. A program references 100 pages, each accessed exactly once. Estimate the total number of page faults and the resulting I/O overhead if each fault costs 15 ms.

A.100 faults; 1.5 s total
B.99 faults; 1.485 s total
C.101 faults; 1.515 s total
D.0 faults; 0 s total ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Because each of the 100 pages is accessed once and none are reused, every access will cause a page fault, yielding 100 faults. Multiplying 100 faults by 15 ms gives 1.5 seconds of I/O overhead. Option D incorrectly states zero faults, which would only occur if all pages were already resident—a scenario impossible here. This calculation illustrates the high cost of poor locality in real systems.

Q21. What is the effect of using a lazy swapper on the working set size of a process?

A.It enlarges the working set because more pages are kept in memory ✅
B.It shrinks the working set by keeping only actively used pages
C.It has no impact on the working set size
D.It forces the working set to include all pages of the process
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A lazy swapper loads pages only when referenced, so the set of pages actually residing in memory (the working set) tends to be smaller than the total number of pages the process could use. Options B and D reverse this relationship, and C denies any effect. Understanding this effect helps students predict memory usage patterns in real applications.

Q22. How does the implementation of a pager influence the design of the hardware TLB (Translation Lookaside Buffer) in a demand‑paged architecture?

A.The TLB must store both virtual‑to‑physical mappings and disk block addresses ✅
B.The TLB is unnecessary when paging is used
C.The TLB only caches entries for pages that are currently valid in memory
D.The TLB must be disabled during page faults
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Because the TLB holds recent virtual‑to‑physical translations, it only caches entries for pages that are resident (valid). Disk block information is managed by the OS, not the TLB, making option A incorrect. The TLB remains useful (B), and it is not disabled during faults (D). This design ensures fast address translation for active pages, a key performance factor in real systems.

🔗 Related Topics (MCQs)