1 5 Keys to Evict Negative Thinking to Thrive in ANY Situation! Kathleen Ronald .
Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate....
-
Upload
baby-woodfork -
Category
Documents
-
view
216 -
download
0
Transcript of Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate....
![Page 1: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/1.jpg)
Page Replacement Algorithms
So, when we have a page fault we have to find an eviction candidate.
Optimally, we would like to evict the page that will not be referenced again for the longest amount of time. In reality the OS has no way of knowing
when each of the pages will be referenced next.
![Page 2: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/2.jpg)
Not Recently Used Examine M and R bits associated with
each page. Page fault occurs, OS places all pages in
1 or 4 classifications Class 0: R=0, M=0 Class 1: R=0, M=1 Class 2: R=1, M=0 Class 3: R=1, M=1
NRU Algorithm says to remove a page at random from the lowest nonempty class.
![Page 3: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/3.jpg)
FIFO Simple design of having a queue
maintained for pages in memory. The head of the queue contains oldest
page in memory. The tail of the queue contains the
newest page in memory. Is there a potential problem with
evicting the head of the queue each time?
![Page 4: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/4.jpg)
FIFO with second chance Performs like FIFO, but inspects the R bit. If R bit of the head page is 1, it is cleared and
placed at the tail. What happens if all pages in memory have the
R bit set to one?
![Page 5: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/5.jpg)
Clock Page Replacement
Behaves liked FIFO with second chance except that it is a circular linked list.
![Page 6: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/6.jpg)
Least Recently Used
Assume pages used recently will be used again soon
throw out page that has been unused for longest time Must keep a linked list of pages
most recently used at front, least at rear update this list every memory reference !!
Keep counter in each page table entry choose page with lowest value counter periodically zero the counter
![Page 7: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/7.jpg)
LRU (cont.) Alternatively used a n by n matrix. n is the
number of page frames. All values in matrix intially set to 0 When a page frame, k, is referenced,
the hardware first sets all the bits in row k to 1.
Then sets all the bits in column k to 0. The row whose binary value is lowest
is the LRU at any instant.
![Page 8: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/8.jpg)
Example of LRU using Matrix
Pages referenced in order 0,1,2,3,2,1,0,3,2,3
![Page 9: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/9.jpg)
Simulated LRU – Not Frequently Used Most machines do not have the
hardware to perform true LRU, but it may be simulated.
We can use a counter to keep track of each R bit for each page upon a timer tick.
Page with the lowest R-bit is evicted. What is the problem with this type of history
keeping?
![Page 10: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/10.jpg)
Modified NFU
Counters are each shifted right 1 bit before the R bit is added.
R bit is added to the leftmost, rather than the rightmost bit.
This modified algorithm is known as aging.
![Page 11: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/11.jpg)
Modified NFU (Aging)
![Page 12: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/12.jpg)
Issues with NFU
References can happen between timer interrupts.
What happens if we are comparing two pages which have identical references over the past n timer ticks? We make a random choice. Is it the right one?
![Page 13: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/13.jpg)
Working Set Page Replacement Locality of Reference – a process references
only a small fraction of its pages during any particular phase of its execution.
The set of pages that a process is currently using is called the working set.
Thrashing – results when a program causes a page fault every few instructions, causing the pages to have to pulled up from memory. No “real” useful work is being accomplished.
![Page 14: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/14.jpg)
Working Set Page Replacement (cont.) So, what happens in a multiprogramming
environment as processes are switched in and out of memory?
Do we have to take a lot of page faults when the process is first started?
It would be nice to have a particular processes working set loaded into memory before it even begins execution. This is called prepaging.
![Page 15: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/15.jpg)
Working Set Page Replacement (cont.)
The working set algorithm is based on determining a working set and evicting any page that is not in the current working set upon a page fault.
![Page 16: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/16.jpg)
Working Set Page Replacement (cont.)
Age = current virtual time – time of last use
![Page 17: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/17.jpg)
Working Set Page Replacement (cont.) What happens when there is more than
one page with R=0 and age less then or eq to tau?
What happens when all pages have R=1? This algorithm requires the entire page
table be scanned at each page fault until a suitable candidate is located. All entries must have their Time of last use
updated even after a suitable entry is found.
![Page 18: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/18.jpg)
WSClock Page Replacement
![Page 19: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/19.jpg)
WSClock Page Replacement (Cont.) What happens when R=0?
Is age > , and page is clean then it is evicted If it is dirty then we can proceed to find a page that
may be clean and avoid a process switch. We will still need to write to disk and this write is scheduled.
What happens if we go all the way around? (Two Scenarios)
At least one write has been scheduled. Keep Looking… someone eventually write to disk.
No writes have been scheduled… all pages are in the working set, so evict a clean page or the current page if a clean page does not exist.
![Page 20: Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not.](https://reader036.fdocuments.us/reader036/viewer/2022062620/5519c8fa550346695e8b49eb/html5/thumbnails/20.jpg)
Page Replacement Algorithm Summary