Chapter 6

Virtual memory

Demand paging keeps a working subset of a virtual address space in physical frames. Questions combine translation, replacement and the large time cost of faults. Keep the reference sequence and the probability model separate.

6.1 Demand paging and fault service

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks

On a nonresident but legal reference, the handler obtains a frame, writes back a dirty victim if required, fetches or creates the needed page, updates mappings, and resumes the faulting instruction. A page fault can also implement copy-on-write or zero-fill; not every fault requires a disk read. An illegal reference is rejected rather than made valid by paging.

6.2 Replacement algorithms

Past papers · CS 2014–2026 (23 papers): 9 questions, 17 marks

Start with the given frames, not an assumed empty memory. For each reference, first check residency. Only a miss can require replacement; with an empty frame, fill it before evicting anything.

AlgorithmVictim on a full-memory missEffect of a hit
FIFOEarliest loaded resident pageDoes not change arrival order
LRUResident page whose last use is oldestUpdates recency
OPT/MINResident page whose next use is farthest awayNo eviction; future knowledge defines choices
Second chance/ClockFirst candidate with reference bit zero during circular scanSets reference bit
LIFOMost recently loaded resident pageDoes not change load order
MRUMost recently used resident pageUpdates recency
LFU / MFUSmallest / largest reference countIncrements the page's count

For frequency policies, state whether counts survive eviction, how new pages are initialised, and how ties are broken. A limited look-ahead version of OPT follows its specified window; it need not achieve full OPT's fault count.

For Clock, a reference sets the page's reference bit. During victim search, clear a one bit and advance; replace a zero-bit page and advance the hand according to the stated implementation. Initial hand position and insertion-bit convention can change the trace.

6.3 Stack property and frame allocation

Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks

LRU and OPT have the stack property: for the same reference prefix, the resident set with mm frames can be nested inside that with m+1m+1 frames, using consistent tie choices. Increasing capacity cannot increase their fault count. FIFO and random replacement can exhibit Belady's anomaly; “more frames always means fewer faults” is false for arbitrary algorithms.

Local replacement selects victims from the faulting process's allocation; global replacement can take a frame from another process. Global policy couples fault rates across processes. A dirty page only requires write-back if its current contents must be preserved and no valid backing copy already contains them.

6.4 Working sets and thrashing

Thrashing means paging consumes so much activity that useful execution collapses. A low CPU-utilisation reading can result from processes waiting for paging I/O; admitting more processes can then make performance worse. Reduce the active population or allocate enough frames for its locality. Page-fault-frequency control adds frames when a process's fault rate is too high and can reclaim them when it is sufficiently low.

6.5 Copy-on-write, sharing and locality

Copy-on-write marks shared private pages nonwritable after fork. A write fault creates a private copy when sharing requires it, then retries the write. Reading alone does not duplicate the page. Shared read-only code can remain shared; intentionally shared writable memory has different semantics from private copy-on-write memory.

For page counts after fork, track physical pages and mappings separately. A single physical page may have two PTEs and later become two physical pages. On replacement or permission changes, stale TLB entries must be made consistent with the new mapping.

Last-minute recall

  • Fault cost is either complete-path time or additional penalty; choose one model.
  • Dirty-victim probability is conditional on the fault path being counted.
  • Count initial fills as faults when frames are initially empty.
  • FIFO age is load age; LRU age is last-use age.
  • OPT is a benchmark using future references, not a practical predictor.
  • More frames cannot hurt LRU or OPT for a fixed trace.
  • A working-set window counts distinct pages, not total references.
  • Copy-on-write duplicates on a relevant write, not on every fork-time read.

Revise offline: the whole Operating System handbook as one PDF

50 pages · 2.0 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections