Unformatted text preview:

CS162 Operating Systems and Systems Programming Lecture 16 Page Allocation and Replacement con t I O Systems October 26 2005 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 26 05 Kubiatowicz CS162 UCB Fall 2005 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 forFall replacement 10 26 05 Kubiatowicz CS162 UCB 2005 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 26 05 Clean pages use N 1 Dirty pages use N 2 and write back to disk when N 1 Kubiatowicz CS162 UCB Fall 2005 Lec 16 4 Review 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 LRU victim CS162 at end ofFall SC2005 list 10 26 05 Kubiatowicz UCB Lec 16 5 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 26 05 Kubiatowicz CS162 UCB Fall 2005 Lec 16 6 Gagne 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 26 05 Kubiatowicz CS162 UCB Fall 2005 Lec 16 7 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 select for replacement a frame from a process with lower priority number Perhaps we should use an adaptive scheme instead 10 26 05 CS162 UCB Fall 2005 Lec 16 8 What if someKubiatowicz application just needs more memory Page Fault Frequency Allocation Can we reduce Capacity misses by dynamically changing the number of pages application Establish acceptable page fault rate If actual rate too low process loses frame If actual rate too high process gains frame Question What if we just don t have enough memory 10 26 05 Kubiatowicz CS162 UCB Fall 2005 Lec 16 9 Thrashing If a process does not have enough pages the page fault rate is very high This leads to low CPU utilization operating system spends most of its time swapping to disk Thrashing a process is busy swapping pages in and out Questions How do we detect Thrashing What is best Kubiatowicz responseCS162 to Thrashing 10 26 05 UCB Fall 2005 Lec 16 10 Locality In A Memory Reference Pattern Program Memory Access Patterns have temporal and spatial locality Group of Pages accessed along a given time slice called the Working Set Working Set defines minimum number of pages needed for process to behave well Not enough memory for Working Set Thrashing Better to swap out process 10 26 05 Kubiatowicz CS162 UCB Fall 2005 Lec 16 11 Working Set Model working set window fixed number of page references Example 10 000 instructions WSi working set of Process Pi total set of pages referenced in the most recent varies in time if too small will not encompass entire locality if too large will encompass several localities if will encompass entire program D WSi total demand frames if D m Thrashing Policy if D m then suspend one of the processes This can improve overall system behavior by a lot 10 26 05 Kubiatowicz CS162 UCB Fall 2005 Lec 16 12 What about Compulsory Misses Recall that compulsory misses are misses that occur the first time that a page is


View Full Document

Berkeley COMPSCI 162 - Lecture 16 Page Allocation and Replacement I/O Systems

Documents in this Course
Lecture 1

Lecture 1

12 pages

Nachos

Nachos

41 pages

Security

Security

39 pages

Load more
Loading Unlocking...
Login

Join to view Lecture 16 Page Allocation and Replacement I/O Systems and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 16 Page Allocation and Replacement I/O Systems and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?