Thrashing & the Working Set
When the working sets of running processes do not fit in memory, the system spends its life paging. That is thrashing: the CPU is busy, but no useful work is happening.
In plain English
Thrashing is running between the desk and the shelf so much that no reading gets done.
By the end you will be able to
- Define thrashing and its symptoms.
- Explain the working-set model.
- Relate degree of multiprogramming to page faults.
- Know the common controls for thrashing.
The failure loop
A process faults, so the kernel evicts a page. That page belongs to another active process, which faults soon after. The kernel evicts another page, and the cycle repeats. Disk I/O dominates, CPU utilization collapses, and the scheduler may add more processes because the CPU looks idle, making everything worse.
The working set
The working set is the set of pages a process has referenced in a recent window. If the sum of all working sets is larger than physical memory, thrashing is likely. The OS can reduce the degree of multiprogramming, admit fewer processes, or allocate more frames to the processes that need them.
working_set(process, window) =
pages referenced in the last window of time
if sum(working_sets) > physical_frames:
reduce multiprogrammingControls
A page-fault-frequency policy monitors each process's fault rate. If the rate is too high, the process needs more frames; if it is too low, it may have too many. The OS can also use a working-set policy to suspend processes whose working sets cannot fit. Adding RAM is the direct fix, but it is not always possible.
Key takeaways
- Thrashing is excessive paging with little useful work.
- It happens when working sets exceed physical memory.
- Adding more processes can make thrashing worse.
- Working-set and page-fault-frequency policies control it.
- Reducing multiprogramming is a common emergency response.
Common pitfalls
- Thinking high CPU utilization always means useful work; thrashing can show high kernel activity.
- Adding processes when the system is already thrashing.
- Confusing a high page-fault rate with a normal cold start.
Kernel notes
- Explain the thrashing feedback loop.
- Define the working set.
- Name two controls for thrashing.
Quick check
1. What is thrashing?
2. What often happens if the scheduler adds more processes during thrashing?