Download presentation
Presentation is loading. Please wait.
Published byLewis Vesey Modified over 9 years ago
1
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.1 Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read Ch. 10.1 - 10.2
2
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.2 Operating System Concepts Segmentation vs. Paging Paging and Segmentation each have different advantages and disadvantages. What are advantages and disadvantages of paging? No external fragmentation (advantage) There is internal fragmentation (disadvantage) Units of code and data are broken up into separate pages (disadvantage) What are advantages and disadvantages of segmentation? No internal fragmentation (advantage) There is external fragmentation (disadvantage) Keeps blocks of code or data as single units (advantage. Can get advantages of both systems by combining them.
3
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.3 Operating System Concepts Segmentation with Paging – MULTICS The MULTICS system solved problems of external fragmentation and lengthy search times by paging the segments. Solution differs from pure segmentation in that the segment-table entry contains not the base address of the segment, but rather the base address of a page table for this segment. The offset for the segment is translated to a page number and an offset for that page.
4
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.4 Operating System Concepts MULTICS Address Translation Scheme We will draw this diagram in class.
5
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.5 Operating System Concepts MULTICS Address Translation Scheme
6
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.6 Operating System Concepts Limitations of Standard Memory Management One goal of memory management is to keep as many processes in memory as possible for multiprogramming. The previous examples require that the entire process be in memory for execution. Therefore, the size of the program cannot exceed the size of physical memory. In many cases, you don't need to have the entire program in memory: Code to handle error conditions that rarely occur doesn't need to be in main memory. Arrays, lists and tables are often allocated more memory than needed. Virtual memory is a technique that allows the execution of processes that are only partially in memory.
7
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.7 Operating System Concepts Benefits of Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical address space can therefore be much larger than physical address space. More programs can run at the same time (because each takes up less space). This increases CPU utilization and throughput. Because you don't have to load the entire program into memory, there is less I/O time needed for loading and swapping. Allows address spaces to be shared by several processes. Virtual memory can be implemented via: Demand paging Demand segmentation
8
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.8 Operating System Concepts Demand Paging Virtual memory is implemented by demand paging. (Also can be implemented by demand segmentation, which is slightly more complex). In demand paging, processes reside on secondary storage (usually a hard disk). When a page is needed, a pager swaps it into memory. The pager guesses which pages will be needed and only swaps those in.
9
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.9 Operating System Concepts Transfer of a Paged Memory to Contiguous Disk Space
10
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.10 Operating System Concepts Valid-Invalid Bit We need to distinguish between pages in memory and pages on disk. With each page table entry a valid–invalid bit is associated (1 in-memory, 0 not-in-memory) During address translation, if valid–invalid bit in page table entry is 0, it generates a page fault. 1 1 1 1 0 0 0 Frame #valid-invalid bit page table
11
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.11 Operating System Concepts Page Table When Some Pages Are Not in Main Memory
12
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.12 Operating System Concepts Page Fault What happens when there is a page fault? An interrupt occurs (page fault). Control goes to the O.S. OS looks at another table (usually in the PCB) to determine whether the memory access is valid. if the reference is invalid abort. If the reference is valid, the page is not in memory. Get empty frame (e.g. from free-frame list). Swap page into frame. Reset tables, validation bit = 1. Restart instruction that was interrupted.
13
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.13 Operating System Concepts Steps in Handling a Page Fault We will diagram this in class.
14
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.14 Operating System Concepts Steps in Handling a Page Fault
15
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.15 Operating System Concepts Potential Problem A page fault generates a lot of system activity and a read from disk. If there are many page faults, efficiency decreases. Page faults are limited because programs tend to have locality of reference. References are clustered together. Temporal Locality: recent references are likely to be referenced in the near future. (e.g. loops, common procedures). Spatial locality: Nearby memory locations likely to be referenced. (e.g. arrays, sequential code execution). Past study: 98% of process time spent in localities. 50% of page faults occur during 2% of process time when changing localities. However, newer programming techniques decrease locality within a process. E.g. multithreaded processes have abrupt changes in page being referenced.
16
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.16 Operating System Concepts What happens if there is no free frame? Page replacement – find some page in memory, but not really in use, swap it out. performance – want an algorithm which will result in minimum number of page faults. Same page may be brought into memory several times.
17
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.17 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) x memory access + p x (page fault time) page fault time = (page fault overhead + [swap page out ] + swap page in + restart overhead)
18
Silberschatz, Galvin and Gagne 2002 Modified for CSCI 399, Royden, 2005 7.18 Operating System Concepts Demand Paging Example Memory access time = 1 nanosecond Swap Page Time = 25 msec If p = 0.001, what is the slow down in performance? What p would lead to a 10% slowdown in performance?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.