This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Friday, April 24 Project #2 Project #3 is posted Due Sunday before midnight Get started as soon as you finish Project #2 Solutions are posted Homework #2 Homework #3 is posted Do Problem #1 Discussion in class Monday Take the COE Computing Services Survey: http://engr.oregonstate.edu/computing/itsurvey.php Today's Topics Homework #2 Virtual Memory Paging Pagereplacement algorithms Virtual Memory Abstraction of logical memory (i.e., memory as viewed by the user) from physical memory. Process can be executed only if it is in main memory, but ... i.e., user programs reference data and instructions in the same way, whether the referenced addresses are in main memory or secondary memory Virtual memory Possibly only part of the program needs to be in main memory at a given time. Logical address space can be much larger than physical address space Allows address spaces to be shared by several processes. use disk space (secondary memory) as if it were main memory Virtual memory Virtual memory can be implemented via: Uses intermediateterm scheduler Demand paging Demand segmentation Demand Paging Bring a page into main memory only when it is referenced. When a process references some part of a page, the entire page must be in a main memory frame Less main memory needed Space for more processes, more users Page stays in main memory until it is replaced Must prevent overallocation of memory If referenced page is not in main memory, load it. Page Tables Recall that each process is allocated a certain number of frames (the process address space) Each process's allocated address space contains (among other things) a page table Page table contains (logical) page number and the associated (physical) frame number Page Tables Example snapshot of one process's page table "Free" bit indicates a frame currently in use (0) or not in use (1) System determines base address for each given frame number During address binding, if a referenced logical address is not in main memory, system generates a "page fault". Seven frames allocated for process (noncontiguous)
Free bit Page # Frame # 0 0 0 1 1 1 1 12 9 14 ? ? ? ? 35 36 37 38 51 52 53 Number of table elements = number of logical pages for process Alternate implementation
Frames 0 1 2 3 4 ... 35 ? 36 51 ? . . . 0 1
ValidInvalid Bit With each page table entry a validinvalid bit is associated (1 inmemory, 0 notinmemory) Table is indexed by logical page numbers Note: number of allocated frames is generally less than number of pages Tradeoff: faster search / more memory 1 0 1 1 0 During address binding, if validinvalid 22 52 bit in page table entry is 0, system generates a "page fault". Initially validinvalid bit is set to 0 on all entries. 21 ? Whenever there is a reference to a page ... OS looks at page table to decide: Valid reference (i.e., page in memory)? Page Faults Invalid reference (i.e., page not in memory)? use it First reference trigger a page fault page fault (or abort) If page fault is generated ... Find empty frame. Load page into frame. Update table entry What happens if there is no free frame in the process address space? Page replacement When a page fault requires replacing a page: Select some page in the process address space and swap it out.
Clean page can be overwritten Dirty (changed) page must be copied to disk before new page is loaded Same page may be brought into memory several times. Basic Page Replacement
s s Find the location on disk of the page that is to be loaded. Find a free frame:
If there is a free frame, use it. If there is no free frame, use a page replacement algorithm to select a victim frame.
Copy the victim to disk (if dirty) s 3. 4. 5. Copy the desired page into the (newly) free frame. Update the page and frame tables. Start/resume the process. Page Replacement Use a modify (dirty) bit to reduce overhead of page transfers Page replacement completes separation of logical memory and physical memory only modified pages are written to disk. large virtual memory can be provided on a smaller physical memory Page Replacement Algorithms Algorithm evaluation: for each algorithm ... Run algorithm on a particular string of memory references (reference string) Compute the number of page faults on that string. Goal: minimize number of page faults!! FirstInFirstOut (FIFO) Page Replacement Algorithm
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 With 3 frames (3 pages can be in memory at a time per process) 1 2 3 1 2 3 4 1 2 5 3 4 9 page faults FirstInFirstOut (FIFO) Page Replacement Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Using 4 frames should improve performance ... RIGHT? Intuition says that more frames fewer page faults Intuition is wrong for this reference string under FIFO Belady's Anomaly 1 2 3 4 1 2 3 4 5 1 2 3 4 5 10 page faults Questions? Do Homework #3, Problem #1 Read Love Chapter 14 ...
View Full Document
This note was uploaded on 06/28/2009 for the course CS 411 taught by Professor Staff during the Spring '08 term at Oregon State.
- Spring '08
- Operating Systems