Ch. 21 · Operating Systems

Working Sets and Memory Thrashing

Working Sets and Memory Thrashing. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readintermediateupdated Oct 3, 2026

A working set is the actively needed memory over a period. If competing work exceeds available memory, repeated eviction and reload can dominate progress.

Before you start

You should understand processes, threads, memory and basic file operations. Track ownership and state changes over time. For concurrent scenarios, write down at least two possible execution orders; the same instructions can behave differently when scheduling or resource availability changes.

The practical goal is to reason through this situation: Several large jobs repeatedly fault pages instead of completing computation. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Estimate active memory

The working set is what tasks repeatedly need, not merely allocated size.

Step 2: Observe repeated eviction

Competing demand can force pages out before reuse.

Step 3: Reduce pressure

Bound simultaneous working sets or provide justified capacity.

Worked scenario

Several large jobs repeatedly fault pages instead of completing computation.

Each of several jobs repeatedly scans a large dataset. Together they exceed available memory and spend increasing time reloading pages. Adding another job increases concurrency but reduces useful throughput. Reduce simultaneous active demand and measure actual progress rather than treating high storage activity as productive work.

Common mistake

Adding concurrent jobs can reduce total throughput under memory pressure.

Verify the behavior

Compare fault rates and completion throughput before and after lowering concurrency.

Interview exercise

Recover from thrashing.

Answer and reasoning

Reduce concurrent working sets or increase suitable memory capacity, then measure residency, faults and actual progress.

Continue learning

Compare the scenario with the Operating Systems interview questions and test your understanding with the Operating Systems MCQs. For terminology and implementation details, consult the reference material.

More in Operating Systems

read ✓Operating Systems · hard

Operating Systems: CPU Cache Locality

Improve performance with spatial and temporal locality, avoid pointer chasing, and understand false sharing between threads.

~2 min readread →
read ✓Operating Systems · hard

Copy-on-Write Memory and fork

How copy-on-write lets fork share pages until a write, why RSS can be misleading, and the implications for memory and latency.

~2 min readread →
read ✓Operating Systems · hard

Operating Systems: epoll and select

How select, poll and epoll report I/O readiness, and the difference between level- and edge-triggered notifications.

~2 min readread →
esc