🎓 BookMCQ
← Back to 9. Virtual Memory

📝 LRU approximation page replacement (21 MCQs)

Approximating Recent Usage Without Exact LRU Tracking

LRU approximation algorithms are page-replacement techniques that estimate recent page usage without maintaining the complete access history required by exact least-recently-used replacement. They commonly use hardware reference bits, counters, or periodic sampling. These mechanisms allow the operating system to identify pages that have been accessed recently and prefer older or less frequently referenced candidates when physical frames must be reclaimed.

Why Exact Reference Ordering Can Be Expensive

Perfect LRU may require updating timestamps or maintaining an ordered structure on every memory reference. Such frequent bookkeeping can create significant processor and kernel overhead. Reference-bit approaches provide a cheaper alternative by recording whether a page has been accessed during an interval. They lose precise ordering information but offer useful approximations for practical memory-management systems.

Reference Bits and Second-Chance Scanning

Hardware sets a page's reference bit when the page is accessed. In the second-chance algorithm, the replacement pointer examines candidate pages. A page with reference bit zero can be replaced; a page with bit one has its bit cleared and receives another opportunity. The pointer advances until it finds a suitable victim, implementing a circular approximation of recency.

Replacing Pages Using Reference-Bit Information

Suppose four frames contain pages A, B, C, and D with reference bits 1, 0, 1, and 0. A circular pointer begins at A. The algorithm clears A's bit and advances, then encounters B with bit zero. Page B becomes the victim, and the requested page occupies its frame.

Lower Overhead and Less Precise Recency Information

LRU approximations reduce bookkeeping costs and can exploit locality without tracking every memory reference precisely. Their performance depends on reference-bit updates, scanning frequency, and pointer behaviour. Enhanced variants may also consider dirty bits to distinguish pages that require write-back. Approximation quality can decline when a page is frequently referenced between sampling intervals but rarely used afterward.

Distinguishing Second Chance from Exact LRU

'Second chance always removes the oldest loaded page' is incorrect because a set reference bit can postpone replacement. 'Reference bits record the complete order of accesses' is incorrect because they indicate access activity rather than exact timing. 'A cleared reference bit means the page is absent' is incorrect because the page remains resident until actually replaced.

Exam Focus: Reference Bits and Circular Pointers

Trace the circular pointer through the frame list and apply each reference-bit rule precisely. Identify the first eligible victim and record reference-bit changes. Compare second chance with FIFO and exact LRU. Questions may also introduce enhanced second chance using reference and modification bits, requiring candidates to prioritise clean, unreferenced pages appropriately.

Key Terms of LRU Approximation

  • Reference bit - Indicates recent page access.
  • Second chance - Gives referenced pages another opportunity.
  • Clock algorithm - Uses a circular replacement pointer.
  • Sampling - Checks access information periodically.
  • Dirty bit - Indicates page modification.
  • Approximate LRU - Estimates recency with limited information.
6
Easy
8
Medium
7
Hard

📝 All LRU approximation page replacement MCQs

Q1. What does the valid bit indicate when it is set to “valid” in a demand‑paging system?

A.The page is illegal and resides on disk
B.The page is legal and currently in memory ✅
C.The page is illegal but cached
D.The page is free and can be allocated
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When the valid bit is “valid”, the operating system knows the page belongs to the process’s address space and that a physical frame already holds its contents. Therefore the CPU can read or write the page without causing a fault. The other choices describe illegal or unused pages, which are not what a valid bit represents. This distinction lets the hardware quickly decide whether a memory reference can proceed, improving overall system efficiency.

Q2. Which hardware structure is commonly used to track recent page references for LRU approximation?

A.Translation Lookaside Buffer (TLB)
B.Reference (or use) bit in the page‑table entry ✅
C.Interrupt Descriptor Table
D.Stack Pointer Register
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The reference bit, also called the use bit, is stored in each page‑table entry and is set to 1 whenever the page is accessed. By periodically clearing it, the system can infer which pages have been used recently, forming the basis of Clock or aging approximations of LRU. The TLB speeds address translation, not reference tracking, while the other structures have unrelated purposes. Using this bit allows the OS to make informed replacement decisions without costly full LRU bookkeeping.

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

