


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Page replacement algorithms, including the basic mechanism of tlb, page faults, and paged virtual memory. It covers the role of page table entries, page fault handling, demand paging, and page replacement strategies such as belady's algorithm, fifo, lru, and lru clock.
Typology: Slides
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















Fully associative TLB
Reminder: Page Table Entries (PTEs)
the valid bit says whether or not the PTE can be used says whether or not a virtual address is valid it is checked each time a virtual address is used the referenced bit says whether the page has been accessed it is set when a page has been read or written to the modified bit says whether or not the page is dirty it is set when a write to the page has occurred the protection bits control which operations are allowed read, write, execute the page frame number determines the physical page physical page start address = PFN
Page faults
when the page was evicted, the OS set the PTE as invalid and noted the disk location of the page in a data structure (that looks like a page table but holds disk addresses) when a process tries to access the page, the invalid PTE will cause an exception (page fault) to be thrown OK, it‟s actually an interrupt! the OS will run the page fault handler in response handler uses the “like a page table” data structure to locate the page on disk handler reads page into a physical frame, updates PTE to point to it and to be valid OS restarts the faulting process
Demand paging
only the code/data that is needed (demanded!) by a process needs to be loaded What‟s needed changes over time, of course… Hence, it‟s called demand paging
OS crystal ball module notoriously ineffective
OS keeps track of pages that should come and go together bring in all when one is referenced interface may allow programmer or compiler to identify clusters
Page replacement When you read in a page, where does it go? if there are free page frames, grab one what data structure might support this? if not, must evict something else this is called page replacement Page replacement algorithms try to pick a page that won‟t be needed in the near future try to pick a page that hasn‟t been modified (thus saving the disk write) OS typically tries to keep a pool of free pages around so that allocations don‟t inevitably cause evictions OS also typically tries to keep some “clean” pages around, so that even if you have to evict a page, you won‟t have to write it accomplished by pre-writing when there‟s nothing better to do
how does it all work?
temporal locality locations referenced recently tend to be referenced again soon spatial locality locations near recently referenced locations are likely to be referenced soon (think about why)
once you‟ve paged something in, it will be used many times on average, you use things that are paged in but, this depends on many things: degree of locality in the application page replacement policy and application reference pattern amount of physical memory vs. application “footprint” or “working set”
#1: Belady’s Algorithm
evict the page that won‟t be used for the longest time in future problem: impossible to predict the future
as a yardstick to compare other algorithms to optimal if Belady‟s isn‟t much better than yours, yours is pretty good how could you do this comparison?
no; depends on workload
no, but random replacement does pretty badly there are some other situations where OS‟s use near- random algorithms quite effectively!
#2: FIFO
when you page in something, put it on the tail of a list evict page at the head of the list
maybe the one brought in longest ago is not being used
then again, maybe it is being used have absolutely no information either way
there are reference strings for which the fault rate increases when the process is given more physical memory
Reference string: A B C A B D A D B C B FIFO Belady LRU A B C A B C A B C A B C A A B C A B C A B C B A B C A B C A B C D D B C A D A C D D A C B D A B C C A B B C A B Faults: FIFO 7 Belady 5 LRU 5
Implementing LRU On every memory reference time stamp each page At eviction time: scan for oldest Keep a stack of page numbers