Project Page Replacement Algorithms Textbook pages 496 500
Project: Page Replacement Algorithms Textbook: pages 496 -500 Operating Systems 1
Assignment • implement different page replacement algorithms (global and local) • generate reference strings (RS) • test and compare algorithms using RSs Operating Systems 2
Overall Organization parameters: P, p, e, m, t, len generate reference string RS file F page replacement algorithm initialize memory and aux structures repeat for each element r of RS { if (r is not in main memory) { record page fault replace an existing page with r } record other statistical data } plot and interpret data Operating Systems 3
Global page replacement • assume single-process system • virtual memory: P pages [0. . P-1] • reference string RS: sequence of integers, p – each p is in range 0. . P-1 • main memory: F frames [0. . F-1]; – implement as array M[F] – each M[f] contains page number p • page replacement: if p (from RS) not in M, select f, replace resident page: M[f]=p • choose from: random, FIFO, LRU, 2 nd chance Operating Systems 4
Global page replacement random replacement: • at page fault: – generate random number r in range 0. . F-1 – replace page in M[r] Operating Systems 5
Global page replacement FIFO: replace oldest page • maintain array index i of oldest page • initially, i=0 (F[0] is the first frame to be filled) • at page fault: – replace page in F[i] – increment i (mod F) Operating Systems 6
Global page replacement LRU: replace least recently used page • uses a queue that is reordered at each reference • implement queue directly in M; no need to maintain additional array • at each reference to p: – find i where M[i] == p – if p is not resident, set i=0 and record a page fault – M[k] = M[k+1] for i k < F-1 (shift elements down) – M[F-1] = p Operating Systems 7
Global page replacement second-chance algorithm • maintain – current index i (like FIFO) – array U[F] of use-bits • at each reference to page p: set U[p]=1 • at page fault: if U[i]==1 then U[i]=0; else replace page in U[i] i++ Operating Systems 8
Local page replacement • pages are not selected from fixed M[F] • instead, each process has a working set ws (= resident set of pages) • working set grows and shrinks dynamically with program behavior: – if p (from RS) is not in ws, include it – ws shrinks based on algorithm (limited by ) Operating Systems 9
Local page replacement working set model: uses trailing window of size +1 • implement as array WIN[ +1] • contains last +1 references from RS • at each reference, p: – slide WIN to the right such that: • p becomes the right-most element of WIN • the left-most element, q, drops out of WIN – if p was not already in WIN, record a page fault and increment ws size by 1 – if q is no longer in WIN, decrement ws size by 1 Operating Systems 10
Generating reference strings • if no locality: pick random number in [0. . P-1] • but typical behavior is: – periods of stable WS – punctuated by transitions: WS grows rapidly, then settles into new stable size • how to simulate different program behaviors? – must vary: • working set size • probability of migration Operating Systems 11
Generating reference strings • model typical behavior: – locus of reference |-----|---------------------| 0 p p+e P-1 • stable period: – assume constant rate in one direction (1 step every m references) • transition: – generate new locus with probability t • locus defined by p, e, m, t Operating Systems 12
Generating reference strings • algorithm to generate RS: – select P, p, e, m, t – repeat until RS generated: • pick m random numbers in [p. . p+e]; include in RS (write to file) • generate random number 0 <= r <= 1; • if (r < t) generate new p else increment p (mod P) Operating Systems 13
Choosing simulation constants • P: size of VM (# pages) • e: size of working set (# pages) – P and e need to be chosen together: e<P, but: • if e is too close to P, working sets overlap after transitions • if e is too small, the program will rarely revisit previous locations (important for LRU to benefit) • suggestion: e varies from 2 to P/10, P=1000 • p random number within [0. . P-1] • m: # of times a page is referenced – typically, m 100 (see page 267, fig 8 -13 b) • t: length of stable period – random number in [0. . 1]; typically, t<0. 1 (i. e. , thousands of instructions executed between transitions) Operating Systems 14
Choosing simulation constants • length of RS: – must be large to make behavior statistically significant – suggestion: >100, 000 • F: number of frames – must be chosen together with P and e – generally e<F<P • with e approaching (or exceeding) F, thrashing is observed • with F approaching P, # page faults approaches 0 • suggestion: set F=P/10; vary e from 2 to F • : window size • typically: e Operating Systems 15
Performance evaluations Individuals: • choose and compare 3 global algorithms • vary e and t, measure #pf for each algorithm – each RS(e, t) produces 1 point for each algorithm • plot #pf against e • repeat for different t’s Operating Systems 16
Performance evaluations Teams (max 2): • compare WS to one global algorithm • problem: how to chose F to be fair • for any given in WS algorithm, determine average ws size (# frames) • use this # frames for a global replacement • for both WS and global – vary e (= ) and t; measure #pf – each RS(e, t) produces 1 point for each algorithm – plot #pf against e – repeat for different t’s Operating Systems 17
Summary of tasks • • develop page replacement algorithms develop program to generate reference strings write programs to compare performance write and submit report – discuss choices of parameters – show results obtained (plots, tables) – discuss results (expectations/conclusions) – include commented code Operating Systems 18
- Slides: 18