The Working Set Model for Program Behavior

Peter J. Denning Massachuses Instute of Technology, Cambridge, Massachuses

1 About the paper

• Published in 1968, 1st ACM Symposium on Operaon Systems Principles (SOSP) • 2005, SIGOPS Hall of Fame Award “This paper introduced the working set model, which has became a key concept in understanding of locality of memory references and for implemenng . Most paging algorithms can trace their roots back to this work”

2 Background: Virtual memory

• In the 50s ~ 60s – System: ATLAS computer – Two-level memory hierarchies: main memory + auxiliary storage – – Backbone for mulprogramming

3 Background: Thrashing

“When it was first observed in the 1960s, thrashing was an unexpected, sudden drop in throughput of a mulprogrammed system … I explained the phenomenon in 1968 and showed that a working-set memory controller would stabilize the system ...” – Peter D. Denning 4 Movaon

• Develop a unified approach to tackle the resource allocaon problem: process and memory management • However, such unified approach is absent, because there is no adequate model for program behavior – Program behavior: a program’s system demand, including processor and memory demand

5 Working Set Model - Overview

• Intended to model the behavior of programs, specifically the programs’ memory demand • What is the working set of a program? – Programmer’s standpoint: the smallest collecon of informaon must be present in main memory to assure efficient execuon of the program – System’s standpoint: the set of most recently referenced pages

6 Working Set Model - Definion

• Working set informaon of a process at me t is defined as

collecon of memory pages referenced by the process during the me interval (t - τ, t), τ is the working set parameter

7 Working Set Model - Example sequences of page references 2 6 1 5 7 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4

W(t1, τ) = {2, 6, 1, 5, 7} 2 6 1 5 7 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4

W(t2, τ) = {7, 5, 1}

2 6 1 5 7 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4

W(t3, τ) = {4, 1, 2, 3} 8 Working Set Model - Properes

• P1. Size of working set – w(t, τ): number of pages in working set W(t, τ) – w(t, 0) is 0 – w(t, τ) is a monotonically increasing funcon of τ

9 Working Set Model - Properes

• P2. Predicon – For small me separaon α, the set W(t, τ) is a good predictor for the set W(t + α, τ), because references to the same page tend to cluster in me, the probability (below) is small

– On the other hand, for large me separaon α (say, α >> τ), W(t, τ) is a not good predictor for the set W(t + α, τ)

10

Working Set Model - Properes

• P3. Reentry Rate – The rate at which memory page reenters a working set – Important property for analyzing page traffic – Highly related to the value of τ. • E.g. as τ is reduced, size of working set decreases, the probability that needed pages are not in W(t, τ) increases.

11 Working Set Model - Properes

• P3. Reentry Rate (connued) – Process-me reentry rate λ(τ) = 1/m(τ), where m(τ) is the mean me between reentries – Real-me reentry rate ϕ(τ) = λ(τ) / (1 + λ(τ)T ), where T is the traverse me for fetching a page – Total return traffic rate βMϕ(τ) • βM is the average number of pages for all working sets • It esmates the number of pages per unit me returning to main memory 12 Working Set Model - Properes

• P4. τ – Sensivity – Measures how sensive is the reentry rate λ(τ) to changes in τ

if τ is decreased by dτ, λ(τ) increases by dτ σ(τ)

13 Choice of τ

• If τ is “too small”, it may result in high traffic of returning pages • If τ is “too large”, it may result in wasted main memory • Recommended τ: a value comparable to the memory traverse me T

14 Detecng W(t, τ)

• A hardware-based approach is described, but not praccal • Need a soware-based approach • The paper proposes sampling the page table entries at intervals of σ seconds, where σ = τ / K (K an integer constant) “The idea of sampling for used pages was not new …… What was new was that the window was defined in the virtual me of the program …”

15 Detecng W(t, τ)

• Page table entries for detecng W(t, τ)

- M is 1 if and only if page is in main memory

- 1->u0 each me a page reference occurs - At end of each sampling interval, paern in use bits shied right one posion 16 Memory Allocaon

• A program will not be run unless there is space in memory for its working set • Knowledge of working set size w(t, τ) with demand paging suffices to mange memory well • Before running a process, insure that there are enough pages of memory to contain its working set

17 Scheduling Implementaon with Working Set • Required properes – Memory management and process scheduling be closely related acvies – Sampling of page tables, only on changing working sets, and as infrequently as possible – Provide measurements of current working set sizes and processor me consumpon

for each process 18 19 Resource Allocaon: A Balancing Problem • Formulate the resource allocaon as a problem of balancing processor and memory demands against available resources • “memory demand” of process I

where M is number of pages of main memory

20 Resource Allocaon: A Balancing Problem • But how to define the “processor demand” • Idea: define “processor demand” to be the fracon of a standard interval a process is expected to use before it blocks – Standard interval A, chosen to reflect the maximum tolerable response me to a user

– Condional expectaon funcon Q(ti), to predict the amount of process me to elapse before the next interacon

21 Resource Allocaon: A Balancing Problem • “processor demand” of process i

Where N is the number of processors

• “system demand” is defined as Di = (pi, mi)

22 Resource Allocaon: A Balancing Problem • Then, a system is balanced if

S is dynamically maintained, and measures the total demand of current running list α, β are constants chose to achieve desired fracon of resource to constute balance • To keep the computer system in balance, a “balance policy” can be designed to minimize ( S – (α, β ) ) 23

Conclusion

• Define the working set model for program behavior • Working set model provides an convenient way to determine what informaon is in use by a computaon and which is not • Working set model enables simple determinaon of memory demands

24