25-Comp-A5 Operating Systems · December 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.
Given. Page reference string of 17 references over 9 distinct pages (171, 172, 173, 174, 177, 178, 179, 275, 276); 3 frames; pure LRU replacement (no pre-loading — each frame starts empty and the first reference to a page is always a fault).
Find. Total number of page faults.
Approach. Step through the reference string one access at a time, keeping a 3-slot frame set and a recency stamp per resident page; on a miss with a full frame set, evict the page with the oldest recency stamp.
| Ref # | Page | Frames after | Result |
|---|---|---|---|
| 1 | 171 | 171 | F |
| 2 | 172 | 171,172 | F |
| 3 | 173 | 171,172,173 | F |
| 4 | 174 | 172,173,174 (evict 171) | F |
| 5 | 275 | 173,174,275 (evict 172) | F |
| 6 | 173 | 173,174,275 | H |
| 7 | 174 | 173,174,275 | H |
| 8 | 171 | 173,174,171 (evict 275) | F |
| 9 | 276 | 174,171,276 (evict 173) | F |
| 10 | 177 | 171,276,177 (evict 174) | F |
| 11 | 178 | 276,177,178 (evict 171) | F |
| 12 | 177 | 276,177,178 | H |
| 13 | 178 | 276,177,178 | H |
| 14 | 179 | 177,178,179 (evict 276) | F |
| 15 | 177 | 177,178,179 | H |
| 16 | 178 | 177,178,179 | H |
| 17 | 179 | 177,178,179 | H |
Counting the F entries: references 1–5, 8, 9, 10, 11, 14 are faults. $$\boxed{\text{Total page faults}=10}$$
Given (b). Free list (in list order): 302K, 243K, 405K, 480K, 270K, 291K, 325K, 350K. Jobs arrive strictly in the order Job1(322K)→Job2(305K)→Job3(403K)→Job4(290K); no job releases memory during this sequence.
Find. Which hole each job is allocated under (i) best fit and (ii) first fit.
Approach. Best fit scans the whole free list for the smallest hole that is still ≥ the request; first fit scans from the head of the list and takes the first hole ≥ the request. After an allocation the hole shrinks by the request size (the leftover remainder stays in the free list at the same position); if a hole is reduced to 0 it is removed.
| Job | Request | Smallest sufficient hole | Remainder left behind |
|---|---|---|---|
| Job 1 | 322K | 325K | 325−322 = 3K |
| Job 2 | 305K | 350K (only 350/405/480 still ≥305; 325 now only 3K) | 350−305 = 45K |
| Job 3 | 403K | 405K | 405−403 = 2K |
| Job 4 | 290K | 291K | 291−290 = 1K |
Free list after all four jobs (best fit): 302K, 243K, 2K, 480K, 270K, 1K, 3K, 45K — every job is placed, with four slivers (1–45K) left as unusable fragments.
| Job | Request | First sufficient hole (scanning from list head) | Remainder left behind |
|---|---|---|---|
| Job 1 | 322K | 405K (302K, 243K both too small) | 405−322 = 83K |
| Job 2 | 305K | 480K (302, 243, 83 all too small) | 480−305 = 175K |
| Job 3 | 403K | none — allocation fails | — |
| Job 4 | 290K | 302K (head of list) | 302−290 = 12K |
| Quantity | Value |
|---|---|
| LRU page faults (3 frames) | 10 |
| Best fit: Job1/Job2/Job3/Job4 → hole | 325K / 350K / 405K / 291K (all placed) |
| First fit: Job1/Job2/Job3/Job4 → hole | 405K / 480K / fails / 302K |