Course contentsShow
← Computer Science
Lesson 1377 of 2,87231. Memory ManagementFree lesson

Thrashing and Prevention

Recognizing when excessive paging degrades performance and strategies to prevent it.

Thrashing and Prevention

You'll learn: How to recognize when a system grinds to a halt from excessive paging and what strategies can prevent this performance catastrophe.

What is Thrashing?

Thrashing occurs when a computer spends more time swapping pages in and out of memory than actually executing processes. It's a vicious cycle: when too many processes are active and each has too few frames, they constantly page fault, triggering more page faults as the system tries to service them.

Imagine a librarian who can only hold 3 books at a time, but has 10 customers each demanding different books every few seconds. The librarian spends all day running back and forth to the shelves and never actually helps anyone check out—that's thrashing.

Signs of Thrashing

  • CPU utilization drops dramatically (despite high process load)
  • Disk I/O activity spikes
  • System becomes unresponsive
  • Page fault rate skyrockets

The operating system misinterprets low CPU usage as "I should admit more processes," which only makes thrashing worse.

Prevention Strategies

1. Working Set Model
Ensure each process has enough frames to hold its working set—the pages it actively uses. If the system can't provide this minimum, don't admit the process.

2. Page Fault Frequency (PFF) Monitoring
Set acceptable upper and lower bounds for page fault rates. When a process exceeds the upper threshold, allocate more frames. If all processes are below the lower threshold, the system can admit more processes.

3. Limit Multiprogramming
Use a local replacement policy and control the degree of multiprogramming—suspend processes when memory pressure is too high.

4. Priority-Based Suspension
Temporarily swap out lower-priority processes to give high-priority ones sufficient frames.

Key Takeaway: Thrashing happens when processes lack enough frames for their working sets, causing constant paging; prevent it by monitoring page fault frequency, respecting working set requirements, and limiting the number of concurrent processes.