CS162 Operating Systems and Systems Programming Lecture 16 Page Allocation and Replacement con t I O Systems October 27 2008 Prof John Kubiatowicz http inst eecs berkeley edu cs162 Review Page Replacement Policies FIFO First In First Out Throw out oldest page Be fair let every page live in memory for same amount of time Bad because throws out heavily used pages instead of infrequently used pages MIN Minimum Replace page that won t be used for the longest time Great but can t really know future Makes good comparison case however RANDOM Pick random page for every replacement Typical solution for TLB s Simple hardware Pretty unpredictable makes it hard to make realtime guarantees LRU Least Recently Used Replace page that hasn t been used for the longest time Programs have locality so if something not used for a while unlikely to be used in the near future Seems like LRU should be a good approximation to MIN 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 2 Review Clock Algorithm Not Recently Used Single Clock Hand Set of all pages in Memory Advances only on page fault Check for pages not used recently Mark pages as not used recently Clock Algorithm pages arranged in a ring Hardware use bit per physical page Hardware sets use bit on each reference If use bit isn t set means not referenced in a long time Nachos hardware sets use bit in the TLB you have to copy this back to page table when TLB entry gets replaced On page fault Advance clock hand not real time Check use bit 1 used recently clear and leave alone 0 selected candidate for replacement 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 3 Review Nth Chance version of Clock Algorithm Nth chance algorithm Give page N chances OS keeps counter per page sweeps On page fault OS checks use bit 1 clear use and also clear counter used in last sweep 0 increment counter if count N replace page Means that clock hand has to sweep by N times without page being used before page is replaced How do we pick N Why pick large N Better approx to LRU If N 1K really good approximation Why pick small N More efficient Otherwise might have to look a long way to find free page What about dirty pages Takes extra overhead to replace a dirty page so give dirty pages an extra chance before replacing Common approach 10 27 08 Clean pages use N 1 Dirty pages use N 2 and write back to disk when N 1 Kubiatowicz CS162 UCB Fall 2008 Lec 16 4 Goals for Today Finish Page Allocation Policies Working Set Thrashing I O Systems Hardware Access Device Drivers Note Some slides and or pictures in the following are adapted from slides 2005 Silberschatz Galvin and 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 5 Gagne Many slides Gagne generated from my lecture notes Second Chance List Algorithm VAX VMS o rfl ve O w Directly Mapped Pages Marked RW List FIFO Page in From disk LRU victim Second Chance List cc A New Active Pages s s e Marked Invalid List LRU New SC Victims Split memory in two Active list RW SC list Invalid Access pages in Active list at full speed Otherwise Page Fault Always move overflow page from end of Active list to front of Second chance list SC and mark invalid Desired Page On SC List move to front of Active list mark RW Not on SC list page in to front of Active list mark RW page out LRUKubiatowicz victim at end of SC list 10 27 08 CS162 UCB Fall 2008 Lec 16 6 Second Chance List Algorithm con t How many pages for second chance list If 0 FIFO If all LRU but page fault on every page reference Pick intermediate value Result is Pro Few disk accesses page only goes to disk if unused for a long time Con Increased overhead trapping to OS software hardware tradeoff With page translation we can adapt to any kind of access the program makes Later we will show how to use page translation protection to share memory between threads on widely separated machines Question why didn t VAX include use bit Strecker architect asked OS people they said they didn t need it so didn t implement it He later got blamed but VAX did OK anyway 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 7 Free ListClock Hand Single Set of all pages in Memory Advances as needed to keep freelist full background D D Free Pages For Processes Keep set of free pages ready for use in demand paging Freelist filled in background by Clock algorithm or other technique Pageout demon Dirty pages start copying back to disk when enter list Like VAX second chance list If page needed before reused just return to active set Advantage Faster for page fault Can always use page or pages immediately on fault 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 8 Demand Paging more details Does software loaded TLB need use bit Two Options Hardware sets use bit in TLB when TLB entry is replaced software copies use bit back to page table Software manages TLB entries as FIFO list everything not in TLB is Second Chance list managed as strict LRU Core Map Page tables map virtual page physical page Do we need a reverse mapping i e physical page virtual page Yes Clock algorithm runs through page frames If sharing then multiple virtual pages per physical page Can t push page out to disk without invalidating all PTEs 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 9 Allocation of Page Frames Memory Pages How do we allocate memory among different processes Does every process get the same fraction of memory Different fractions Should we completely swap some processes out of memory Each process needs minimum number of pages Want to make sure that all processes that are loaded into memory can make forward progress Example IBM 370 6 pages to handle SS MOVE instruction instruction is 6 bytes might span 2 pages 2 pages to handle from 2 pages to handle to Possible Replacement Scopes Global replacement process selects replacement frame from set of all frames one process can take a frame from another Local replacement each process selects from only its own set of allocated frames 10 27 08 Kubiatowicz CS162 UCB Fall 2008 Lec 16 10 Fixed Priority Allocation Equal allocation Fixed Scheme Every process gets same amount of memory Example 100 frames 5 processes process gets 20 frames Proportional allocation Fixed Scheme Allocate according to the size of process Computation proceeds as follows si size of process pi and S si m total number of frames ai allocation for pi si m S Priority Allocation Proportional scheme using priorities rather than size Same type of computation as previous scheme Possible behavior If process pi generates a page fault
View Full Document
Unlocking...