Explaining thrashing and load control design
Thrashing occurs when the system spends most of its time swapping pages in and out instead of executing processes, causing CPU utilization to drop as multiprogramming increases. The working set model tracks the set of pages a process actively uses within a recent time window; if the total working sets exceed available memory frames, thrashing arises. To control load, a mechanism monitors working set sizes and, when their sum surpasses RAM capacity, it selectively suspends processes—typically those with large working sets or lower priority—to free memory and reduce multiprogramming, allowing the system to recover. This approach uses page fault frequency and working set tracking to detect and mitigate thrashing effectively.
In a demand–paged system the CPU only makes progress when the working set of pages for whatever is running can be kept in memory. If you turn the degree of multiprogramming up too far, you reach a point where you don't have enough page frames to hold the active parts of all of the processes. The page‑fault rate spikes, the pager spends all of its time evicting a page that will be referenced again a few milliseconds later, and the processors are mostly idle waiting for I/O. That pathological state is what people mean by “thrashing”.
One way of reasoning about and avoiding thrashing is Denning's working–set model. For each process (i) at time (t), define (W_i(t,\Delta)) as the set of distinct pages it has referenced in the trailing window of length (\Delta) (for example the last 10 000 references or the last 100 ms of execution). (|W_i|) is a measure of that process's current locality; if you allocate roughly (|W_i|) frames to the process it should be able to run with a low fault rate. The system as a whole needs (\sum_i |W_i|) frames to support all processes’ current working sets. If (\sum_i |W_i|) approaches or exceeds the number of physical frames (M), the system is at risk of thrashing.
A simple load‑control mechanism based on this model looks like this:
- The pager maintains, for each runnable process, an estimate of its working set size. This can be done by timestamping page references and counting distinct pages in a sliding window, or more cheaply with page‑fault frequency heuristics.
- Periodically, or when a fault occurs, the kernel computes the total demand (D = \sum_{i \in \text{runnable}} |W_i|).
- If (D \leq M - \text{reserve}), all processes remain runnable and the page replacement algorithm can keep each working set resident.
- If (D > M), the kernel reduces the degree of multiprogramming by selecting one or more processes to suspend. Suspending consists of stopping the process, writing its resident pages back to disk, and reclaiming its frames.
- Victim selection can be based on priority, working set size, or recent CPU usage: for example, choose the lowest‑priority process with the largest (|W_i|) to free up the most frames with the least impact.
- After removing a victim, recompute (D); repeat until (D) fits in (M).
- As memory pressure eases and (D) falls well below (M), previously suspended processes can be resumed, loading their working set back into memory.
By monitoring each process’s working set and throttling the number of concurrently active processes, this form of load control keeps the total resident demand within the limits of physical RAM and prevents the system from entering a thrashing state.