Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne Operating System Concepts Chapter 9: Virtual Memory.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne Operating System Concepts Chapter 9: Virtual Memory."— Presentation transcript:

1 Silberschatz, Galvin and Gagne Operating System Concepts Chapter 9: Virtual Memory

2 Silberschatz, Galvin and Gagne Operating System Concepts Objectives To describe the benefits of a virtual memory system To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames To discuss the principle of the working-set model

3 Silberschatz, Galvin and Gagne Operating System Concepts Background

4 Silberschatz, Galvin and Gagne Operating System Concepts In chapter of memory management, various memory-management strategies used in computer systems were discussed and all of these strategies have the same goal: to keep many processes in memory simultaneously to allow multiprogramming. However, they tend to require that an entire process be in memory before it can execute. Virtual memory is a technique that allows the execution of processes that are not completely in memory. Background

5 Silberschatz, Galvin and Gagne Operating System Concepts Advantages o that programs can be larger than physical memory. o Further, virtual memory abstracts main memory into an extremely large, uniform array of storage, separating logical memory as viewed by the user from physical memory. o This technique frees programmers from the concerns of memory- storage limitations. Background Virtual Memory That is Larger Than Physical Memory

6 Silberschatz, Galvin and Gagne Operating System Concepts Virtual-address Space we allow the heap to grow upward in memory as it is used for dynamic memory allocation. Similarly, we allow the stack to grow downward in memory through successive function calls. The large blank space (or hole) between the heap and the stack is part of the virtual address space

7 9.7 Silberschatz, Galvin and Gagne Operating System Concepts Advantages (cont) o Virtual memory also allows processes to share files easily and to implement shared memory. Background Shared Library Using Virtual Memory

8 9.8 Silberschatz, Galvin and Gagne Operating System Concepts disadvantage Virtual memory is not easy to implement, however, and may substantially decrease performance if it is used carelessly Background

9 9.9 Silberschatz, Galvin and Gagne Operating System Concepts Background Virtual memory can be implemented via : 1. Demand paging 2. Demand segmentation

10 9.10 Silberschatz, Galvin and Gagne Operating System Concepts 1-Demand Paging Consider how an executable program might be loaded from disk into memory. One option is to load the entire program in physical memory at program execution time. However, a problem with this approach is that we may not initially need the entire program in memory. Ex: Suppose a program starts with a list of available options from which the user is to select. Loading the entire program into memory results in loading the executable code for all options, regardless of whether an option is ultimately selected by the user or not. An alternative strategy is to load pages only as they are needed during program excution. This technique is known as demand paging and is commonly used in virtual memory systems.

11 9.11 Silberschatz, Galvin and Gagne Operating System Concepts 1-Demand Paging A demand-paging system is similar to a paging system with swapping But rather than swapping the entire process into memory, we use a lazy swapper. lazy swapper never swaps a page into memory unless that page will be needed. Since we are now viewing a process as a sequence of pages, rather than as one large contiguous address space, use of the term swapper is technically incorrect. A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process. We thus use pager, rather than swapper, in connection with demand paging.

12 9.12 Silberschatz, Galvin and Gagne Operating System Concepts 1-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

13 9.13 Silberschatz, Galvin and Gagne Operating System Concepts Transfer of a Paged Memory to Contiguous Disk Space

14 9.14 Silberschatz, Galvin and Gagne Operating System Concepts With this scheme, we need some form of hardware support to distinguish between 1. the pages that are in memory 2. the pages that are on the disk. The valid–invalid bit scheme can be used for this purpose.  “valid,” : the associated page is both legal and in memory.  “invalid,” the page either is not valid (that is, not in the logical address space of the process) or is valid but is currently on the disk. 1-Demand Paging

15 9.15 Silberschatz, Galvin and Gagne Operating System Concepts Valid-Invalid Bit With each page table entry a valid– invalid bit is associated (v  in-memory, i  not-in-memory) Initially valid–invalid bit is set to i on all entries page table 1-Demand Paging

16 9.16 Silberschatz, Galvin and Gagne Operating System Concepts Page Table When Some Pages Are Not in Main Memory

17 9.17 Silberschatz, Galvin and Gagne Operating System Concepts Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault 1. Operating system looks at another table to decide: Invalid reference  abort Just not in memory 2. Get empty frame 3. Swap page into frame 4. Reset tables 5. Set validation bit = v 6. Restart the instruction that caused the page fault

18 9.18 Silberschatz, Galvin and Gagne Operating System Concepts Steps in Handling a Page Fault

19 9.19 Silberschatz, Galvin and Gagne Operating System Concepts Performance of Demand Paging Demand paging can significantly affect the performance of a computer system. why ? if no page faults, the effective access time is equal to the memory access time. If, however, a page fault occurs, we must first read the relevant page from disk and then access the desired word. Let p be the probability of a page fault (0 ≤ p ≤ 1). expect p to be close to only a few page faults. effective access time = (1 − p) × ma + p × page fault time.

20 9.20 Silberschatz, Galvin and Gagne Operating System Concepts Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds EAT = (1 – p) x 200 + p (8 milliseconds) = (1 – p x 200 + p x 8,000,000 = 200 + p x 7,999,800 If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!

21 9.21 Silberschatz, Galvin and Gagne Operating System Concepts Process Creation Virtual memory allows other benefits during process creation: - Copy-on-Write - Memory-Mapped Files (later)

22 9.22 Silberschatz, Galvin and Gagne Operating System Concepts End of Chapter 9


Download ppt "Silberschatz, Galvin and Gagne Operating System Concepts Chapter 9: Virtual Memory."

Similar presentations


Ads by Google