š Applications and page replacement (8 MCQs)
How Application Memory Behaviour Influences Replacement
Application behaviour strongly influences the effectiveness of virtual-memory page-replacement policies. Programs access instructions and data according to their algorithms, data structures, and execution phases. These access patterns determine temporal and spatial locality, affecting which pages should remain resident. The operating system observes or estimates memory usage and selects replacement mechanisms that attempt to preserve pages likely to be referenced again.
Why Application Locality Matters More Than Page Age Alone
Applications differ in memory-access patterns. Compilers repeatedly access active code and symbol tables, databases process large indexes and records, and scientific programs may traverse extensive arrays. A page recently accessed may remain important, while another may become inactive after a workload phase changes. Replacement policies must therefore respond to actual reference behaviour rather than assuming every application has identical locality.
Working Sets and Replacement Policy Interaction
The working set represents pages actively referenced during a recent interval. The memory manager attempts to retain useful working-set pages while reclaiming less active contents when necessary. LRU and its approximations exploit recent references, while frequency-based methods estimate repeated usage. Application hints and memory-mapping behaviour may also influence reclaim decisions without guaranteeing that a particular page remains resident.
Array Traversal and Page Reuse
Consider a program processing a two-dimensional array stored in row-major order. Traversing elements across successive columns of one row generally uses nearby memory locations and benefits from spatial locality. Repeatedly accessing a small group of rows also creates temporal locality. A replacement policy that preserves these active pages can reduce faults compared with one that repeatedly removes them.
Database, Scientific and General Workload Considerations
Interactive applications benefit from fast access to active code and data, while database and scientific workloads may operate on memory regions larger than available RAM. Sequential scans can make pages unlikely to be reused, whereas frequently accessed index pages may deserve retention. No single replacement algorithm is ideal for every workload, so real systems combine reclaim heuristics, caching policies, and workload-specific mechanisms.
Misunderstandings About Application-Aware Replacement
'Every frequently accessed page must remain resident forever' is incorrect because memory pressure can require its eviction. 'Sequential scans always benefit from retaining every scanned page' is incorrect because those pages may not be reused. 'The same replacement policy gives identical results for every program' is incorrect because reference patterns and working-set sizes vary.
Exam Focus: Locality and Workload-Based Replacement
Identify temporal and spatial locality in short program fragments and explain their effect on page faults. Compare sequential array traversal with repeated random access. Relate application working sets to LRU, FIFO, and frequency-based replacement. Questions may ask why database indexes remain useful in memory or why retaining every page from a one-pass scan can waste frames.
Key Terms of Application Page Replacement
- Temporal locality - Reuse of recently accessed data.
- Spatial locality - Access to nearby locations.
- Working set - Recently active virtual pages.
- Sequential scan - Ordered traversal of data.
- Page locality - Concentration of page references.
- Reclaim - Recovering physical memory frames.
š All Applications and page replacement MCQs
Q1. A process currently has only pageāÆ2 resident in memory. The next CPU reference is to pageāÆ2. What does the lazy swapper do?
š Explanation: The lazy swapper checks the validāinvalid bit before accessing a page. Since pageāÆ2 is already resident, the bit is marked valid, so the CPU proceeds without a fault. OptionāÆB correctly describes this behavior. OptionāÆA is wrong because a page fault occurs only when the page is not in memory. OptionāÆC is incorrect; no replacement is needed when the page is already present. OptionāÆD is false because an invalid reference would trigger a fault, not terminate the process. This illustrates how lazy swapping avoids unnecessary disk I/O.
Q2. Why is a lazy swapper preferred over swapping the entire process when using demand paging?
š Explanation: A lazy swapper brings in pages only when they are referenced, which cuts down on the amount of data transferred between disk and memory. This reduction in I/O speeds up program startāup and saves physical memory. OptionāÆA captures this advantage. OptionāÆB is opposite to the lazy approach, which does not keep all pages resident. OptionāÆC is inaccurate because a page table is still required to track page locations. OptionāÆD is unrelated; lazy swapping does not affect swapāfile size.
Q3. What does the āvalidā setting of the validāinvalid bit indicate in a pageātable entry?
š Explanation: When the valid bit is set, the operating system knows the page is part of the processās address space and that a physical frame holds its contents, so memory can be accessed directly. OptionāÆC states this precisely. OptionāÆA describes an illegal page, which would be marked invalid. OptionāÆB corresponds to an invalid bit that may point to a disk location, not a valid bit. OptionāÆD is not a standard meaning of the valid bit. Understanding this distinction is key for correct handling of page faults.
Q4. Given a reference string 1,2,3,2,4,1,2,3,4 and three frames, which pageāreplacement algorithm will incur the fewest page faults under a lazy swapping policy?
š Explanation: LRU replaces the page that has not been used for the longest time, which matches the pattern of the reference string and results in fewer faults than FIFO, which discards pages in arrival order. OptionāÆB is correct. FIFO (OptionāÆA) would replace pages too early, causing extra faults. Random (OptionāÆC) is generally less efficient. The optimal algorithm (OptionāÆD) is theoretical and not implementable; it would give the minimum possible faults but is not a practical policy. This scenario shows how lazy swapping works with different replacement strategies.
Q5. How does the pager decide which pages to bring into memory when a process is swapped in?
š Explanation: The pager uses heuristics such as locality of reference to guess which pages will be needed next, loading those ahead of time to reduce page faults. This predictive behavior is described in optionāÆB. OptionāÆA would load every invalid page, defeating the purpose of lazy swapping. OptionāÆC suggests randomness, which provides no performance benefit. OptionāÆD is nonsensical because page identifiers have no alphabetical order. Predictive loading is the core idea behind efficient demand paging.
Q6. If memory access time is 0.1āÆms, pageāfault service time is 10āÆms, and the pageāfault rate is , what is the effective access time (EAT) using lazy swapping?
š Explanation: The effective access time combines the time for a normal memory reference and the extra cost when a fault occurs: for hits plus for faults, giving optionāÆC. OptionāÆA omits the hit probability factor. OptionāÆB uses the wrong fault cost, missing the memory access that still occurs during a fault. OptionāÆD swaps the coefficients, implying faults happen on hits. This formula is essential for evaluating the impact of lazy swapping on overall system performance.
Q7. Compare lazy swapping with preāpaging. Which statement best describes their tradeāoff?
š Explanation: Preāpaging brings in a block of pages before they are referenced, which can cause extra disk reads if some pages are never used; lazy swapping loads pages only on demand, reducing unnecessary I/O but potentially incurring more page faults. OptionāÆB captures this balance. OptionāÆA is false because preāpaging can sometimes reduce faults. OptionāÆC is incorrect; lazy swapping does not need more RAM. OptionāÆD is wrong because both techniques still rely on the validāinvalid bit to track page residency. Understanding this tradeāoff helps designers choose the appropriate strategy.
Q8. A programās working set requires 12 pages, but the system has only 10 frames. What is the most likely effect, and how does lazy swapping influence it?
š Explanation: When the working set exceeds available frames, the system repeatedly evicts and reloads pages, causing thrashing. Lazy swapping exacerbates this by loading pages only on demand, which can lead to a high pageāfault rate as each new reference triggers a swap. OptionāÆB correctly describes the outcome. OptionāÆA is opposite to the expected slowdown. OptionāÆC misrepresents lazy swapping, which does not keep all pages resident. OptionāÆD describes a fullāprocess swap, not the pageālevel behavior of lazy swapping. This scenario highlights the importance of matching workingāset size to physical memory.