150 likes | 238 Views
2Q Algorithms. Fall 2004 CS 186 Review Session for hw1 9/13/04. Your ever friendly TA’s Paul Huang <cs186-ta@imail.eecs> Matt Denny <cs186-tb@imail.eecs> Murali Rangan <cs186-tc@imail.eecs>. Overview. LRU - Disadvantages 2Q – Enhanced LRU Simplified 2Q Full 2Q Q & A.
E N D
2Q Algorithms Fall 2004 CS 186 Review Session for hw1 9/13/04 Your ever friendly TA’s Paul Huang <cs186-ta@imail.eecs> Matt Denny <cs186-tb@imail.eecs> Murali Rangan <cs186-tc@imail.eecs>
Overview • LRU - Disadvantages • 2Q – Enhanced LRU • Simplified 2Q • Full 2Q • Q & A
LRU - Disadvantages • Locality of reference • Same pages referred frequently (warm pages) • Example: 2, 1, 3, 2, 4, 2, 4, 1, 5, 6, 2, … • LRU takes advantage of this. • Disadvantage: • Dislodges warm pages if a long sequence of one time page references occur. • In the above ex, page 2 may get dislodged by the access pattern …, 4, 1, 5, 6, …
2Q – Enhanced LRU • 2Q is enhancement over LRU • Manages pages in 2Q’s (FIFO and LRU) • Aims to retain warm pages as long as possible • Two variations • Simplified 2Q • Full 2Q • Efficient compared to LRU-2, GClock,etc • LRU-2, GClock - beyond the scope of this discussion
Simplified 2Q • Pages in 2 queues (FIFO and LRU) • If a requested page • Is in FIFO (A1) => Move it to LRU head • Is in LRU (Am) => Move it to LRU head • If page fault • If free frame available, occupy it and add it to FIFO • Elif FIFO size > threshold (50% pool size) • Then first item in FIFO is victim • Else remove the tail item LRU, but add new page to FIFO (New pages ALWAYS go to FIFO)
Simplified 2Q (contd…) • Correlated references • A page receives several references for a short time and no references for a long time • Ex: 2, 3, 4, 1, 6, 7, 7, 6, 4, 4, 2, 3, 2, 2, 3,12, 15, … • Disadvantages • Evicts long term warm pages (ex 2, 3) to make room for short term correlated pages (ex 6, 7)
Simplified 2Q (contd…) • About the tuning threshold (chosen as 50%) • FIFO queue grows in spite of threshold as long as there are free frames. • FIFO threshold is checked only if there is a page fault and no free frames. • Larger the threshold => Greater the chance for FIFO to remain longer • Longer the FIFO => Greater the chance for some page in it to be re-referenced and promoted to LRU
Simplified S2Q • About threshold (contd…) • The immediateness of re-referencing a page plays higher factor in promotion to LRU than total number of repetitions. • Ex: 2, 3, 3, 4, 4, 2, 5, 5, 7, 6, 2, 6, 7, 6, 8, 2 • The chance for pages making it to LRU are: • (3, 4, 5) > (6) > (7) > (2) > 8 • 3, 4, and 5 have highest chance because of the immediateness of their re-reference, even though they are only short term and referred only twice each. • 6 has lesser chance than (3, 4, 5) because the page re-reference is not as immediate as 3, 4, 5, even though it gets referred more. • Same argument for pages 7 and 2. • Threshold is the factor in determining how farther apart re-referenced pages will make it to LRU • But higher threshold also means smaller LRU as downside!
Full 2Q • Addresses Correlated references • Pessimistic on re-referenced FIFO pages • Retains them in FIFO (A1in) itself • Remembers page ids of victimized FIFO pages as history (A1out – FIFO of page ids) • Puts a page in LRU only if it is seen in history list (A1out) • A1out max size is 50% of pool size • A1in threshold is 25% of pool size
F2Q (contd…) • If a requested page • Is in FIFO (A1in) => Do nothing (corr. ref.!) • Is in LRU (Am) => Move it to LRU head • If page fault • If free frame available, occupy it and add it to FIFO • Elif FIFO size > threshold (25% pool size) • Then first item in FIFO is victim, • Add page id of victim in A1out (50% pool size) • Else remove the tail item LRU, but add new page to FIFO (New pages ALWAYS go to FIFO)
Full 2Q (contd…) 3, 1 3, 1