Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Published byModified over 6 years ago
Presentation on theme: "Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001."— Presentation transcript:
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001
What is Virtual Memory Swaps data in and out of physical memory. Make physical memory appear to the CPU that there is more physical memory than is actually present.
The three main reasons for using Virtual Memory 1. To free programmers from the need to carry out storage allocation and to permit efficient sharing of memory space among different users. 2. To make programs independent of the configuration and capacity of the memory systems used during their execution. 3. To achieve the high access rates and low cost Per bit that is possible with a memory hierarchy.
What does Virtual Memory really do? Virtual memory places open applications that are not active and portions of active applications on your hard drive and only keeps what is necessary for functionality in real RAM.
Memory Management Unit (MMU) Moves data between physical memory and some slower storage device, usually a disk. It translates the CPU address (logical address) to physical memory address. It moves data from the swap disk to physical memory and from physical memory back to the swap.
How the MMU convert logical address output from the CPU to a physical address CPU MMU Physical Memory Swap Disk Control signal Logical address Physical address
Two primary methods to implement virtual memory Paging Segmentation
Paging and Frames In paging, the entire range of logical addresses is divided into contiguous blocks called pages. Each pages is the same size and each logical address is resides in exactly one page. Physical memory is divided into non- overlapping frames The size of each frame is the same as the size of one page
paging Moves pages from the swap disk to frames of the physical memory so data can be accessed by the processor. Any page can occupy any frame. This leads to several issues must be resolved by a paging system.
Paging issues that are handled by the MMU 1. When should a page be moved into physical memory? 2. How does the CPU find data in physical memory? 3. What happens when all the frames have page and the CPU needs to access data from a page not currently stored in physical memory?
Paging Example: Simple CPU Physical memory space –16K Logical address space –64k Page size –4k 4 frames in physical memory 4k Page F Page 0 Page 1 Page 2 FFFFH F000H 2FFFH 2000H 1FFFH 1000H 0FFFH 0000H Frame 3 Frame 2 Frame 1 Frame 0 3FFFH 3000H 2FFFH 2000H 1FFFH 1000H 0FFFH 0000H Logical memory Address space Physical memory......
Page Table The MMU uses a page table to keep track of which pages are stored in which frames. The MMU uses a page table to calculate the required physical addresses.
Page Fault The page is not located in physical memory. The Memory Management unit would cause the page to be copied from the swap disk to a frame in physical memory.
Demand Paging Memory Management unit would clear a page out of physical memory and move the newly required page into the vacated frame if all frames in physical memory already contained pages.
Begin Process fetched word Compute Physical address X of next Word required Fetch required word From M Is X in M? Is there a free Page frame in M? Select page frame F in M to replace Has F been altered? Transfer page In F to Secondary memory Transfer page containing X Form secondary memory To free page frame in M Update page Address tables Yes No Suspend Normal execution Resume normal execution Yes No Yes No O P E R A T I O N O F A D E M A N D P A G I N G System
Translation Lookaside Buffer (TLB) Because of a time delay associated with reading the frame number from the page table, and the system may read the same value hundreds or thousands of times consecutively as it fetches contiguous instructions, MMU usually contain a TLB.
Conversion of Logical Address to Physical Address Using the TLB Offset Logical address Page Page Frame Valid 0000011 0100111 1111001 0101101 Offset Frame Physical address: To physical memory
Segmentation Another method of allocating memory that can be used instead of or in conjunction with page. Program is divided into several segments. Segments can vary in size. Segmentation have a segmented MMU.
Segments compared to paging Segments has advantage (internal fragmentation), and disadvantage (external fragmentation)
Internal fragmentation A program of size 4k + 1 would require the MMU to allocate two pages of memory, even though the second page would use one of its 4K locations.
External Fragmentation There are three segments resident in memory and 8K of free space. However, the free spaces is partitioned such that no segment greater than 3K can be loaded into memory with out moving or removing one of the currently loaded segments. Unused Segment 3 Unused Segment 2 Unused Segment 1 16K –1 13K 13K –1 9k 9k –1 6k 6k –1 5k 5k –1 3k 3k –1 0 External fragmentation in physical memory caused by segmentation
Memory Protection Why need Memory Protection? 1. A multitasking operating system may have several different program, or parts of programs, resident in memory simultaneously. 2. These program components may belong to one user or to different users. 3. The operating system may also have components.
Advantages of Virtual Memory You can run more applications at once. You can run larger applications with less real RAM. Applications may launch faster because of File Mapping. You don't have to buy more memory.
Disadvantages of Virtual Memory Applications run slower. It takes more time to switch between applications. Less hard drive space for your use. Reduced system stability.