Download presentation
Presentation is loading. Please wait.
Published byShanna Fleming Modified over 9 years ago
1
Silberschatz, Galvin and Gagne 2002 10.1 Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of Frames Thrashing Operating System Example
2
Silberschatz, Galvin and Gagne 2002 10.2 Operating System Concepts Virtual memory separation of logical memory from physical memory only part of the program must be in memory for execution logical address space can therefore be much larger than physical address space allows address spaces to be shared by several processes allows for more efficient process creation implemented via: demand paging demand segmentation
3
Silberschatz, Galvin and Gagne 2002 10.3 Operating System Concepts Virtual Memory That is Larger Than Physical Memory
4
Silberschatz, Galvin and Gagne 2002 10.4 Operating System Concepts Demand Paging Bring a page into memory only when it is needed Less I/O needed Less memory needed Faster response More users Page is needed reference to it invalid reference abort not-in-memory bring to memory
5
Silberschatz, Galvin and Gagne 2002 10.5 Operating System Concepts Transfer of a Paged Memory to Contiguous Disk Space
6
Silberschatz, Galvin and Gagne 2002 10.6 Operating System Concepts each page table entry has valid–invalid bit: 1 in-memory, 0 not-in-memory initially valid–invalid but is set to 0 on all entries Example: if valid–invalid bit is 0 page fault Valid-Invalid Bit 1 1 0 0 0 Frame #valid-invalid bit 1 1 page table
7
Silberschatz, Galvin and Gagne 2002 10.7 Operating System Concepts Page Table When Some Pages Are Not in Main Memory
8
Silberschatz, Galvin and Gagne 2002 10.8 Operating System Concepts Page Fault Procedure 1) first page reference will trap to OS page fault 2) OS looks at another table to decide: 1) invalid reference abort. 2) just not in memory 3) get empty frame 4) swap page into frame 5) reset tables, validation bit = 1 6) restart instruction 1) caution: is it restartable ?
9
Silberschatz, Galvin and Gagne 2002 10.9 Operating System Concepts Steps in Handling a Page Fault
10
Silberschatz, Galvin and Gagne 2002 10.10 Operating System Concepts What happens if there is no free frame? Page replacement find some page in memory, that is not in use Algorithm performance want an algorithm which will result in minimum number of page faults Same pages may be paged in/out repeatedly
11
Silberschatz, Galvin and Gagne 2002 10.11 Operating System Concepts Performance of Demand Paging Page Fault Rate 0 p 1.0 if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 – p) * memory access + p (page fault overhead + [swap page out ] + swap page in + restart overhead) optional
12
Silberschatz, Galvin and Gagne 2002 10.12 Operating System Concepts Copy-on-Write used when creating a new process (fork) parent and child process initially share the same pages in memory if either process modifies a shared page, only then is the page copied COW allows efficient process creation free pages are allocated from a pool of zeroed-out pages
13
Silberschatz, Galvin and Gagne 2002 10.13 Operating System Concepts Memory-Mapped Files File I/O treated as routine memory access by mapping a disk block to a page in memory file is initially read using demand paging portion of file read from the file system into a physical page Subsequent reads/writes to/from the file are treated as ordinary memory accesses Less overhead than read() write() system calls several processes may map to same file via page sharing
14
Silberschatz, Galvin and Gagne 2002 10.14 Operating System Concepts Memory Mapped Files
15
Silberschatz, Galvin and Gagne 2002 10.15 Operating System Concepts Need For Page Replacement
16
Silberschatz, Galvin and Gagne 2002 10.16 Operating System Concepts Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: 1. If there is a free frame, use it 2. If there is no free frame, use a page replacement algorithm to select a victim frame 3. Read the desired page into the (newly) free frame. Update the page and frame tables 4. Restart the process
17
Silberschatz, Galvin and Gagne 2002 10.17 Operating System Concepts Page Replacement
18
Silberschatz, Galvin and Gagne 2002 10.18 Operating System Concepts Page Replacement Algorithms Want lowest page-fault rate Evaluate algorithm: Consider series of memory references (reference string) Compute the number of page faults Example: reference string 1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 2 Page number
19
Silberschatz, Galvin and Gagne 2002 10.19 Operating System Concepts Graph of Page Faults Versus The Number of Frames
20
Silberschatz, Galvin and Gagne 2002 10.20 Operating System Concepts First-In-First-Out (FIFO) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frames (3 pages can be in memory at a time per process) 4 frames 1 2 3 1 2 3 4 1 2 5 3 4 9 page faults 1 2 3 1 2 3 5 1 2 4 5 10 page faults 4 43
21
Silberschatz, Galvin and Gagne 2002 10.21 Operating System Concepts FIFO: Belady’s Anamoly
22
Silberschatz, Galvin and Gagne 2002 10.22 Operating System Concepts Optimal Algorithm Replace page that will not be used for longest time 4 frames example: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 How do you know this ? (predict future !) Used to measure quality of an algorithm 1 2 3 4 6 page faults 4 5
23
Silberschatz, Galvin and Gagne 2002 10.23 Operating System Concepts Least Recently Used (LRU) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Counter implementation Every page entry has a counter On page access, copy the clock into the counter When a page needs to be changed, compare counters Replace page with smallest counter 1 2 3 5 4 4 3 5
24
Silberschatz, Galvin and Gagne 2002 10.24 Operating System Concepts LRU Algorithm via Stack keep a stack of page numbers in a double link form: Page referenced: move it to the top requires 6 pointers to be changed No search for replacement
25
Silberschatz, Galvin and Gagne 2002 10.25 Operating System Concepts LRU Approximation Algorithms Reference bit(s) for each page initially = 0 set to 1 when page is used victim page has 0 problems: order no page with 0 bit aging
26
Silberschatz, Galvin and Gagne 2002 10.26 Operating System Concepts Example: Second-Chance Algorithm upon bit check, reset to 0 FIFO via circular queue page use set bit to 1 victim is page with 0
27
Silberschatz, Galvin and Gagne 2002 10.27 Operating System Concepts Counting Algorithms Counter frequency of references 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
28
Silberschatz, Galvin and Gagne 2002 10.28 Operating System Concepts Allocation of Frames Each process needs minimum number of pages Example: IBM 370 – 6 pages for SS MOVE instruction: instruction is 6 bytes, might span 2 pages 2 pages to handle from address 2 pages to handle to address Two major allocation schemes: fixed allocation priority allocation
29
Silberschatz, Galvin and Gagne 2002 10.29 Operating System Concepts Fixed Allocation Equal allocation e.g., if 100 frames and 5 processes, give each 20 pages Proportional allocation, allocate according to the size of process
30
Silberschatz, Galvin and Gagne 2002 10.30 Operating System Concepts Priority Allocation Use a proportional allocation scheme using priorities rather than size If process P i generates a page fault, select for replacement one of its frames. select for replacement a frame from a process with lower priority number
31
Silberschatz, Galvin and Gagne 2002 10.31 Operating System Concepts Global vs. Local Allocation Global replacement - process selects a replacement frame from the set of all frames - one process can take a frame from another Local replacement - each process selects from only its own set of frames
32
Silberschatz, Galvin and Gagne 2002 10.32 Operating System Concepts Thrashing If a process does not have “enough” pages, the page-fault rate is very high: process does page i/o low CPU utilization scheduler starts another process less memory per process
33
Silberschatz, Galvin and Gagne 2002 10.33 Operating System Concepts Thrashing Why does paging work? Locality model Process migrates from one locality to another Localities may overlap Why does thrashing occur? size of locality > total memory size
34
Silberschatz, Galvin and Gagne 2002 10.34 Operating System Concepts Locality In A Memory-Reference Pattern
35
Silberschatz, Galvin and Gagne 2002 10.35 Operating System Concepts Working-Set Model Working set of Process WS(t) = pages referenced in the most recent working-set window
36
Silberschatz, Galvin and Gagne 2002 10.36 Operating System Concepts Working-Set Model WSS i = number of distinct pages used by process i in the most recent if too small will not encompass entire locality if too large will encompass several localities if = will encompass entire program D = WSS i total demand frames if D > m Thrashing Policy: if D > m, then suspend a process
37
Silberschatz, Galvin and Gagne 2002 10.37 Operating System Concepts Keeping Track of the Working Set Approximate with interval timer + a reference bit + 2 memory bits Example: = 10,000 timer interrupts after every 5000 time units then copy all reference bits to memory bits clear all reference bits to 0 if one of the bits in memory = 1 page in working set
38
Silberschatz, Galvin and Gagne 2002 10.38 Operating System Concepts Page-Fault Frequency Scheme Establish “acceptable” page-fault rate If actual rate too low, process loses frame If actual rate too high, process gains frame
39
Silberschatz, Galvin and Gagne 2002 10.39 Operating System Concepts Other Considerations Prepaging Page size selection fragmentation table size I/O overhead TLB Reach = (TLB Size) X (Page Size) increase the page size provide multiple page sizes Inverted page table Program structure I/O interlock
40
Silberschatz, Galvin and Gagne 2002 10.40 Operating System Concepts Example: Windows NT Uses demand paging with clustering Clustering brings in pages surrounding the faulting page Process has working set minimum and maximum minimum number of pages guaranteed to process in memory a process is assigned more pages up to maximum When the amount of free memory in system falls to threshold automatic working set trimming removes pages from processes that have more than minimum
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.