Course Content
Bonus Section (for Interviews and GATE/Placement prep)
0/1
Operating Systems (OS)
Thrashing and Working Set Model

In a demand paging system, proper memory management is critical to system performance. When memory is overcommitted and page faults occur too frequently, the system can enter a condition called thrashing. To prevent this, operating systems use strategies like the Working Set Model to manage memory more intelligently.


What Is Thrashing?

Thrashing is a situation where the operating system spends more time swapping pages in and out of memory than executing actual processes.

It happens when:

 

  • Too many processes are competing for limited memory.
  • Each process doesn’t have enough frames to hold its active pages.
  • As a result, frequent page faults occur, slowing down all programs drastically.

 

Symptoms of Thrashing:

 

  • High CPU wait time.
  • Constant disk activity.
  • Low throughput (few instructions executed despite high CPU usage).

Causes of Thrashing
Cause Explanation
Overloading the system Too many active processes exceed available memory.
Poor page replacement strategy Frequently replacing needed pages causes more faults.
Lack of locality awareness Ignoring temporal/spatial patterns of page use.
No working set awareness Not knowing which pages a process truly needs during its execution window.

The Working Set Model

 

To combat thrashing, the Working Set Model was introduced by Peter Denning.

A working set is the set of pages a process is actively using during a given time interval. The model ensures each process is allocated enough frames to hold its working set.


Key Concepts
Term Description
Δ (Delta) A fixed time window (e.g., last N instructions or seconds).
Working Set (W) All pages the process referenced in the last Δ time window.
WSS (Working Set Size) The number of pages in a process’s working set.

If:

 
  • Σ WSS of all processes < total available frames → System runs efficiently.
  • Σ WSS > total available frames → Thrashing may occur.

Benefits of Working Set Model
Benefit Explanation
Minimizes page faults By keeping necessary pages in memory.
Avoids thrashing Prevents memory overcommitment by controlling process loads.
Informs load control OS can suspend or swap out processes when memory is overused.
Enables smarter allocation Frames are allocated based on real usage, not assumptions.

Difference Between Locality and Working Set

 

While locality refers to patterns of memory access (e.g., accessing the same few pages repeatedly), the working set defines the explicit set of pages based on recent access. The working set is essentially a quantification of locality.


Real-World Analogy

Imagine you’re studying with 10 open books. You usually refer to 3 books repeatedly in the last 30 minutes. These 3 books are your working set. If your desk is too small (not enough frames) and you keep swapping books every few minutes, you’re thrashing—wasting time switching instead of studying.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.