📝 LRU page replacement (18 MCQs)
Replacing the Least Recently Used Resident Page
Least Recently Used page replacement is a virtual-memory algorithm that removes the resident page whose most recent reference occurred farthest in the past. It uses historical access information to estimate future usefulness, relying on temporal locality. Pages accessed recently are considered more likely to be needed again. LRU approximates the optimal policy without requiring direct knowledge of future references.
Why Recent Accesses Help Predict Future Locality
Programs commonly reuse instructions and data within short intervals, so recently accessed pages often remain useful. FIFO ignores this behaviour because it considers only arrival time. LRU improves victim selection by considering reference history. Its main implementation challenge is tracking access order accurately, which can require hardware support or additional bookkeeping that increases memory-management overhead.
Updating Usage Information and Selecting Victims
Whenever a page is referenced, the system records that access as the most recent. This can be implemented using timestamps, ordered lists, or hardware-maintained reference information. If a fault occurs with all frames occupied, the operating system selects the page with the oldest recorded reference and replaces it with the required page.
Tracing LRU with Three Frames
Consider the reference string 1, 2, 3, 1, 4 with three initially empty frames. After loading pages 1, 2, and 3, the reference to page 1 makes it most recently used. When page 4 arrives, page 2 is removed because it has not been referenced since its initial loading.
Temporal Locality and Implementation Costs
LRU generally performs well when workloads exhibit temporal locality and often produces fewer faults than FIFO. It does not exhibit Belady's anomaly because it is a stack algorithm. Exact implementation can be expensive because every reference may require updating ordering information. Practical processors and operating systems commonly use approximate LRU mechanisms instead of maintaining a perfect access history.
Confusing Recency with Arrival Order
'LRU removes the page loaded earliest' is incorrect because it removes the page referenced least recently. 'A page hit never affects replacement order' is incorrect because every reference updates recency. 'LRU uses future access information' is incorrect because it relies on past references to estimate future usefulness.
Exam Focus: Updating Recency After Every Reference
Trace the reference string and update recency after every page hit and fault. Identify the least recently accessed resident page whenever replacement becomes necessary. Compare the resulting fault count with FIFO and optimal replacement. Remember that LRU requires the recency order to change after a hit, even when no physical frame is replaced.
Key Terms of LRU Replacement
- LRU - Removes the least recently used page.
- Temporal locality - Tendency to reuse recent references.
- Timestamp - Records an access time.
- Recency - How recently a page was accessed.
- Stack algorithm - Maintains nested resident-page sets.
- Victim - Page selected for replacement.
📝 All LRU page replacement MCQs
Q1. What does LRU stand for in page replacement algorithms?
📖 Explanation: Least Recently Used (LRU) is the standard abbreviation for the algorithm that evicts the page that has not been used for the longest time. Option A matches this definition. Options B, C, and D describe unrelated concepts, so they are incorrect. Recognizing the abbreviation helps students identify the algorithm in textbooks and system documentation.
Q2. In the valid‑invalid bit scheme, what does a valid bit indicate?
📖 Explanation: A valid bit means the operating system knows the page is present in physical memory and can be accessed without a fault. Option A states this directly. Option B confuses validity with location on disk, while C misinterprets it as an illegal address, and D incorrectly ties it to protection status. Understanding this distinction is essential for handling page faults.
Q3. Why does LRU generally produce fewer page faults than FIFO?
📖 Explanation: LRU chooses the page that has not been referenced for the longest time, reflecting actual usage patterns, so it tends to keep frequently accessed pages. Option B captures this reasoning. FIFO (Option A) ignores recent references, leading to higher fault rates. Random eviction (Option C) and always keeping the newest page (Option D) are not how LRU works. The concept demonstrates why recency matters.
Q4. How is recency typically tracked in hardware to support LRU?
📖 Explanation: Modern processors often store a timestamp or a counter with each page table entry; each time a page is accessed, its counter is updated, allowing the OS to compare counters and decide which page is oldest. Option C describes this mechanism. A global tick counter (Option A) does not provide per‑page information. A software‑only stack (Option B) lacks hardware assistance, and the dirty bit (Option D) tracks modifications, not recency.
Q5. What is the principal disadvantage of implementing a true LRU algorithm in a multitasking system?
📖 Explanation: True LRU needs to know the exact order of every page reference, which demands extra data structures and frequent updates, increasing CPU and memory overhead. Option A states this drawback. Limiting processes (Option B) is unrelated, as LRU works with any number of processes. Locking pages (Option C) defeats virtual memory, and eliminating the valid‑invalid bit (Option D) is inaccurate.
Q6. Which statement best describes the relationship between LRU and the Clock (second‑chance) algorithm?
📖 Explanation: The Clock algorithm approximates LRU: it cycles through pages, checking a reference bit that indicates recent use; if set, the bit is cleared and the page gets another chance, mimicking LRU without tracking exact timestamps. Option A captures this trade‑off. Option B incorrectly claims exact LRU, while Option C describes the opposite behavior, and Option D is false because Clock is a well‑known replacement policy.
Q7. When a system experiences thrashing, how does LRU performance change?
📖 Explanation: Thrashing occurs when the active working set cannot fit in memory, leading to a rapid succession of page faults. Under such pressure, LRU still replaces pages but cannot keep up, so the fault rate skyrockets, making the algorithm effectively useless; many systems may switch to a different policy. Option D reflects this outcome. Options A, B, and C mischaracterize LRU's behavior during thrashing.
Q8. If a reference string repeatedly accesses the same small set of pages, what effect does LRU have on the page‑fault rate?
📖 Explanation: When the same limited set of pages is accessed frequently, LRU keeps those pages in memory, so after an initial warm‑up period, faults become rare. Option B incorrectly suggests increased faults; the correct impact is a reduction, which is captured by Option A. Options C and D do not describe the typical LRU behavior in this scenario.
Q9. Assume a process's working set exactly matches the number of allocated frames. How does LRU behave in steady state?
📖 Explanation: When the working set size equals the number of frames, LRU will have all needed pages loaded after the initial loading phase, and because no page is ever older than any needed page, no further evictions occur. Thus, option A is correct. Options B and C contradict the definition of a stable working set, and D misstates frame allocation.
Q10. With three frames and the reference sequence 1, 2, 3, 4, which page will LRU evict when page 4 is referenced?
📖 Explanation: Initially the frames hold pages 1, 2, 3. When page 4 is requested, LRU selects the page that has not been used for the longest time, which is page 1 (its last use was at the very beginning). Therefore option A is correct. Options B and C are more recent, and D is false because a replacement is required.
Q11. A system has four frames. The reference string is 2, 3, 2, 1, 5, 2 using LRU. Which page is evicted when reference 5 occurs?
📖 Explanation: After processing 2, 3, 2, 1, the frames contain 2, 3, 1 and one empty slot. When 5 is referenced, the empty slot is filled, so no eviction occurs. However, if we assume the empty slot is already used, the least recently used page among 2, 3, 1 is 3 (because its last use was before 2 and 1). Thus option B (page 1) would be wrong; the correct answer is 3, which corresponds to option A. Since the question asks which page is evicted, the correct choice is 3, option A.
Q12. Given three frames and the reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, using LRU, how many page faults occur?
📖 Explanation: Step‑by‑step tracking shows faults on 7,0,1,2,3,4,2,3,0,3,2 – a total of 11 faults. Options A (9) and B (10) underestimate the count, while D (12) overestimates it. The correct count aligns with option C, demonstrating how LRU minimizes faults compared to FIFO but still incurs faults when new pages appear.
Q13. If a system increases its frame allocation from 3 to 5 for the same reference string, what is the expected effect on LRU page faults?
📖 Explanation: Adding more frames can only hold more pages, so LRU will either reduce the number of evictions or leave them unchanged if the extra frames are never used. Therefore option C is correct. Option A ignores the possibility of reduction, B suggests a paradoxical increase, and D is unrelated to the algorithm's behavior.
Q14. Two processes share a total of 4 frames. Process A references 1, 2, 3, 4 while Process B references 5, 6 in alternating bursts. Using LRU, which page from Process A is most likely evicted when Process B needs a frame?
📖 Explanation: When Process B requests a frame, the LRU victim is the page whose last use is farthest in the past. Because Process A’s pages are accessed before the burst from B, the earliest accessed page (1) becomes the least recent. However, the alternating pattern means the most recent page from A at the moment of eviction is 4, making it the least likely victim. Thus the correct answer is 4, option D.
Q15. Which operation on a stack‑based LRU implementation can be performed in time?
📖 Explanation: When a page is accessed, the stack‑based LRU moves that page node to the top, which can be done with a constant‑time pointer update if the node is known. Option A describes this operation. Scanning (Option B) is linear, removing the bottom (Option C) requires traversal, and rebuilding (Option D) is certainly not constant‑time.
Q16. Consider a reference string 6, 0, 3, 0, 1, 2, 6, 2, 4, 6, 5, 0, 1, 2, 3 with five frames. Using true LRU, which page is evicted at the reference to 5?
📖 Explanation: After processing up to the reference 0 before 5, the frames contain 6, 0, 2, 4, 3 with last‑use times: 6(9), 0(12), 2(14), 4(9), 3(15). The least recently used page is 4, whose last use was at position 9, making it the victim. However, the question asks which page is evicted when 5 arrives; the correct victim is 4, which corresponds to option D. Since option B is 0, the correct answer is 4, option D.
Q17. What is a key performance difference between true LRU and an approximate LRU using a two‑bit counter per page?
📖 Explanation: A two‑bit counter approximates recency by recording recent references, which saves space compared to storing full timestamps, but it can misidentify the least recent page, leading to occasional extra faults. Option A captures this trade‑off. Option B is false because true LRU is optimal; Option C reverses the typical overhead relationship, and Option D confuses validity tracking with replacement policy.
Q18. A system with five frames sees the reference pattern 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. After the twentieth reference, which pages remain in memory under LRU?
📖 Explanation: The first ten references fill the frames with 1‑5 and then reuse them, so no eviction occurs. Starting at reference 6, each new page forces eviction of the least recently used page, which cycles out 1, 2, 3, 4, 5 in order. By the twentieth reference (which is 10), the frames hold the most recent five pages 6‑10. Thus option A is correct; the other options list older pages that have already been replaced.