4.1.17 · D4Computer Architecture (Deep)

Exercises — Working set model, thrashing

2,714 words12 min readBack to topic

Before we start, one reminder of the two symbols we lean on the whole way down — earned in the parent note, restated here so nothing is assumed:


Level 1 — Recognition

Exercise 1.1

A process's window is set to . Its recent reference string (oldest → newest) is What is at this instant?

Recall Solution 1.1

WHAT we do: take the last references and count the distinct pages. The window: . The four touches are all page . Distinct pages: just . WHY: the working set counts which pages, not how many touches. Repeats collapse. This is exactly the "run of 7s" behaviour from the parent trace — high temporal locality ⇒ tiny working set.

Exercise 1.2

State whether each is measured in seconds or in memory references: (a) the window , (b) a page-fault rate .

Recall Solution 1.2

(a) memory references (virtual time). It must be speed-independent so the same code has the same working-set behaviour on any CPU. (b) = faults per reference (or per unit time as a rate) — a frequency, faults divided by references. The core insight to keep: is a count, not a clock.


Level 2 — Application

Exercise 2.1

Reference string: with . Compute for the last three positions (, 1-indexed).

Recall Solution 2.1

Method: at each , slide a window over the last 4 references and count distinct pages. The string, indexed: pos1=4, pos2=5, pos3=6, pos4=4, pos5=5, pos6=6, pos7=7, pos8=7, pos9=5, pos10=4.

last-4 window distinct set
8 (pos5–8) 5 6 7 7 {5,6,7} 3
9 (pos6–9) 6 7 7 5 {5,6,7} 3
10 (pos7–10) 7 7 5 4 {4,5,7} 3

WHY it stays at 3: the double- (temporal locality) keeps the distinct count below the window width of 4. At page 6 falls off the back and page 4 enters the front — count holds. See the sliding-window picture:

Figure — Working set model, thrashing

Exercise 2.2

Four processes share frames with working-set sizes Is the system thrashing? Show the demand calculation.

Recall Solution 2.2

Step 1 — total demand. Sum the live demands: Step 2 — compare with supply. WHY: every process needs its whole working set resident to run without constant faulting. Demanding 22 frames when only 20 exist means at least 2 live pages get evicted and immediately re-faulted — the swap-storm begins.


Level 3 — Analysis

Exercise 3.1

The parent note draws a CPU-utilization cliff: utilization rises with the multiprogramming degree, then collapses. Explain why the collapse is a cliff (sudden) and not a gentle slope, in terms of the demand condition .

Recall Solution 3.1

WHAT happens as we add processes: each new process adds its to the total demand . While , every working set fits, faults are rare, and overlapping I/O keeps CPU busy → utilization climbs. The tipping point: the moment crosses , you cannot fit all working sets. Now evicting one live page causes a fault, whose service evicts another live page, which faults... The fault rate does not drift up linearly — it compounds, because each process's shrunken resident set makes it fault more, and every fault steals service time from everyone. Why a cliff, not a slope: below the fault rate is near zero; the marginal page still fits. Just above the marginal page does not fit, and its absence triggers a chain of mutual eviction (positive feedback). A threshold with feedback past it = a cliff. The scheduler's fatal reflex: it sees low CPU use, misreads it as "idle CPU", and adds a process — pushing even further above . The feedback tips the graph off the edge.

Figure — Working set model, thrashing

Exercise 3.2

A process runs with through a phase change. Its reference string is Track across the boundary (positions 6→9) and explain the bump.

Recall Solution 3.2

Indexed: pos1=1,2,1,2,1,2(pos6),8(pos7),9(pos8),8(pos9),9(pos10).

last-3 window distinct
6 2 1 2 {1,2} 2
7 1 2 8 {1,2,8} 3
8 2 8 9 {2,8,9} 3
9 8 9 8 {8,9} 2

The bump: during pure phase P the count sits at 2. At the boundary () the window straddles both phases — it still remembers old pages while new pages stream in, so the count temporarily rises to 3. Once the window has fully moved into phase Q (), the stale pages drop off and it settles at 2 again. WHY this matters: the working set transiently over-estimates at every phase boundary. This is exactly why must roughly match the phase length — too large a makes the "bump" permanent, wasting frames on dead pages.


Level 4 — Synthesis

Exercise 4.1

Frames . Three processes: (a) Show it thrashes. (b) You may suspend exactly one process. Which choice restores with the most slack, and how much slack results?

