ICS 145B -- L. Bic1 Project: Page Replacement Algorithms Textbook: pages 496-500 ICS 145B L. Bic

  • View
    218

  • Download
    0

Embed Size (px)

Text of ICS 145B -- L. Bic1 Project: Page Replacement Algorithms Textbook: pages 496-500 ICS 145B L. Bic

  • Slide 1
  • ICS 145B -- L. Bic1 Project: Page Replacement Algorithms Textbook: pages 496-500 ICS 145B L. Bic
  • Slide 2
  • ICS 145B -- L. Bic2 Assignment implement different page replacement algorithms (global and local) generate reference strings test and compare algorithms using reference strings
  • Slide 3
  • ICS 145B -- L. Bic3 Overall Organization generate reference string RS 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 parameters: P, p, e, m, t, len plot and interpret data file F
  • Slide 4
  • ICS 145B -- L. Bic4 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
  • Slide 5
  • ICS 145B -- L. Bic5 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
  • Slide 6
  • ICS 145B -- L. Bic6 Global page replacement random replacement: generate random number r in range 0..F-1 replace page in M[r]
  • Slide 7
  • ICS 145B -- L. Bic7 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
  • Slide 8
  • ICS 145B -- L. Bic8 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
  • Slide 9
  • ICS 145B -- L. Bic9 Global page replacement LRU: for the purposes of measurements, implement the queue directly in M; no need to maintain additional array (Q) 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
  • Slide 10
  • ICS 145B -- L. Bic10 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
  • Slide 11
  • ICS 145B -- L. Bic11 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
  • Slide 12
  • ICS 145B -- L. Bic12 Global page replacement 0 | 1 2 3 4 5 | c a w d b w 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)
  • Slide 13
  • ICS 145B -- L. Bic13 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 )
  • Slide 14
  • ICS 145B -- L. Bic14 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
  • Slide 15
  • ICS 145B -- L. Bic15 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
  • Slide 16
  • ICS 145B -- L. Bic16 Local page replacement optimal (VMIN) with =3 uses forward-looking sliding window (WS) Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | d| c c d b c e c e a d Page a | -| - - - - - - - - x - Page b | -| - - - x - - - - - - Page c | -| x x x x x x x - - - Page d | x| x x x - - - - - - x Page e | -| - - - - - x x x - - IN | | c b e a d OUT | | d b c e a
  • Slide 17
  • ICS 145B -- L. Bic17 Local page replacement VMIN use WIN[ +1] as with WS model WIN is forward-looking sliding window: contains future +1 references from RS at each reference, p: slide WIN to the right such that: the the left-most element drops out of WIN p becomes the new left-most element of WIN the reference, q, that is steps in future becomes the right- most element of WIN if q was not already in WIN, record a page fault (will occur steps in future)
  • Slide 18
  • ICS 145B -- L. Bic18 Local page replacement page fault frequency if time between page faults < , grow resident set: add new page to resident set if time between page faults , shrink resident set: add new page but remove all pages not referenced since last page fault
  • Slide 19
  • ICS 145B -- L. Bic19 Local page replacement page fault frequency Time t | 0| 1 2 3 4 5 6 7 8 9 10 RS | | c c d b c e c e a d Page a | x| x x x - - - - - x x Page b | -| - - - x 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 x - x Page e | x| x x x - - x x x x x IN | | c b e a d OUT | | ae bd
  • Slide 20
  • ICS 145B -- L. Bic20 Local page replacement PFF maintain virtual memory representation, VM: VM[p].res -- page p is resident/not resident VM[p].u -- use bit for page p at each reference to p: VM[p].u=1 at page fault: set VM[p].res=1 record page fault if time between page faults : remove all resident pages with VM[p].u=0 reset u-bit of all pages (VM[*].u=0)
  • Slide 21
  • ICS 145B -- L. Bic21 Generating reference strings no locality: pick random number in [0..P-1] typical behavior: periods of stable WS punctuated by transitions: WS grows rapidly, then settles into new stable size
  • Slide 22
  • ICS 145B -- L. Bic22 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
  • Slide 23
  • ICS 145B -- L. Bic23 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 generate random number 0
  • ICS 145B -- L. Bic25 Choosing simulation constants length of RS: must be large to make behavior statistically significant suggestion: >100,000 write vs read access (for 3 rd chance algorithm) assume 10% (or less) of write accesses F: number of frames must be chosen together with P and e generally e