What is thrashing, why does it happen, and how can it be prevented?
HardConceptPage Replacement & Thrashing
Answer
Thrashing is a state in which the system spends more time moving pages between RAM and disk than running programs. It happens when the active processes together need more frames than memory has, so each fault evicts a page that is needed again almost at once.
- Vicious cycle: CPU utilisation drops because processes wait for the disk. A naive OS sees the idle CPU and admits more processes, raising the degree of multiprogramming (the number of processes in memory), which makes it worse.
- Working-set model: a process's working set is the set of pages it used in its last Δ references. If the working sets add up to more than the available frames, the OS suspends (swaps out) a process.
- Page-fault frequency: give a process more frames when its fault rate is above an upper limit, and take frames away when it is below a lower limit.
- Simpler fixes: run fewer processes or add RAM.
Example: with Δ = 5 and last references 2, 6, 1, 5, 7, the working set is {1, 2, 5, 6, 7}. If three processes have working sets of 5, 4 and 6 pages (15 in total) but only 12 frames exist, the OS should suspend one process rather than let all three thrash. A laptop frozen by too many browser tabs while the disk works constantly is thrashing.
More in Page Replacement & Thrashing
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Compare FIFO, LRU and Optimal page replacement. | Concept | Medium | Read the answer to Compare FIFO, LRU and Optimal page replacement. | |||
| 2 | What is Belady's anomaly? | Concept | Medium | Read the answer to What is Belady's anomaly? | |||
| 3 | Why is exact LRU expensive, and how does the clock algorithm approximate it? | Concept | Hard | Read the answer to Why is exact LRU expensive, and how does the clock algorithm approximate it? | |||
| 4 | What is thrashing, why does it happen, and how can it be prevented? | Concept | Hard | Read the answer to What is thrashing, why does it happen, and how can it be prevented? |