A.It reduces the number of disk I/O operations by loading only needed pages ✅
B.It eliminates the need for page tables entirely
C.It guarantees that all pages will eventually be resident in memory
D.It forces every process to run in isolation
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A lazy pager brings in a page only when the process actually accesses it, so the system avoids reading pages that will never be used. This saves disk bandwidth, shortens swap‑in time, and leaves more physical memory for other processes. The other statements are false: page tables are still required, not all pages become resident, and isolation is unrelated to paging strategy. The result is faster program start‑up and higher overall throughput.

Q4. How does the “invalid” state differ from a page fault caused by an illegal address?

A.Invalid means the page is on disk but still belongs to the process, whereas an illegal address does not belong to the process at all
B.Invalid indicates a corrupted page, while illegal address indicates a protected page
C.Invalid triggers a segmentation fault, illegal address triggers a page‑fault interrupt ✅
D.Invalid and illegal address are synonymous concepts
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: When the valid/invalid bit is “invalid” because the page is on disk, the CPU generates a page‑fault interrupt that the OS handles by loading the page into memory. In contrast, an illegal address fault occurs when the accessed address is outside the process’s logical address space, leading to a segmentation fault or protection exception. The OS cannot simply load a non‑existent page, so the handling differs. Understanding this distinction helps the OS decide whether to fetch a page or terminate the offending process.

Q5. In the second‑chance (clock) algorithm, what is the purpose of the reference bit?

A.To indicate whether the page has been modified since it was loaded
B.To record the time of the last write operation
C.To show if the page has been accessed recently, allowing the algorithm to give it another chance before eviction
D.To store the physical frame number of the page ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The reference (or use) bit is set to 1 whenever the page is accessed. When the clock hand examines a frame, a set bit means the page has been used recently, so the algorithm clears the bit and moves on, granting the page a “second chance”. Only pages with a cleared bit are evicted. The other options describe dirty bits, timestamps, or frame numbers, which are unrelated to the second‑chance decision process.

Q6. Explain how a counter‑based LRU approximation with kk-bit counters approximates true LRU.

A.Each counter stores the exact time of the last reference, matching true LRU behavior ✅
B.Counters are shifted right at regular intervals and the reference bit is inserted as the most‑significant bit, so pages accessed recently accumulate larger values
C.The counters count the number of page faults per page
D.The counters are used to hash page numbers for quick lookup
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: At each clock tick the OS shifts every page’s counter right by one bit and inserts the current reference bit as the new most‑significant bit. Pages referenced often keep high‑order bits set, resulting in larger counter values, while pages not accessed for many ticks have low values. The page with the smallest counter is chosen for replacement, mimicking the order of recent use without tracking exact timestamps. This method is less precise than true LRU but requires only simple bit operations, making it practical for hardware implementation.

Q7. Why might a system prefer the Clock algorithm over true LRU despite higher overhead of true LRU?

A.Clock needs fewer hardware resources and approximates LRU well enough for most workloads
B.Clock guarantees optimal page‑replacement decisions, unlike true LRU ✅
C.Clock eliminates the need for a page table
D.Clock works only with read‑only pages, simplifying management
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: True LRU requires maintaining a precise ordering of all pages, which demands expensive data structures and frequent updates on every memory reference. The Clock algorithm, by using only a single reference bit per page and a rotating hand, provides a good approximation with far lower CPU and memory overhead. It does not guarantee optimal decisions, but its simplicity and speed make it attractive for general‑purpose operating systems. The other statements misrepresent the algorithm’s capabilities.

Q8. How does the presence of a valid/invalid bit simplify page‑replacement decisions?

A.It allows the OS to ignore dirty pages entirely
B.It tells the hardware whether a page is resident, so the OS only considers invalid pages for replacement
C.It automatically updates the LRU stack ✅
D.It merges multiple page‑table entries into one
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: When a page‑table entry is marked “valid”, the hardware knows the page is already in a physical frame and can be accessed directly. If the entry is “invalid”, the page resides on disk, and a page‑fault will occur on access. Consequently, the OS can focus replacement policies on the set of invalid pages, without having to scan every entry to determine residency. This binary information reduces the complexity of choosing a victim page, speeding up the replacement process.

Q9. In a scenario where the reference bit is cleared periodically, what effect does this have on the aging algorithm’s sensitivity to recent accesses?

