Page replacement algos (8+9) Flashcards
goal of page replacement algorithm (policy)
manage page access from pages referenced in virtual address space so as to minimize page faults for all pages belonging to a process
Replacement algos run on which data structure?
Strings of memory page references - page references are pointers to actual memory pages
Basic steps followed when page fault occurs
Select a page from a string of referenced pages (pages scheduled to be run)
retrieve page from memory storage and find free frame - if full, evict a victim frame
selected frame loaded into victim frame
victim frame loaded into TLB or secondary storage
update page table
OS exits kernel mode and continues from where it was interrupted (by page fault trap)
Explain random page replacement
Simplest
random frame evicted
issues with random page replacement
unpredictable doesn’t achieve goal of minimizing page faults and does not fit with principle of locality
principle of locality
tendency of CPU to access same set of mem locations repetitively over a short period of time - since these locations correspond to a few processes that CPU scheduled to execute during the given period
Basic idea of FIFO page replacement
allow every page to spend same amount of time in phys mem - first in first out - page that has been loaded in the longest is the first to be swapped out when a new page needs to be swapped in
maintains a linked list of all pages which keeps the order in which pages entered memory - page at front of list is replaced
advantage of FIFO
easy to implement - single pointer needed
Main disadvantage of FIFO
doesnt keep frequently used pages in main mem - page that has been in longest could be the most used page but FIFO will swap it out (and cause page faults)
Explain the OPT algorithm (page replacement)
used as benchmark algorithm
Assumes that page that will not be used for longest time should be selected for replacements
BUT - needs to assume perfect knowledge of the future
If an algorithm is within 5% of OPT then it’s effective
Explain LRU page replacement algorithm
Least Recently Used uses a record of page page replacement to replace pages that have not been used recently
On each page replacement, it places new page at head of list. The list tail is removed.
Implemented with linked list
Main advantage of LRU
accounts for principle of locality - same set of pages tend to be frequently used while the process is executing, so these pages should not be swapped out of main mem
How LRU implements a counter
Every page has associated counter, every time a page is used, counter is incremented (represents time at which page was used in main mem) - we now replace the page with the smallest time value (oldest page)
Relationship between number of frames and number of faults (FIFO)
more frames = more faults
What is Belady’s anomaly?
increasing number of page frames increases the page faults for a given mem access pattern. Seen in fifo, random and second chance algorithms. Does not occur for stack based algorithms