Working Set
The pages a process is actually using. If they do not fit in RAM, the system thrashes.
Level: intermediate
What is it?
A process's working set is the set of pages it has referenced during a chosen recent time window. It approximates the memory needed to keep that process's current locality resident and avoid frequent page faults.
Why does it matter?
Working-set information helps explain and prevent thrashing. Allocating fewer frames than an active working set may cause repeated eviction and reload of pages, wasting I/O and reducing useful CPU work.
Mental model
The working set moves as the application changes phases. A database scan, a graph traversal, and a compiler phase may need different page sets; the OS cannot assume one fixed number is best forever.
How it works
- Working-set size depends on the measurement window and the program's current phase.
- If the sum of active working sets exceeds available memory, some workloads may thrash.
- Working-set models help reason about frame allocation and degree of multiprogramming.
- Working-set estimates are approximations; pages referenced recently may not always be needed again soon.
- Reducing memory footprint, limiting concurrency, or changing access locality can reduce pressure more effectively than adding CPU.
Steps
- Choose a recent reference window and track which pages were touched.
- Estimate the current working-set size for each active process.
- Compare the combined demand with available physical frames.
- If demand exceeds capacity, reduce active memory pressure or adjust allocation and workload behavior.
Real-world usage
- Diagnosing thrashing, high page faults, and low throughput under memory pressure.
- Understanding locality in compilers, databases, and streaming data processing.
Common mistakes
- Treating a working set as every page ever allocated by the process.
- Assuming the estimate is independent of the chosen time window.
- Responding to memory thrashing by increasing process concurrency without measurement.
Interview questions
How does a working set relate to thrashing?
When active working sets do not fit in physical memory, processes may repeatedly fault on pages that were recently evicted, causing excessive paging.
Can a working set remain constant throughout a program?
No. The set can change as the program moves between phases with different code, data, and access patterns.