Presentation is loading. Please wait.

Presentation is loading. Please wait.

Virtual Memory 3 Fred Kuhns Department of Computer Science and Engineering Washington University.

Similar presentations


Presentation on theme: "Virtual Memory 3 Fred Kuhns Department of Computer Science and Engineering Washington University."— Presentation transcript:

1 Virtual Memory 3 Fred Kuhns (fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk) Department of Computer Science and Engineering Washington University in St. Louis

2 2 Fred Kuhns () Basic Paging Policies Fetch Policy: when to bring page into memory –Demand paging: fetch when referenced –Prepaging brings in more pages than needed Replacement Policy: which page to remove from memory –Page removed should be the page least likely to be referenced in the near future –Most policies predict the future behavior on the basis of past behavior –Frame Locking - If frame is locked, it may not be replaced. Placement Policy: where fetched page is placed

3 3 Fred Kuhns () Demand Paging Static Paging Algorithms – fixed number of pages allocated to process –Optimal –Not recently used –First-in, First-out and Second chance –Clock algorithm –Least Recently Used –Least Frequently Used Dynamic Paging Algorithms –Working Set Algorithms

4 4 Fred Kuhns () Static Replacement Algorithms Optimal –Selects for replacement that page for which the time to the next reference is the longest –Impossible to have perfect knowledge of future events Not Recently used –recall M and R bits –when page fault occurs divide each page into one of 4 groups 0) ~R & ~M; 1) ~R & M; 2) R & ~M; 3) R & M and replace from the lowest ordered non-empty group. –disadvantage is having to scan all pages when a fault occurs

5 5 Fred Kuhns () Static Replacement Algorithms First-in, first-out (FIFO) –Treats page frames allocated to a process as a circular buffer –Pages are removed in round-robin style –Simplest replacement policy to implement –But may remove needed pages Second Chance Algorithm –improvement to FIFO by using the R bit –if R bit is set then clear and move to end of list otherwise replace –may result in expensive list manipulations

6 6 Fred Kuhns () Static Replacement Algorithms Least Recently Used (LRU) –Replaces the page that has not been referenced for the longest time –By the principle of locality, this should be the page least likely to be referenced in the near future –Each page could be tagged with the time of last reference. This would require a great deal of overhead. –Expensive to implement if not supported in hardware

7 7 Fred Kuhns () Static Replacement Algorithms Least Frequently Used –software implementation of least recently used –associate counter with each page initialized to 0 and increment by R each clock tick –problem is history... slow to react to changing reference string Implementing Least Frequently Used –shift counter right 1 bit and add R to leftmost bit. This is known as aging.

8 8 Fred Kuhns () Static Replacement Algorithms Clock Policy –Behavior is same as second chance but avoids extra list manipulations –put pages on a circular list in the form of a clock with a hand referencing the current page –when page fault occurs, if current page has R = 0 then replace otherwise set R = o and advance to next page. Keep advancing until locate page with R = 0.

9 from William Stallings, Operating Systems, 4 th edition, Prentice Hall

10 10 Fred Kuhns () Dynamic Replacement Algorithms Working set algorithm – aka demand paging –working set – set of pages currently used by process –OS keeps track of processes working set, the working set model, and is modeled as w(k,t), for the k most recent references and process virtual time t. –implementations use virtual time rather then k, the virtual time of a process. Can track the pages referenced in the past x seconds of virtual time –Required scanning entire page list, expensive –Compromise the is the WSClock algorithm: stamp page with

11 11 Fred Kuhns () WSClock Algorithm Similar to clock algorithm with circular list and clock hand. scans list and if R = 1 then it is cleared and the current virtual time is written. advance hand if R = 0 then check timestamp > T then replace (if dirty schedule for write else put on free list)

12 12 Fred Kuhns () Some Details Stack Algorithms –pages loaded with allocation m is always subset of those loaded with allocation of m+1. Page Buffering –Replaced page is added to one of two lists Fixed process page allocation –gives a process a fixed number of pages within which to execute –when a page fault occurs, one of the pages of that process must be replaced Variable process page allocation –number of pages allocated to a process varies over the lifetime of the process

13 13 Fred Kuhns () Variable Allocation, Global Scope Easiest to implement Adopted by many operating systems Operating system keeps list of free frames Free frame is added to resident set of process when a page fault occurs If no free frame, replaces one from another process

14 14 Fred Kuhns () Variable Allocation, Local Scope When new process added, allocate number of page frames based on application type, program request, or other criteria When page fault occurs, select page from among the resident set of the process that suffers the fault Reevaluate allocation from time to time

15 15 Fred Kuhns () Cleaning Policy Demand cleaning –a page is written out only when it has been selected for replacement Precleaning –pages are written out in batches Best approach uses page buffering –Replaced pages are placed in two lists Modified and unmodified –Pages in the modified list are periodically written out in batches –Pages in the unmodified list are either reclaimed if referenced again or lost when its frame is assigned to another page

16 16 Fred Kuhns () Load Control Determines the number of processes that will be resident in main memory Too few processes, many occasions when all processes will be blocked and much time will be spent in swapping Too many processes will lead to thrashing

17 17 Fred Kuhns () Process Suspension Lowest priority process Faulting process –this process does not have its working set in main memory so it will be blocked anyway Last process activated –this process is least likely to have its working set resident Process with smallest resident set –this process requires the least future effort to reload Largest process –obtains the most free frames Process with the largest remaining execution window


Download ppt "Virtual Memory 3 Fred Kuhns Department of Computer Science and Engineering Washington University."

Similar presentations


Ads by Google