Beruflich Dokumente
Kultur Dokumente
Note: Some slides are adapted from slides 2005 Silberschatz, Galvin, and Gagne, and Prof. John Kubiatowicz lecture
Goals for Today Virtual Memory Demand Paging Page Replacement Allocation of Frames Thrashing Demand Segmentation Operating System Examples
CPU
Virtual Address
TLB
Cached? Yes No
Physical Address
Physical Memory
But they dont use all their memory all of the time
90-10 rule: programs spend 90% of their time in 10% of their code Wasteful to require all of users code to be in memory
Caching
Main Second Secondary Level Memory Storage Cache (DRAM) (Disk) (SRAM)
Datapath
Virtual Memory
Virtual memory separation of user logical memory from physical memory.
Only part of the program needs to be in memory for execution.
Some functions are almost never executed. E.g. Over-provision data structures in program. E.g.
Logical address space can be much larger than physical address space. Allows address spaces to be shared by several processes. Allows for more efficient process creation. E.g. COW and vfork( ) (in a moment )
Virtual-address space
Demand Paging
Page Replacement Allocation of Frames Thrashing Demand Segmentation Operating System Examples
Demand Paging
Demand paging: pages are only loaded into memory when they are demanded during execution
Less I/O needed Less memory needed Higher degree of multiprogramming Faster response
Pager (lazy swapper) never swaps a page into memory unless that page will be needed. An extreme case: Pure demand paging starts a process with no pages in memory
Transfer of a Paged Memory to Contiguous Disk Space
Valid-Invalid Bit
V/I bit is a hardware support (slight different from v/i bit in ch8)
Frame #
valid-invalid bit
1 1 1 1 0
0 0
page table
e.g. P = 0.1 Memory access time = 200 ns page fault time = 8 ms EAT = (1 0.1) x 200 + 0.1 x 8000000 ns Why The page fault is very expensive?
The page fault rate significantly affect the System performance reduce page fault rate P !
Page Replacement
Allocation of Frames Thrashing Demand Segmentation Operating System Examples
Page Replacement
Basic page replacement algorithm
1. Find the location of the desired page on disk 2. 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. Check if the victim frame is modified (dirty). If its dirty, write back to disk
3. Load the demand page from disk into the (newly) free frame. Update the page and frame tables 4. Restart the interrupted process
(page replacement diagram is next )
Optimal (OPT) Page Replacement Algorithm OPT has the lowest page fault rate: replace page that will not be used for longest period of time 4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
1 2 3 4 5 4
How do you know which page will not be used for longest period of time?
A benchmark used for measuring how well other page replacement algorithm performs
No search for replacement Problem with both implementations Need additional hardware support Expensive housekeeping is required at each memory reference. Interrupt handling overhead Any solutions ?
Additional-Reference-Bit Algorithm
Keep an 8-bit (reference byte ?)for each page to record reference information for the last 8 time periods At regular interval (e.g. 100 ms), OS shifts the reference bit right by 1 and discard the low-order bit e.g.1 if a page does not be referred for a while 0 0 0 0 0 0 0 e.g.2 if a page is continuously referred 1 1 1 1 1 1 1 1 e.g.3 Which page shall be replaced?
11000100 0111 0111
Second-Chance (clock) Page-Replacement Algorithm Second chance: If page to be replaced (in clock order) has reference bit = 1 then: set reference bit 0, and leave page in memory replace next page (in clock order), subject to same rules
Counting Algorithms
Keep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used
Allocation of Frames
Thrashing Demand Segmentation Operating System Examples
Allocation of Frames
How does OS allocate the fixed amount of free memory (frames) among the various processes? Simple frame allocation algorithm: in a single user system, OS takes some frames, the rest of frames are assigned to a user process Some variations:
Demand paging on the buffer and table space of OS Always reserve a couple of free frames in free frame list Why?
Allocate at least a minimum number of frames for each process defined by the computer architecture e.g. In IBM 370 MVC instruction instruction might span 2 pages 2 pages to handle from 2 pages to handle to Hence minimum 6 pages are needed.
What if there are total 5 frames in this system?
Allocation of Frames
Another example: indirect addressing one-level indirect addressing: a load instruction refers to an address on another page, which is an indirect reference to another page.
How many frames needed? What if in a multi-level indirect addressing computer architecture? any solution?
Priority Allocation
In both equal and proportional allocation algorithms:
The number of frames allocated also depends on multiprogramming level the more processes, the less frames each gets No differentiation on the priority of processes
We want to allocate more frames to high priority processes to speed up their execution Proportional + Priority allocation scheme Use a proportional allocation scheme using priorities rather than size
Local
pro: deterministic con: inflexible and may hinder system throughput