25-Comp-A5 Operating Systems · May 2014
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) The working set model defines, for each process at time $t$, the set $WS(t,\Delta)$ of distinct pages it has referenced in the most recent $\Delta$ references (the "working set window") — an operational approximation of the process's locality of reference at that moment. The OS tracks each running process's working-set size and only keeps a process resident (fully loaded and eligible to run) if the sum of all resident processes' working sets fits within physical memory; if a process's working set would not fit, that process is suspended (swapped out entirely) rather than left to run with too few frames. It prevents thrashing — the pathological state where the system spends nearly all its time servicing page faults rather than doing useful work, because every process has fewer frames than its own current locality requires — precisely by refusing to over-commit memory in the first place: the working-set admission test is a direct, continuously-recomputed measurement of how many frames each active process genuinely needs right now, so the degree of multiprogramming is throttled down (processes suspended) exactly when the combined working sets would exceed physical memory, before thrashing can start, rather than reacting after CPU utilization has already collapsed.
Given. Page reference string (17 references): 71, 72, 73, 74, 75, 73, 74, 71, 76, 77, 78, 77, 78, 79, 77, 78, 79; three page frames, all empty at the start; demand paging (a page loads only on the reference that first faults it in); FIFO replacement.
Find. The total number of page faults incurred by FIFO with 3 frames.
Approach. Step through the reference string maintaining the 3 resident frames as a FIFO queue; on a fault with all frames full, evict whichever resident page was loaded longest ago (regardless of how recently it was actually used — this is what distinguishes FIFO from LRU).
| Ref # | Page | Hit/Fault | Frames after (oldest→newest) |
|---|---|---|---|
| 1 | 71 | Fault | 71 |
| 2 | 72 | Fault | 71, 72 |
| 3 | 73 | Fault | 71, 72, 73 |
| 4 | 74 | Fault (evict 71) | 72, 73, 74 |
| 5 | 75 | Fault (evict 72) | 73, 74, 75 |
| 6 | 73 | Hit | 73, 74, 75 |
| 7 | 74 | Hit | 73, 74, 75 |
| 8 | 71 | Fault (evict 73) | 74, 75, 71 |
| 9 | 76 | Fault (evict 74) | 75, 71, 76 |
| 10 | 77 | Fault (evict 75) | 71, 76, 77 |
| 11 | 78 | Fault (evict 71) | 76, 77, 78 |
| 12 | 77 | Hit | 76, 77, 78 |
| 13 | 78 | Hit | 76, 77, 78 |
| 14 | 79 | Fault (evict 76) | 77, 78, 79 |
| 15 | 77 | Hit | 77, 78, 79 |
| 16 | 78 | Hit | 77, 78, 79 |
| 17 | 79 | Hit | 77, 78, 79 |
(c) Fragmentation in memory management comes in two forms. External fragmentation arises with variable-sized partition allocation (or contiguous memory generally): as processes are loaded and removed, free memory becomes broken into many small, non-adjacent holes, and even though their total may be more than enough for a new request, no single hole is large enough to satisfy it. It is controlled by compaction (periodically sliding all allocated regions together to consolidate free space into one block — costly, since it typically requires relocating running processes) or, more fundamentally, by abandoning contiguous allocation altogether in favour of paging, which allocates memory in fixed-size frames so any free frame can satisfy any request, eliminating external fragmentation by design. Internal fragmentation is the flip side: with fixed-size allocation units (pages, or fixed partitions), a process's last page is usually only partially used, wasting the unused remainder of that page/partition; it is controlled by choosing a smaller page size (reduces the average per-process waste, at the cost of a larger page table) or, for partitions, choosing partition sizes that better match typical process sizes. Fragmentation in disk block allocation is conceptually the same family of problem: contiguous disk allocation suffers external fragmentation identically to contiguous memory (free disk space breaks into scattered extents, requiring disk compaction/defragmentation utilities), while fixed-block allocation (the norm for disks) suffers internal fragmentation whenever a file's size is not an exact multiple of the block size, wasting the unused tail of its last block — the same smaller-block-size trade-off applies, and clustering strategies (allocating in multi-block "extents" for large files) trade a little internal fragmentation back for reduced external fragmentation and fewer, larger disk transfers.