Inferensys

Glossary

Working Set

A working set is the collection of memory pages that a process actively references within a specific time interval, a core concept for optimizing cache performance and virtual memory in AI accelerators.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
MEMORY HIERARCHY MANAGEMENT

What is a Working Set?

A core concept in computer architecture and operating systems for optimizing memory and cache performance.

A working set is the collection of memory pages or cache lines that a process actively references during a defined time interval. This concept is fundamental to virtual memory management and cache optimization, as it represents the minimal data required for the process to make efficient progress without excessive page faults or cache misses. The size and composition of the working set directly influence system performance by determining the pressure on the memory hierarchy.

In the context of NPU acceleration, managing the working set is critical for maximizing data reuse in on-chip scratchpad memory or caches. A compiler or runtime that effectively minimizes or fits the working set into fast local memory reduces costly accesses to High Bandwidth Memory (HBM) or main memory, directly improving throughput and energy efficiency. This optimization requires analyzing the program's memory access patterns and data locality.

MEMORY HIERARCHY MANAGEMENT

Key Characteristics of a Working Set

The working set is a dynamic subset of a program's total memory footprint that is actively referenced within a specific time window. Its properties are fundamental to the design of efficient virtual memory, caching, and accelerator memory subsystems.

01

Temporal Locality

The working set is defined by the principle of temporal locality, which states that memory locations accessed recently are likely to be accessed again soon. This is the foundational assumption that makes caching and paging effective. A program's working set at time t is formally the set of pages (or cache lines) referenced in the time interval (t - Δ, t), where Δ is the working set window. The size and composition of this set change as the program's execution phase changes.

02

Dynamic and Phase-Based

A working set is not static; it evolves with program execution. It typically exhibits phase behavior, where periods of stable memory access patterns (a steady working set) are punctuated by phase transitions where the set changes rapidly. For example:

  • An initialization phase loads a large dataset into memory.
  • A computation phase repeatedly accesses a core subset of that data.
  • A cleanup phase accesses new memory for writing results. Effective memory management, especially on NPUs with limited on-chip memory, requires algorithms to detect these phases and adapt data placement accordingly.
03

Critical Determinant of Performance

The relationship between the working set size (WSS) and the cache size or fast memory capacity is the primary determinant of cache/memory performance. This leads to three fundamental regimes:

  • Ideal (WSS < Cache): The entire working set fits in fast memory, yielding hit rates near 100% and optimal performance.
  • Thrashing (WSS >> Cache): The working set vastly exceeds cache capacity, causing constant eviction of needed data and catastrophic performance drops.
  • Knee of the Curve (WSS ≈ Cache): Performance is highly sensitive to small changes in WSS or cache size; this is the critical design point for systems engineers optimizing NPU memory hierarchies.
04

Basis for Page Replacement

In virtual memory systems, the working set model directly informs page replacement policies. The Working Set Model for process scheduling, formalized by Peter Denning, states a process should only be allowed to run if its working set is resident in physical memory to prevent thrashing. Practical algorithms like the WSClock approximate the working set to decide which pages to keep in RAM and which to page out to disk. For NPU scratchpad memory, similar explicit management is performed by the compiler, which must analyze the program's expected working set to allocate data structures.

05

Measured via Profiling

The working set is not directly programmable but is observed through hardware performance counters and memory trace analysis. Key metrics include:

  • Last-Level Cache (LLC) Misses: A sharp increase indicates the working set exceeds LLC size.
  • Page Fault Rate: In virtual memory, a high rate indicates the working set exceeds allocated physical frames.
  • Access Pattern Stride: Analyzed to distinguish between sequential, random, or strided working sets, which impacts prefetching effectiveness. Tools like perf (Linux) or VTune profile these events to guide optimization, such as adjusting data layout or tile sizes for NPU kernels.
06

Optimization Target for Accelerators

On NPUs and GPUs, managing the working set is a core compiler and programmer responsibility due to explicit memory hierarchies (e.g., global, shared, local memory). Key optimization techniques include:

  • Tiling/Loop Blocking: Restructuring computations to break large data sets into tiles that fit the accelerator's fast scratchpad memory or cache, ensuring the tile becomes the kernel's working set.
  • Data Layout Transformation: Rearranging data structures (e.g., Array of Structs to Struct of Arrays) to improve spatial locality and create a more compact, cache-friendly working set.
  • Kernel Fusion: Combining operations to keep intermediate data in registers or shared memory, preventing it from spilling to slower memory and bloating the working set.
WORKING SET

Frequently Asked Questions

Essential questions about the working set, a core concept in memory hierarchy management that defines the active data footprint of a process, directly impacting cache performance, virtual memory efficiency, and overall system throughput.

A working set is the collection of memory pages or cache lines that a process actively references during a defined time window, representing its current locality of reference. This concept, formalized by Peter Denning in the 1960s, is fundamental to virtual memory and cache management policies. The principle states that to run efficiently, a process's working set must be resident in fast memory (like RAM or cache). If the working set exceeds the available fast memory capacity, the system experiences thrashing—a severe performance penalty from continuously swapping data between memory levels. For Neural Processing Units (NPUs), managing the working set of a model's weights, activations, and intermediate tensors is critical for keeping data in on-chip scratchpad memory or caches to avoid stalls from high-latency off-chip DRAM accesses.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.