0
0
Operating Systemsknowledge~6 mins

Thrashing and working set model in Operating Systems - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine your computer slowing down drastically because it keeps switching between tasks without making real progress. This problem happens when the system spends too much time moving data in and out of memory instead of running programs smoothly.
Explanation
Thrashing
Thrashing occurs when a computer's memory is overloaded and it spends most of its time swapping data between the main memory and disk. This constant swapping leaves little time for actual program execution, causing severe slowdowns. It usually happens when too many programs run simultaneously or when programs require more memory than available.
Thrashing is when excessive memory swapping causes the system to slow down drastically.
Working Set Model
The working set model helps the system decide how much memory each program needs to run efficiently. It tracks the set of pages a program uses actively during a recent time window. By keeping these pages in memory, the system reduces the chance of thrashing and improves performance.
The working set model identifies the active memory pages a program needs to avoid thrashing.
Working Set Window
The working set window is the time period during which the system observes which pages a program accesses. This window helps determine the current working set. If the window is too short, the system might miss important pages; if too long, it might keep unnecessary pages in memory.
The working set window defines how the system measures a program's active memory usage.
Relation Between Thrashing and Working Set
When the total working sets of all running programs exceed the available memory, thrashing can occur. The system uses the working set model to balance memory allocation and prevent thrashing by ensuring enough pages stay in memory for each program.
Managing working sets helps prevent thrashing by balancing memory use among programs.
Real World Analogy

Imagine a small kitchen where several cooks try to prepare meals at the same time but there isn't enough counter space. They keep moving ingredients back and forth, bumping into each other, and slowing down the cooking. If each cook had just enough space for their current ingredients, the kitchen would run smoothly.

Thrashing → Cooks constantly moving ingredients around due to lack of counter space, causing delays
Working Set Model → Each cook having a defined space for the ingredients they need right now
Working Set Window → The time period during which cooks decide which ingredients they need on the counter
Relation Between Thrashing and Working Set → Ensuring total counter space matches the combined needs of all cooks to avoid chaos
Diagram
Diagram
┌───────────────────────────────┐
│          System Memory         │
│ ┌───────────────┐ ┌─────────┐ │
│ │ Working Set 1 │ │ Working │ │
│ │ (Program A)   │ │ Set 2   │ │
│ │               │ │(Program │ │
│ │               │ │ B)      │ │
│ └───────────────┘ └─────────┘ │
│           ↓                   │
│   If total working sets >     │
│   memory → Thrashing occurs   │
└───────────────────────────────┘
This diagram shows how programs' working sets fit into system memory and how exceeding memory causes thrashing.
Key Facts
ThrashingA state where excessive paging operations cause a system to slow down severely.
Working SetThe set of pages a program actively uses during a recent time window.
Working Set WindowThe time period used to observe which pages belong to a program's working set.
Page FaultAn event when a program tries to access a page not currently in memory.
Memory OvercommitmentWhen the total memory demand of programs exceeds the available physical memory.
Common Confusions
Thrashing means the system is running many programs at once.
Thrashing means the system is running many programs at once. Thrashing specifically refers to excessive memory swapping, not just running many programs; it happens when memory demands exceed capacity.
The working set is a fixed set of pages for a program.
The working set is a fixed set of pages for a program. The working set changes over time as the program accesses different pages within the working set window.
Summary
Thrashing happens when the system spends too much time swapping memory pages, causing slowdowns.
The working set model tracks the active pages a program needs to run efficiently and helps prevent thrashing.
Balancing the total working sets of all programs with available memory is key to smooth system performance.