{
  "id": "working-set",
  "title": "Working Set",
  "lang": "en",
  "source_lang": "en",
  "summary": "A working set is the collection of memory pages or data actively used by a program during a specified interval, used to understand memory demand and performance.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "Working-set model"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/working-set/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/working-set/",
      "json": "https://aiwiki.page/zh/working-set.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A working set is the collection of memory pages or other units of data that a program uses during a specified interval. In its classical meaning, it is a model of a process’s recent memory references, used by an operating system to estimate which pages should remain in physical memory. More broadly, the term describes the data actively used by an application, computation, or workload at a particular level of the memory hierarchy. A working set is therefore time-dependent: it is not necessarily the program’s entire allocated memory, nor is it always identical to the memory currently resident in RAM."
    },
    {
      "heading": "Origins and purpose",
      "text": "Peter J. Denning introduced the working-set model in the 1960s, with the influential paper “The Working Set Model for Program Behavior” published in 1968. The model addressed a central problem in virtual memory: deciding how much physical memory an executing program needs to make useful progress.\n\nWith paging, a program’s virtual address space is divided into fixed-size pages, only some of which need to be present in physical memory at a given time. When execution references a page that is not resident, a page fault occurs. Resolving the fault may require retrieving data from storage, although some faults can be resolved without storage access.\n\nThe working-set approach connects memory allocation to observed program behavior. Rather than assigning every process an unchanging number of page frames, a system can try to retain the pages that each process is actively using. It can also limit the number of simultaneously active processes when their combined memory requirements exceed available capacity."
    },
    {
      "heading": "Formal definition",
      "text": "In a reference-count formulation, let \\(r_1,r_2,\\ldots\\) be the sequence of virtual page references made by a process. For a positive integer window length \\(\\Delta\\), the working set after reference \\(n\\) is\n\n\\[W(n,\\Delta) = \\left\\{ r_i \\mid \\max(1,n-\\Delta+1)\\leq i\\leq n \\right\\}.\\]\n\nThe working-set size is the number of distinct pages in this set:\n\n\\[w(n,\\Delta)=|W(n,\\Delta)|.\\]\n\nRepeated references to the same page do not increase the size of the set. For example, if the last six references are\n\n\\[A,\\ B,\\ A,\\ C,\\ B,\\ D,\\]\n\nthen the working set for that window is \\(\\{A,B,C,D\\}\\), with a size of four pages.\n\nDefinitions also commonly use a window measured in process execution time rather than a fixed number of references. This distinction matters: a reference-count window and an execution-time window need not contain the same accesses. Process execution time also differs from wall-clock time, which continues to advance while a process is suspended.\n\nIf every page has size \\(P\\) bytes, the memory represented by the set is \\(P\\,w(n,\\Delta)\\) bytes. This is a page-granularity measure; it does not imply that every byte within those pages was accessed.\n\nChoosing the window\n\nThe window determines the timescale of the measurement.\n\n- A short window responds quickly to changes but may omit pages that are used regularly at longer intervals.\n- A long window captures more of a program’s recurring behavior but may retain pages belonging to an earlier phase.\n- For a fixed observation point, increasing the window cannot decrease the working-set size, because the larger window contains all references from the smaller one.\n\nThere is no universally correct window. Its usefulness depends on the workload, the cost of missing data, and the memory-management decision being made."
    },
    {
      "heading": "Locality and program phases",
      "text": "The model is based on locality of reference: programs commonly concentrate their accesses on a limited region of code and data for a period of time.\n\nTemporal locality means recently accessed items are likely to be accessed again. Spatial locality means accesses tend to occur near other accesses. Working sets directly capture recent use, while page or cache-line granularity also brings nearby data into memory.\n\nA program may move through phases with different working sets. For example, a compiler may first process source text, then traverse intermediate representations, and later generate machine code. Each phase can emphasize different data structures. During a transition, a window may temporarily include pages from both the old and new phases, producing a larger working set.\n\nRecent use is an estimate of future demand, not a guarantee. A sequential scan may touch many pages without revisiting them, while a page absent from the recent window may become important immediately afterward."
    },
    {
      "heading": "Memory allocation and thrashing",
      "text": "A classical working-set policy attempts to keep each active process’s working set resident. Pages that have not been referenced within the chosen window become candidates for reclamation.\n\nIf a process receives substantially fewer page frames than its active computation needs, it may repeatedly fault on pages that were recently evicted. When excessive paging leaves little time for useful execution, the system is experiencing thrashing.\n\nFor processes with working sets \\(W_1,\\ldots,W_k\\), a simplified memory-demand estimate is\n\n\\[D \\approx \\sum_{i=1}^{k}|W_i|.\\]\n\nIf this demand exceeds the page frames available for those processes, the operating system may need to reduce the number of active processes or reclaim memory elsewhere. The sum is only an approximation: shared pages must not be counted repeatedly when estimating physical storage requirements, and the system also needs memory for kernel data, buffers, and other purposes.\n\nWorking-set management therefore involves both page replacement and load control. Selecting a different eviction policy cannot by itself make an arbitrarily large collection of simultaneously active working sets fit into insufficient physical memory."
    },
    {
      "heading": "Implementation and approximations",
      "text": "Tracking every memory reference precisely is generally too expensive for routine operating-system use. Practical implementations often estimate recent activity using hardware-maintained page-access information, periodic sampling, and software bookkeeping.\n\nA page-replacement algorithm may inspect an accessed bit associated with a page mapping. If the bit indicates recent use, the system can record that observation and clear the bit for a later sampling interval. Such methods approximate the age of a page’s most recent reference rather than reconstructing the exact reference sequence.\n\nWorking-set ideas are related to least-recently-used replacement, but they are not identical. Least-recently-used replacement ranks pages by recency; a working-set policy identifies pages used within a specified window and can use the resulting set size to guide memory allocation.\n\nWSClock combines working-set age information with a clock-style scan of page frames. It considers recent use and whether pages have been modified when identifying replacement candidates. Another related approach, page-fault-frequency control, adjusts memory allocation in response to observed fault rates rather than explicitly constructing a working set."
    },
    {
      "heading": "Working set versus other memory measures",
      "text": "Several measurements describe different aspects of a process’s memory:\n\nMeasure | What it describes\nVirtual address-space size | The extent of virtual addresses mapped or reserved for the process\nResident set | Pages currently present in physical memory\nClassical working set | Distinct pages referenced within a specified recent window\nPrivate memory | Memory not shared with other processes, according to the accounting system used\n\nA resident set can contain inactive pages, while pages belonging to a recently observed working set may already have been evicted.\n\nTerminology also varies by platform. In Microsoft Windows, a process’s working set refers to pageable pages in its virtual address space that are currently resident in physical memory. This operational meaning is not identical to Denning’s time-window definition. Private-working-set measurements exclude shared pages.\n\nOn Linux, resident-memory statistics and proportional accounting for shared pages provide useful memory measurements, but these should not automatically be interpreted as measurements of a classical working set. Comparisons require attention to what each counter includes, its sampling interval, and its treatment of shared memory."
    },
    {
      "heading": "Broader applications and limitations",
      "text": "The term extends beyond virtual-memory pages. At the level of a CPU cache, a working set may mean the cache lines actively reused by a computation. In a database, it may refer to frequently accessed table and index pages. The total dataset can be much larger than the active working set.\n\nThis distinction helps explain why reorganizing a computation can improve performance without reducing its total input size. Processing an array in blocks, for example, can reduce the data that must remain simultaneously available in a fast cache.\n\nWorking-set size alone does not determine performance. Two workloads with equally sized sets can have very different access frequencies, write behavior, and memory bandwidth requirements. A set that fits within a cache’s nominal capacity may still suffer misses because of mapping conflicts or interference from other workloads. On non-uniform memory access systems, the physical location of resident pages also affects access cost.\n\nA working-set measurement is consequently meaningful only when its scope is specified: the execution entity being observed, the unit of memory, the observation window, and the memory level whose behavior is being studied."
    }
  ],
  "links": [
    "process-computing",
    "operating-system",
    "memory-hierarchy",
    "virtual-memory",
    "paging",
    "page-fault",
    "compiler",
    "microsoft-windows",
    "linux",
    "cpu-cache",
    "database",
    "array-data-structure",
    "non-uniform-memory-access"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}