130 likes | 269 Views
Approximating the Optimal Replacement Algorithm Ben Juurlink. Plan. Motivation LRU and OPT algorithms Related work TNRP algorithm TNRP tuning TNRP comparison with LRU and OPT. Motivation. It takes millions of cycles to serve a page fault
E N D
Plan • Motivation • LRU and OPT algorithms • Related work • TNRP algorithm • TNRP tuning • TNRP comparison with LRU and OPT
Motivation • It takes millions of cycles to serve a page fault • Small reduction of the miss rate will pay for the cost of advanced replacement algorithm
LRU Algorithm • LRU: Replaces the page that hasn’t been used for the longest time • The optimal algorithm (OPT) evicts the page that will not be used for the longest time • LRU approximates OPT • At times LRU is far from optimal: • 4 page frames • 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5… • LRU’s miss rate: 100% • OPT’s miss rate: 40% • LRU-2: replaces the page whose second to last access is least recent
Related work: Fiat and Rosen Algorithm • Dynamically build weighted access graph • An edge is created the first time the two pages are requested in succession • Each time the edge is traversed, the weight is decreases by a constant factor • “Forgetfulness”: the weight of all edges multiplied by a constant factor every 10n pages accesses • The page to be evicted on a page fault: the furthest page from the page just accessed • Expensive algorithm
Time of Next Reference Predictor • Three parameters recorded for each page: • TLAST(p) = time of last reference • STRIDE(p) = # of page accesses between the last and previous to last reference • State: • Transient initially • Steady when • STRIDE(p) – SD ≤ STRIDEcurr(p) ≤ STRIDE(p) + SD (SD = Stride Deviation) • Time – consecutive accesses to one page replaced by one
Time of Next Reference Predictor • On a page fault: • Replace a page with the largest expected time of next reference EXP-TNEXT(p) • EXP-TNEXT(t)= • TLAST(p) + STRIDE(p) if State=Steady • current_time + [current_time – TLAST(p)] if State=Transient
Time of Next Reference Predictor-Example • Reference String: 1 4 1 1 6 1 1 4 4 6 6 • SD = 2 • Time: 0 1 2 3 4 5 6 • Page: 1 4 1 6 1 4 6 • Stride: 0 0 2 0 2 4 3 • State: T T S T S T T
Time of Next Reference Predictor • A correction is needed for EXP-TNEXT(p) • 1,2,3,4,5,6,7,8,9,5,11,12,13,14,5,16,17,18,19,5,… • 3 pages can be kept in memory • STRIDE(5)=5 • At time 16 • 13,14 and 5 are in memory • EXP-TNEXT(5) = 15 + 5 = 20 • EXP-TNEXT(13) = 16 + (16 – 13) = 19 • EXP-TNEXT(14) = 16 + (16 – 14) = 18 • Page 5 will be evicted
Time of Next Reference Predictor:EXP-TNEXT (p) - solution • If the page hasn’t been accessed before or the state is transient then • EXP-TNEXT(p) = current_time + TF * (current_time – TLAST(p)) • TF>=1 • If the page hasn’t been accessed within the expected time current_time > TLAST(p) + STRIDE(p) +SD, use the above formula for EXP-TNEXT(p) and return its state to Transient • In our example, take TF=2 • EXP-TNEXT(5) = 15 + 5 = 20 • EXP-TNEXT(13) = 16 + 2 * (16 – 13) = 22 • EXP-TNEXT(14) = 16 + 2 * (16 – 14) = 20 • 13 will be evicted
Implementation Issues • How to find a victim page • Priority queue (priority = EXP-TNEXT(p)) • Takes O(log n) to find a victim page • But it takes O(log n) to update the queue • Updates occur frequently • Scan all the paged in pages on a page fault
Experiments - Parameters • Benchmarks from the SPEC 2000 suite • Stride Deviation: • Investigate the distribution of |STRIDEcurr – STRIDEprev| • The distribution depends on benchmark • SD of 5 captures over 60% of all stride values • Time of next reference Factor • Check the miss rate for 1<= TF <= 3 with 4 and 8 page frames • Performance rather independent of the exact values • 4 page frames, the difference is at most 5% • 8 page frames, the difference is at most 0.8% • For some benchmarks the miss rate decreases as TF increases • For other, it decreases and then increases • Optimal value between 2 and 2.75
Experiments – Miss Rate Reduction • TNRP incurs fewer misses than LRU for almost all benchmarks • 4 page frames • Improvement: Avg: 13.5%, range from 6% to 28.2% • 8 page frames • Improvement: Avg: 4%, 20.7 for one benchmark • 16 page frames • Improvement less than 1% for 7 out of 9 benchmarks • Double the number of misses for 1 benchmark • Performance improvement significant when # of pages is small • Works best in multi-tasking environment when the physical memory needs to be shared among several processes • TNRP outperforms LRU-2 for most workloads and number of pages