Recall Solution 4.1

(a) ⇒ thrashing. (b) Test each suspension — compute the surviving demand and the slack :

Suspend New Slack Feasible?
(5)
(4)
(6)

Choose . Suspending the largest working set frees the most frames, giving the most slack ( frames). A and B run cleanly; C resumes when a working set fits. WHY prefer maximum slack: headroom absorbs the transient bumps at phase boundaries (Exercise 3.2) without re-triggering thrashing.

Exercise 4.2

Same three processes, but now the OS uses Page-Fault-Frequency (PFF) control with bounds and . Process currently holds frames and its measured fault rate is ; there is 1 free frame. Trace what PFF does over the next two decisions if giving the frame drops below but still above .

Recall Solution 4.2

Decision 1: and a free frame exists → PFF grants one frame. Now holds frames. Effect: more of 's working set is resident → its fault rate falls. Given: now . Decision 2: sits in the dead band → PFF does nothing. Neither (would grant) nor (would revoke) fires. WHY the dead band exists: it prevents oscillation — without a gap between and , the controller would grant a frame, drop below threshold, revoke it, fault again, grant again... forever. The band is hysteresis that servo-controls the resident set toward "just enough" ≈ the working set, without ever enumerating .


Level 5 — Mastery

Exercise 5.1 (Design & defend)

You manage frames. Four processes arrive with working-set sizes (a) Compute and decide if all four can run. (b) If not, you must suspend the fewest processes to make . Which do you suspend and what is the resulting slack? (c) Justify why suspending whole processes beats simply shrinking everyone's frame allocation proportionally.

Recall Solution 5.1

(a) . Overcommitted by frames ⇒ thrashing. (b) We must shed at least frames of demand. Sort working sets descending: .

  • Suspend one: the biggest is . That alone works. New , slack . ✓
  • Could a smaller single suspension work? Need the freed amount . works too but gives less slack (, slack ). → slack ; → slack (tie with D by count but D frees most). Best single suspension: suspend (or ) — freeing (resp. ) frames. Suspending gives new , slack , the largest headroom while removing only one process. (c) Why suspend whole processes rather than shrink everyone: if you cut every process below its working-set size, each one now faults on its own live pages — you convert one over-committed system into four permanently-faulting ones. Utilization collapses for all. Suspending one process keeps the survivors' working sets intact, so they run at full speed while the suspended one waits its turn. Better to run some processes fast than all at a crawl — the parent note's core allocation principle.

Exercise 5.2 (Choose )

A workload has locality phases each lasting about references. Explain the consequence of choosing (a) , (b) , and (c) , in terms of over/under-estimating the working set.

Recall Solution 5.2

(a) (far too small): the window sees only a fraction of the current phase, so it under-estimates — some genuinely-live pages fall outside the window, get evicted, and are re-faulted almost immediately. Result: thrashing within a phase. (b) (far too large): the window spans roughly ten phases at once, so it keeps stale pages from long-finished phases resident. This over-estimates , wastes frames, and lowers the multiprogramming degree (fewer processes fit). (c) (matched): the window covers one phase, dropping old pages just as new ones enter (the "bump" from Exercise 3.2 stays brief). This tracks the true working set — enough to avoid faults, no more. Tune to the phase length.


Connections to revisit

  • The prediction only works because of Locality of Reference — recently used ⇒ soon used.
  • Faults are serviced by Demand Paging and Page Fault Handling; which page leaves is decided by Page Replacement Algorithms.
  • The count of concurrent processes is the Multiprogramming Degree whose cliff you analysed in L3.
  • Hardware caches of translations live in TLB and Caches.
  • Hinglish walkthrough: 4.1.17 Working set model, thrashing (Hinglish).

Final Active Recall

Which quantity is measured in memory references, or CPU time?
— it is a count of memory references (virtual time), never seconds.
In Exercise 4.1, which process should be suspended and why?
() — freeing the largest working set gives the most slack ( frames).
Why is the CPU-utilization drop a cliff rather than a slope?
Crossing triggers mutual page eviction with positive feedback, so the fault rate compounds instead of drifting.
In PFF, what is the purpose of the gap between and ?
A hysteresis dead band preventing oscillation — grant/revoke chatter around a single threshold.
Why suspend a whole process instead of shrinking everyone's frames?
Shrinking below each working set makes all processes fault; suspending one keeps survivors' working sets intact and fast.