1. Why Simple Working Set Is Too Expensive
While the theoretical Working Set model prevents thrashing by ensuring a process's active pages (w(k, t)) remain resident in RAM, implementing it naively is impractical. In a basic working set algorithm, every single page fault triggers a linear scan across all allocated page table entries to evaluate whether their age exceeds \tau. On systems with gigabytes of RAM and hundreds of thousands of frames, this O(N) traversal consumes an unacceptable number of CPU cycles.
2. The WSClock Innovation: Circular List with Asynchronous Flushing
To solve this problem, Carr and Hennessy formulated WSClock. Like the standard Clock algorithm, all allocated page frames are linked in a circular ring traversed by a single moving hand. When a page fault occurs, the hand examines the page pointed to and evaluates four specific criteria:
Let Tcurrent be the process's current virtual execution time, and let \tau be the working set age threshold.
1. If R = 1: The page was referenced recently. Clear R ← 0, update Time of Last Use ← Tcurrent, and advance the hand.
2. If R = 0 and (Tcurrent - Time) ≤ \tau: The page is still within the active working set window. Do not evict; advance the hand.
3. If R = 0 and (Tcurrent - Time) > \tau and M = 0: The page is cold and clean. Immediate Victim! Evict this page, claim the frame, and finish.
4. If R = 0 and (Tcurrent - Time) > \tau and M = 1: The page is cold but dirty. To avoid blocking the CPU, schedule an asynchronous disk write and keep advancing the hand in search of a clean candidate.
3. Handling Full Hand Sweeps
If the clock hand completes a full 360-degree rotation without finding an evicted clean page:
- If at least one write was scheduled: The hand continues advancing until the first scheduled write completes, allowing that newly clean frame to be reclaimed.
- If no writes were scheduled: All resident pages have R=1 or are within the working set \tau. The process is genuinely thrashing under severe memory pressure, so the OS picks the first clean page it encounters or falls back to standard Clock.
Part 3: Interactive WSClock Ring Simulator
Simulate reference streams, dirty write flushes, and observe real-time clock hand sweeps.
| Frame | Page | R | M | Last Used | Age | Status |
|---|