Virtual Memory

Download Report

Transcript Virtual Memory

Virtual Memory
Pranav Shah
CS147 - Sin Min Lee
Concept of Virtual Memory
Purpose of Virtual Memory - to use hard disk as an extension
of RAM.
Personal Computer doesn’t have enough memory to handle
multiple applications.
Computer addresses more main memory than it actually has
and store excess on an area of the hard drive called page file.
Most common way to implement Virtual Memory is paging,
segmentation and a combination of paging and segmentation.
Definitions.
Virtual Address - The logical or program address that the process uses.
Physical Address - The real address in the physical memory.
Mapping - The mechanism to translate virtual address into physical.
Page Frames - Equal size chunks that main memory is divided into.
Pages - Equal size chunks that virtual memory is divided into - equal to the size of
a page frame.
Paging - Process of copying virtual page from disk to page frame in memory.
Fragmentation - The memory that becomes unusable.
Page Fault - Occurs when requested page is not in memory and must be copied
from disk into memory.
Paging.
Allocate physical memory to processes in fixed size chunks
and keep track of where the various pages of the process
reside by recording information in a page table.
Every process has its own page table that typically resides
in the main memory and the page table stores the physical
location of each virtual page of the process.
Paging contd.
If there are pages of process currently not in the main
memory, the page table sets the valid bit to 0; or if the page
is already in the main memory then the valid bit is set to 1.
More fields can also bee added to relay more information.
Example: A modify bit can be added to indicate if the
page has been changed.
How paging works.
When a process generates a virtual address, the operating
system must dynamically translate this virtual address into a
physical address in memory at which the data actually
resides.
To accomplish the address translation, a virtual address is
split into a page field and a offset field.
Example of Paging
Program Address Space
Main Memory Address
A
B
Page Frame
C
D
0
C
D
E
F
1
G
H
G
H
2
I
B
K
3
J
K
L
M
A
Page Table
L
Virtual Address 1010 = 10102
N
Page
Frame
O
P
0
2
1
1
0
1
2
-
0
3
1
1
Physical Address
4
-
0
3 bits
5
3
1
6
-
0
7
-
0
Valid Bit
4 bits( Holds Value K)
1
0 1 0
1 1 0
Advantages and Disadvantages of Paging
Advantages
1.Easy to allocate memory.
2.Easy to “page out”
chunks of programs.
Disadvantages
1. Can still have internal
fragmentation.
2.Memory reference overhead
3.Memory Required to hold
page tables can be large.
Segmentation
In segmentation, virtual address space is divided into
logical, variable length units called segments.
When segment needs to be copied into physical memory,
the OS looks for chunk of free memory large enough to
store the entire segment.
A segment has a base address, indicating its location in
memory, and a bounds limit indicating its size.
Similar to Paging, Each program consisting of multiple
segments, now has an associated Segment table.
External Fragmentation in Segmentation
As segments are allocated and de-allocated, the free chunks
that reside in memory become broken up.
There are many small chunks, but none large enough to store
an entire segment.
To combat this, the systems use some sort of garbage
collection.
Garbage collection basically shuffles occupied chunks of
memory to turn the smaller, fragmented chunks into larger,
usable chunks. (Similar to defragmenting a hard drive)
Combination of Paging and Segmentation
Virtual Address space is divided into segments of variable lengths, and
the segments are divided into fixed- size pages. main memory is divided
into the same size frames.
Thus, each segment has a page table, which means every program has
multiple page tables.
Physical Address is divided into 3 fields: the segment field to point to
the appropriate page table, the page number to offset into this page
table and the offset within the page.
Combined, Paging and segmentation is very advantageous as it allows
for segmentation from user point of view and paging from system’s point
of view.