Project: Page Replacement Algorithms - PowerPoint PPT Presentation

yanka
project page replacement algorithms n.
Skip this Video
Loading SlideShow in 5 Seconds..
Project: Page Replacement Algorithms PowerPoint Presentation
Download Presentation
Project: Page Replacement Algorithms

play fullscreen
1 / 25
Download Presentation
Project: Page Replacement Algorithms
651 Views
Download Presentation

Project: Page Replacement Algorithms

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Project: Page Replacement Algorithms Textbook: pages 496-500 Fall 2010

  2. Assignment • implement different page replacement algorithms (global and local) • generate reference strings • test and compare algorithms using reference strings Fall 2010

  3. Overall Organization generate reference string RS parameters: P, p, e, m, t, len file F 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 } page replacement algorithm plot and interpret data Fall 2010

  4. 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 Fall 2010

  5. Global page replacement • optimal (MIN): replace page that will not be referenced for the longest time in the future Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | | c a d b e b a b c d Frame 0| a| a a a a a a a a a d Frame 1| b| b b b b b b b b b b Frame 2| c| c c c c c c c c c c Frame 3| d| d d d d e e e e e e IN | | e d OUT | | d a • at page fault: search RS for most distant pg Fall 2010

  6. Global page replacement • optimal (MIN): implementation • Search for most distant reference • for each p in M, search RS for next occurrence • if p does not occur in RS, stop search, select • else choose the most distant p Fall 2010

  7. Global page replacement • random replacement: • generate random number r in range 0..F-1 • replace page in M[r] Fall 2010

  8. Global page replacement • FIFO: replace oldest page Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | | c a d b e b a b c d Frame 0|>a|>a >a >a >a e e e e >e d Frame 1| b| b b b b >b >b a a a >a Frame 2| c| c c c c c c >c b b b Frame 3| d| d d d d d d d >d c c IN | | e a b c d OUT | | a b c d e • maintain array index of oldest page • increment (mod F) when page replaced Fall 2010

  9. Global page replacement • LRU: replace least recently used page Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | | c a d b e b a b c d Frame 0| a| a a a a a a a a a d Frame 1| b| b b b b b b b b b b Frame 2| c| c c c c e e e e e d Frame 3| d| d d d d d d d d c c IN | | e c d OUT | | c d e Q.end | d| c a d b e b a b c d | c| d c a d b e b a b c | b| b d c a d d e e a b Q.head | a| a b b c a a d d e a Fall 2010

  10. Global page replacement • LRU: • implement the 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) • M[F-1] = p Fall 2010

  11. Global page replacement • second-chance algorithm … 4 5 6 7 8 9 10 … b e b a b c d … >a/1 e/1 e/1 e/1 e/1 >e/1 d/1 … b/1 >b/0 >b/1 b/0 b/1 b/1 >b/0 … c/1 c/0 c/0 a/1 a/1 a/1 a/0 … d/1 d/0 d/0 >d/0 >d/0 c/1 c/0 … e a c d • maintain • current pointer • array U[F] of use-bits Fall 2010

  12. Global page replacement • third-chance algorithm • u-bit set at every reference (read or write) • w-bit set at write reference • to select a page, cycle through frames, resetting bits, until uw==00: uw  uw 1 1 0 1 1 0 0 0 0 1 0 0 * (remember modification) 0 0 select Fall 2010

  13. Global page replacement … 0 | 1 2 3 4 5 … | c aw d bw e … >a/10 |>a/10 >a/11 >a/11 >a/11 a/00* … b/10 | b/10 b/10 b/10 b/11 b/00* … c/10 | c/10 c/10 c/10 c/10 e/10 … d/10 | d/10 d/10 d/10 d/10 >d/00 … | e • maintain • current pointer • array U[F] of use-bits • array W[F] of write-bits • no need to maintain marker bits (asterisk) Fall 2010

  14. 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 ) Fall 2010

  15. Local page replacement • working set model (=3) • uses trailing window of size +1 (=WS) Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | a| c c d b c e c e a d Page a | x| x x x - - - - - x x Page b | -| - - - x x x x - - - Page c | -| x x x x x x x x x x Page d | x| x x x x x x - - - x Page e | x| x - - - - x x x x x IN | | c b e a d OUT | | e a d b Fall 2010

  16. Local page replacement • working set model • maintain array WIN[+1] • WIN represents sliding window (queue): 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 increase ws by 1 • if q no longer in WIN, ws shrinks by 1 Fall 2010

  17. Local page replacement • Implement only WS algorithm • VMIN: similar implementation • PFF: too tedious to implement Fall 2010

  18. 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 Fall 2010

  19. 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 Fall 2010

  20. 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) Fall 2010

  21. 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-13b) • t: length of stable period • random number in [0..1]; typically, t<0.1 (i.e., thousands of instructions executed between transitions) Fall 2010

  22. Choosing simulation constants • length of RS: • must be large to make behavior statistically significant • suggestion: >100,000 • write vs read access (for 3rd chance algorithm) • assume 10% (or less) of write accesses • 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 Fall 2010

  23. Performance evaluations • Individuals: 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 Fall 2010

  24. Performance evaluations • Groups (max 2): compare WS to global • 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 Fall 2010

  25. Summary of tasks • develop page replacement algorithms • develop program to generate reference strings • programs due in 3 weeks (Moodle) • use programs to compare performance • write report (due 2 weeks later) • discuss choices of parameters • show results obtained (plots, tables) • discuss results (expectations/conclusions) Fall 2010