šŸŽ“ BookMCQ
← Back to 9. Virtual Memory

šŸ“ 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.
2
Easy
3
Medium
3
Hard

šŸ“ 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?

A.It issues a page fault and loads page 2 from disk.
B.It finds page 2 already valid and continues execution. āœ…
C.It swaps out another page to make room for page 2.
D.It terminates the process due to invalid reference.
šŸ’” Difficulty: easy | āœ… Correct: B

šŸ“– 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?

A.It reduces disk I/O by loading only needed pages. āœ…
B.It guarantees that all pages are always in memory.
C.It eliminates the need for a page table.
D.It increases the size of the swap file.
šŸ’” Difficulty: easy | āœ… Correct: A

šŸ“– 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?

A.The page is illegal and cannot be accessed.
B.The page is currently stored on disk.
C.The page is legal and present in physical memory. āœ…
D.The page is reserved for future use.
šŸ’” Difficulty: medium | āœ… Correct: C

šŸ“– 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?

A.FIFO
B.LRU āœ…
C.Random
D.Optimal (theoretical)
šŸ’” Difficulty: medium | āœ… Correct: B

šŸ“– 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?

A.It loads all pages whose valid–invalid bit is set to invalid.
B.It predicts future references and loads pages likely to be used soon. āœ…
C.It randomly selects pages from the process’s address space.
D.It loads pages in alphabetical order of their identifiers.
šŸ’” Difficulty: medium | āœ… Correct: B

šŸ“– 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 pp, what is the effective access time (EAT) using lazy swapping?

A.EAT=0.1+pƗ10EAT = 0.1 + p \times 10
B.EAT=0.1Ɨ(1āˆ’p)+10ƗpEAT = 0.1 \times (1-p) + 10 \times p
C.EAT=0.1Ɨ(1āˆ’p)+(0.1+10)ƗpEAT = 0.1 \times (1-p) + (0.1 + 10) \times p āœ…
D.EAT=10Ɨ(1āˆ’p)+0.1ƗpEAT = 10 \times (1-p) + 0.1 \times p
šŸ’” Difficulty: hard | āœ… Correct: C

šŸ“– Explanation: The effective access time combines the time for a normal memory reference and the extra cost when a fault occurs: (1āˆ’p)Ɨ0.1(1-p) \times 0.1 for hits plus pƗ(0.1+10)p \times (0.1+10) 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?

A.Lazy swapping always yields fewer page faults than pre‑paging.
B.Pre‑paging may load unnecessary pages, increasing I/O, while lazy swapping avoids that at the risk of more faults. āœ…
C.Lazy swapping requires more RAM than pre‑paging.
D.Pre‑paging eliminates the need for a valid‑invalid bit.
šŸ’” Difficulty: hard | āœ… Correct: B

šŸ“– 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?

A.The system will run faster because lazy swapping caches extra pages.
B.The system will experience thrashing; lazy swapping may increase fault frequency because pages are loaded only when needed. āœ…
C.The system will never swap pages because lazy swapping keeps all pages in memory.
D.The system will swap out the entire process each time a new page is needed.
šŸ’” Difficulty: hard | āœ… Correct: B

šŸ“– 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.

šŸ”— Related Topics (MCQs)