25-Comp-A5 Operating Systems · May 2017
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) Given. Base (relocation) register $=1200$; limit register $=1500$; logical address $=501$. Find. The physical memory address, or whether the reference is out of bounds. Approach. Base-and-limit translation is a bounds check followed by a simple addition: valid only if $0\le\text{logical}<\text{limit}$, in which case $\text{physical}=\text{base}+\text{logical}$.
| Quantity | Value |
|---|---|
| Bounds check | 501 < 1500 → legal |
| Physical address | 1701 |
(b) Given. Reference string 82, 83, 84, 85, 83, 84, 81, 86, 87, 88, 87, 88, 88, 87, 88, 81 (16 references, frames initially empty); 4 frames; FIFO replacement. Find. Total number of page faults. Approach. Simulate the FIFO queue of resident pages exactly: a fault occurs whenever the referenced page is not resident, and if all 4 frames are already occupied the page resident LONGEST (front of the FIFO queue) is evicted, regardless of how recently it was used.
| Ref# | Page | Outcome | Frames after (oldest→newest) |
|---|---|---|---|
| 1 | 82 | FAULT | 82 |
| 2 | 83 | FAULT | 82, 83 |
| 3 | 84 | FAULT | 82, 83, 84 |
| 4 | 85 | FAULT | 82, 83, 84, 85 |
| 5 | 83 | hit | 82, 83, 84, 85 |
| 6 | 84 | hit | 82, 83, 84, 85 |
| 7 | 81 | FAULT (evicts 82, oldest) | 83, 84, 85, 81 |
| 8 | 86 | FAULT (evicts 83) | 84, 85, 81, 86 |
| 9 | 87 | FAULT (evicts 84) | 85, 81, 86, 87 |
| 10 | 88 | FAULT (evicts 85) | 81, 86, 87, 88 |
| 11 | 87 | hit | 81, 86, 87, 88 |
| 12 | 88 | hit | 81, 86, 87, 88 |
| 13 | 88 | hit | 81, 86, 87, 88 |
| 14 | 87 | hit | 81, 86, 87, 88 |
| 15 | 88 | hit | 81, 86, 87, 88 |
| 16 | 81 | hit | 81, 86, 87, 88 |
| Quantity | Value |
|---|---|
| Page faults (FIFO, 4 frames) | 8 of 16 references |
(c) A priority-based page replacement strategy always evicts the resident page with the numerically lowest priority value (treating priority here as "value to keep resident" — smaller means more disposable). Any classical replacement policy can be reproduced by choosing how a page's priority is set and updated:
(i) FIFO is reproduced by setting a page's priority to (the negative of, or simply) its load timestamp at the moment it is brought into memory, and never updating it again regardless of subsequent references. Example: pages A, B, C, D loaded at times 1, 2, 3, 4 keep priorities 1, 2, 3, 4 forever; whichever page is resident with the smallest timestamp (A, having been loaded longest ago) is evicted first, exactly reproducing "oldest resident page goes first" — the defining FIFO behaviour, indifferent to how often a page has actually been used since loading.
(ii) LRU is reproduced by setting a page's priority to its timestamp at every reference (not just at load time), so a page's priority is continually refreshed to "now" each time it is touched. Example: if A is loaded at $t=1$ and then referenced again at $t=10$ while B (loaded at $t=2$) is never touched again, at $t=11$ A's priority (10) is higher than B's (2), so B — the page whose most recent access is furthest in the past — is evicted first, exactly reproducing "least recently used."
(iii) LFU is reproduced by setting a page's priority to a running COUNT of how many times it has been referenced (incremented by 1 on every reference, starting at 0 or 1 on load), independent of when those references occurred. Example: page A referenced 8 times and page B referenced 2 times both currently resident — B has the lower reference count and is evicted first regardless of which one was touched more recently, exactly reproducing "least frequently used." (A pure counter never decays, so a page that was frequently used long ago but is now cold can resist eviction indefinitely — the well-known weakness of true LFU, sometimes mitigated by periodically halving all counts.)