25-Comp-A5 Operating Systems · December 2015
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
(a) A demand-paged virtual memory system divides a process's logical address space into fixed-size pages, but loads a page into a physical memory frame only when it is actually referenced for the first time (on demand), rather than loading the entire process up front. A reference to a page not currently resident triggers a page fault, which the OS services by fetching the page from backing store (disk), possibly first evicting a resident page to free a frame. Advantages: (1) a process can run with far less physical memory than its total logical address-space size, since only the pages actually touched are ever resident; (2) more processes can be kept in memory simultaneously (higher degree of multiprogramming), improving CPU utilization; (3) a process can start executing before all of it is loaded, reducing startup latency; (4) unused code paths (error handlers, rarely-taken branches) may never be loaded at all, saving both memory and the I/O time to fetch them.
(b) Demand paging works because real programs exhibit the principle of locality of reference: at any point in execution a program references only a small, slowly-changing subset of its total address space. Spatial locality (nearby addresses tend to be referenced close together in time — sequential instruction execution, array traversal) means that once a page is fetched, most of the memory accesses that follow will hit other bytes already on that same page, amortizing the fault's cost. Temporal locality (recently referenced addresses tend to be referenced again soon — loop bodies, frequently-called subroutines) means that once a page is resident it will likely be reused many times before it needs to be evicted, again amortizing the one-time fault cost over many cheap in-memory accesses. Together these give programs a small, stable working set of pages that captures the overwhelming majority of memory references at any given time, which is exactly why loading only that working set (demand paging) achieves near-full-memory performance at a fraction of the physical memory footprint.
(c) Given. Page-fault service time: 20 ms if an empty frame is available or the replaced page is unmodified; 50 ms if the replaced page is modified. Memory access time $m_a=100$ ns. 60% of page faults require replacing a modified page (cost 50 ms); by implication the remaining 40% cost 20 ms. Find. The maximum page fault rate $p$ such that the effective access time (EAT) does not exceed 200 ns. Approach. Compute the fault-rate-weighted average page-fault service time, substitute into the standard EAT formula $EAT=(1-p)m_a+p\cdot t_{fault}$, and solve the resulting inequality for $p$.
| Quantity | Value |
|---|---|
| Weighted average page-fault service time | 38,000,000 ns (38 ms) |
| Maximum acceptable page fault rate | ≈ 2.632 × 10-6 (≈ 1 in 380,000 references) |