A.It makes the algorithm ignore recent accesses completely
B.It increases the algorithm’s responsiveness to recent accesses because only pages with a recent reference bit set retain high counter values
C.It causes all counters to reset to zero each period
D.It forces the algorithm to treat all pages as equally old ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Clearing the reference bit at regular intervals gives the aging algorithm a time window during which a page must be accessed to keep its counter high. Pages accessed after the clear will have their most‑significant bit set, preserving recent usage, while pages not accessed will gradually lose bits and become candidates for eviction. This periodic reset therefore enhances the algorithm’s ability to distinguish truly recent references from older ones, improving approximation of true LRU.

Q10. A system with 4 frames uses the Clock algorithm. Initially all reference bits are 1 for pages A, B, C, D. After accesses to A and B, a page fault occurs for E. Which page is replaced?

A.Page A ✅
B.Page B
C.Page C
D.Page D
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When the hand starts at A, it sees the reference bit 1, clears it to 0 and moves to B, clears B’s bit, then to C and D, clearing each. After one full rotation the bits are all 0, so when the hand returns to A it finds a cleared bit and replaces that frame with page E. Therefore A is evicted. The other pages remain because their bits were cleared earlier, not because they were chosen as victims.

Q11. Suppose a process references pages in order 1,2,3,4,1,2,5,1,2,3,4,5. Using an 8‑bit counter aging algorithm, after the first 8 references which page will have the highest counter?

A.Page 1 ✅
B.Page 2
C.Page 3
D.Page 5
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: During the first eight accesses (1,2,3,4,1,2,5,1) each reference inserts a 1 as the most‑significant bit of the page’s counter and shifts the existing value right. Page 1 is referenced three times, so its counter accumulates three high‑order 1s, giving it a larger binary value than pages referenced fewer times. Consequently, after eight ticks page 1 holds the highest counter, making it the least likely victim for replacement.

Q12. If a system implements a 2‑bit counter per page for LRU approximation, after the access sequence P, Q, R, P, Q, S, which page is most likely to be evicted next?

A.Page P
B.Page Q
C.Page R ✅
D.Page S
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Each access shifts the existing 2‑bit counter right and inserts a 1 as the new most‑significant bit. After the sequence, pages P and Q have been accessed twice, giving them counters like 11, while R and S have been accessed once, resulting in counters like 01. Between R and S, the one with the smaller counter (both 01) will be chosen; typically the algorithm selects the first such page, which is R. Hence R is the most likely victim.

Q13. A computer uses a lazy pager and a page fault occurs. Describe the steps the operating system takes to handle the fault, assuming the needed page is not in memory.

A.The OS immediately terminates the process ✅
B.The OS loads the required page from disk into a free frame, updates the page‑table entry to “valid”, and resumes the process
C.The OS swaps out the entire process and restarts it
D.The OS ignores the fault and continues execution
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: When a page fault occurs, the OS first locates a free frame (or selects a victim via a replacement algorithm). It then reads the missing page from secondary storage into that frame, marks the corresponding page‑table entry as valid, and restarts the instruction that caused the fault. The process is not terminated, and only the needed page is brought in, reflecting the lazy‑paging principle. The other options describe actions that are not part of normal page‑fault handling.

Q14. Given a 3‑level memory hierarchy (register, cache, RAM) and a demand‑paged virtual memory, how does the valid/invalid bit affect the interaction between cache and RAM?

A.It forces the cache to store only pages marked valid
B.It causes the cache to bypass RAM and fetch directly from disk
C.It tells the CPU whether a RAM address is resident, allowing the cache controller to issue a miss and trigger a page‑fault if the bit is invalid
D.It has no effect because cache operates independently of virtual memory ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: The valid/invalid bit resides in the page table, not in the cache hardware. When the CPU accesses an address, the cache controller checks the tag; if the tag matches, the data is supplied without consulting the page table. Only when a miss occurs does the CPU consult the page table, and if the valid bit is “invalid”, a page‑fault is generated, causing the OS to bring the page into RAM before it can be cached. Thus the bit indirectly influences cache behavior via page‑fault handling, not by directly controlling cache storage.

Q15. In a multi‑programmed environment, two processes share a pool of 6 pages. Process X uses the Clock algorithm, Process Y uses FIFO. If both generate page faults simultaneously, which algorithm is more likely to cause thrashing?

A.Clock
B.FIFO ✅
C.Both are equally likely
D.Neither, thrashing depends only on workload
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: FIFO evicts the oldest page regardless of its recent use, so a process that repeatedly accesses a small set of pages can suffer many unnecessary evictions, leading to repeated faults and thrashing. Clock, by giving pages a second chance based on the reference bit, tends to keep recently used pages longer, reducing the churn of pages. Therefore, when both processes fault at the same time, the FIFO‑using process is more prone to thrashing.

