10
Virtual Memory Chantha Thoeun

Virtual Memory Chantha Thoeun. Overview Purpose: Use the hard disk as an extension of RAM. Increase the available address space of a process

Embed Size (px)

Citation preview

Page 1: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Virtual Memory

Chantha Thoeun

Page 2: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Overview Purpose:

Use the hard disk as an extension of RAM. Increase the available address space of a process. Allow multiple applications to run concurrently. Managed by the operating system.

Implementations: Paging (most popular) Segmentation Combination of both paging and segmentation

Page 3: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Terminology Virtual address

Logical or program address that processes use Physical Address

Address in physical memory Mapping

Translating virtual addresses to physical addresses Page frames

Equal-size chunks physical memory is divided into Pages

Equal-size chunks virtual memory is divided into Paging

Process of copying a page to a page frame. Fragmentation

Memory that becomes unusable Page fault

An event signaling a requested page is not in physical memory

Page 4: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Paging Basic idea:

Allocate physical memory to processes in fixed size chunks (page frames).

Keep track of the pages of a process by recording information in a page table.

The page table stores the physical location of each page.

The page table stores a valid bit: 0 if the page is currently not in memory, 1 if it is.

Page 5: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Paging (cont.) Internal fragmentation

Pages and page frames are divided into fixed-size chunks.

Unusable space within a given page. Caused by when a process does not need an

entire page frame, but must occupy an entire page frame when loaded into memory.

Page 6: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Paging Process1. Extract the page number from the virtual address.2. Extract the offset from the virtual address.3. Translate the page number into the physical page frame number

using the page table.A. Look up the page number in the page tableB. Check the valid bit for the page.

1. If the valid bit = 0, generate a page fault.a. Locate the desired page on disk.b. Find a free page frame.c. Copy desired page into the free page frame in memory.d. Update the page table.e. Resume execution of the process causing the page fault,

continue to step B2.2. If the valid bit = 1, the page is in memory.

a. Replace the virtual page number with the actual frame number.

b. Access the data at offset in physical page frame by adding the offset to the frame number.

Page 7: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Paging Example

Page 8: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Segmentation Virtual address space is divided into variable-

length units, called segments. Each segment has a base address and a

bounds limit, indicating its size. A program consists of multiple segments, and

an associated segment table. A segment table consists of base/bounds pairs

for each segment.

Page 9: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

Segmentation Example

Page 10: Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process

External Fragmentation Free chunks that reside in memory become

broken up. These broken chunks are too small to store an

entire segment. These small chunks must then be garbage

collected to form bigger chunks (similar to defragging a hard drive).