Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.

Similar presentations


Presentation on theme: "Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001."— Presentation transcript:

1 Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001

2 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.

3 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.

4 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.

5 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.

6 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

7 Two primary methods to implement virtual memory Paging Segmentation

8 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

9 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.

10 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?

11 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......

12 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.

13 Example of Page table and corresponding Physical Memory 0 111 00 0 0 0 0 0 0 0 1 10 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 Frame Valid Count Dirty 0123456789ABCDEF0123456789ABCDEF Page 4 Unused Page 0 Page F 3FFFH 3000H 2FFFH 2000H 1FFFH 1000H 0FFFH 0000H Physical Memory Page Table

14 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.

15 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.

16 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

17 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.

18 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

19 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.

20 Segments compared to paging Segments has advantage (internal fragmentation), and disadvantage (external fragmentation)

21 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.

22 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

23 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.

24 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.

25 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.

26 Thanks The End Do you have any Question ?


Download ppt "Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001."

Similar presentations


Ads by Google