Download presentation
Presentation is loading. Please wait.
Published byShanon Hodges Modified over 9 years ago
1
ICS 145B -- L. Bic1 Project: Page Replacement Algorithms Textbook: pages 496-500 ICS 145B L. Bic
2
ICS 145B -- L. Bic2 Assignment implement different page replacement algorithms (global and local) generate reference strings test and compare algorithms using reference strings
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
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
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
6
ICS 145B -- L. Bic6 Global page replacement random replacement: –generate random number r in range 0..F-1 –replace page in M[r]
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
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
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
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
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
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)
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 )
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
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
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
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)
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
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
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)
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
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
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 <= r <= 1; if (r < t) generate new p else increment p (mod P)
24
ICS 145B -- L. Bic24 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=500 or 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 are executed between transitions)
25
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<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
26
ICS 145B -- L. Bic26 Performance evaluations 1. global a. how much is gained using FIFO over Random; or LRU over FIFO b. how close is LRU to optimal (MIN) c. how effective are 2nd-chance and 3rd-chance in approximating LRU (for 3rd chance, assume that some percentage of requests are write ops) –compare in terms of average numbers of page faults relative overhead
27
ICS 145B -- L. Bic27 Performance evaluations 2. local a.how close is WS to optimal (VMIN) b. how does page fault rate vary with (for WS, VMIN, or PFF) c. how close is PFF to WS –compare in terms of average numbers of page faults average size of working set (e.g., # of page faults will be the same for VMIN and WS but the average working set size will be smaller for VMIN) relative overhead (if applicable)
28
ICS 145B -- L. Bic28 Performance evaluations 3. local versus global –choose local algorithm –for a given , determine: average size of working set (# frames) number of page faults –use # frames for a global replacement determine number of page faults compare number of faults for local and global relative overhead (if applicable)
29
ICS 145B -- L. Bic29 Summary of tasks develop page replacement algorithms develop program to generate reference strings compare performance: –individuals: (1a || 1b || 2a) && 3 –groups of 3: 1c && 2b && 3 deliverables –commented/documented code –report presenting choices made, results obtained (plots, tables, interpretations), conclusions drawn
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.