Q16. A system uses an aging algorithm with 4‑bit counters updated every clock tick. After 5 ticks the counters are: A = 1010, B = 0111, C = 1100. Which page will be replaced next?

A.Page A
B.Page B ✅
C.Page C
D.No replacement is needed
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The aging algorithm selects the page with the smallest counter value as the victim. Converting the binary values: A = 10, B = 7, C = 12. Since 7 is the lowest, page B is the least recently used according to the counters and will be evicted. The other pages have larger counters, indicating more recent references.

Q17. If the reference bit of a page is never cleared, what pathological behavior could occur in the Clock algorithm?

A.The page will be evicted immediately on the next fault
B.The page will never be evicted, potentially exhausting free frames ✅
C.The system will crash due to an overflow error
D.The page will cause a segmentation fault on every access
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The Clock algorithm relies on clearing the reference bit after a first scan; a page with a permanently set bit is always considered “recently used”. Consequently, the algorithm will skip that frame forever, never selecting it as a victim. If many pages behave this way, the system may run out of replaceable frames, leading to excessive page faults or an out‑of‑memory condition. The other outcomes are not characteristic of the algorithm.

Q18. Consider a scenario where the valid bit is incorrectly set to “valid” for a page that actually resides on disk. What type of fault occurs when the CPU tries to access this page?

A.A page fault is raised because the frame is not present ✅
B.A protection fault terminates the process immediately
C.No fault occurs; the CPU reads stale data
D.A hardware interrupt signals a memory‑parity error
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: When the valid bit incorrectly claims residency, the hardware attempts to access a physical frame that does not contain the page. This mismatch triggers a page‑fault interrupt, prompting the OS to load the correct page from secondary storage and correct the page‑table entry. It is not a protection violation because the address is still within the process’s logical space. The other options describe unrelated error conditions.

Q19. For a system with 8 frames using the second‑chance algorithm, after a series of references the hand points to a frame with reference bit 0 and dirty bit 1. What does the OS do next?

A.Replace the page immediately without any I/O
B.Set the reference bit to 1 and continue scanning
C.Write the page to disk before replacing it ✅
D.Discard the page because it is clean
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A dirty page has been modified, so its contents must be saved before the frame can be reused. Because the reference bit is already 0, the algorithm selects this frame as a victim. The OS therefore initiates a write‑back to secondary storage to preserve the changes, and only after the I/O completes does it replace the frame with the new page. The other actions either ignore the dirty state or incorrectly treat the page as clean.

Q20. A programmer wants to reduce page faults by prefetching pages. Explain why the lazy pager may still be more efficient than aggressive prefetching in a memory‑constrained environment.

A.Prefetching always guarantees fewer faults than lazy paging
B.Lazy paging only loads pages that are actually needed, avoiding unnecessary I/O and memory pressure, whereas aggressive prefetching may load many pages that are never used, wasting scarce RAM and increasing disk traffic ✅
C.Prefetching eliminates the need for a page table
D.Lazy paging requires no CPU cycles
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Lazy paging waits until a page is truly referenced before bringing it into RAM, which means the system only spends I/O bandwidth and memory on pages that will be used. Aggressive prefetching guesses future accesses; if the guess is wrong, those pages occupy valuable frames without benefit, potentially evicting needed pages and causing additional faults. In environments with limited memory, the overhead of storing unused prefetched pages can outweigh any reduction in faults, making the conservative lazy approach more efficient.

Q21. In an LRU approximation that uses a stack of page numbers, what is the impact on performance if the stack size exceeds the number of physical frames?

A.Performance improves because more pages are tracked
B.Performance degrades because the algorithm may consider pages that cannot be resident, leading to unnecessary evictions
C.The stack size has no effect on performance
D.The system will crash due to stack overflow ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: When the stack holds more entries than there are frames, the algorithm may select a page for eviction that is not actually resident, requiring extra checks and possibly causing a page fault for a page that was never loaded. This extra work increases CPU overhead and can lead to sub‑optimal replacement decisions, reducing overall throughput. Keeping the stack size equal to or smaller than the frame count ensures that only resident pages are considered, preserving the efficiency of the approximation.

🔗 Related Topics (MCQs)