Virtual Memory Thi Nguyen

Download Report

Transcript Virtual Memory Thi Nguyen

VIRTUAL MEMORY
By
Thi Nguyen
Motivation
 In early time, the main memory was not
large enough to store and execute
complex program as higher level
languages became popular.
 In 1961, virtual memory was proposed to
solve the problem of storage allocation.
Definition
 Virtual memory is a memory management
system that gives a computer the
appearance of having more main memory
than it really has.
Advantages
 Main memory is used more efficiently.
Only those portions of an executing
program that are in use occupy main
memory.
 Programs that are bigger than main
memory can still be executed
Implementation of Virtual
Memory
 The virtual memory abstraction is
implemented by using secondary storage
to augment the processor's main memory.
 Data is transferred from secondary to main
storage when necessary and the data
replaced is written back to the secondary
storage.
Implementation of Virtual
Memory
 If the data swapped is designated a fixed
size, this swapping is called paging.
 if variable sizes are permitted and the data
is split along logical lines, it is called
segmentation.
 Some operating systems combine
segmentation and paging.
Paging
 In a simple paging system view,
 user programs consists of fixed-length blocks
called pages.
 Main memory consists of fixed-length blocks
called frames.
 When an operating system loads a user
program into memory, it loads each page
into any available frame.
Page Table
 To keep track of the location of each page
in the memory, the operating system
builds a one-dimensional array called
Page Table.
Page
Number
Frame
Number
Valid bit
0
0
0
1
0
0
2
2
1
3
5
1
• 0 means not in memory
Mapper
 The mapper is the part of the operating system
that translates the logical page number
generated by the program into the physical page
frame number where the main memory holds the
page.
 This translation is accomplished by using page
table. If the page table reveals that the page is
not resident in the main memory, the mapper
issues a page fault to the operating system so
that execution is suspended on the process until
the desired page can be read in from the
secondary storage and placed in main memory.
Page in
 The corresponding operation of reading
them in again later when one of the pages
is referenced is called a page in.
Page out
 The operation of writing one inactive page,
or a cluster of inactive memory pages to
disk is called a page out.
Advantages
 Paging is effective because programs
typically only use a small proportion of
their virtual memory pages actively at any
one a time.
 Allows a program that is too big to fit into
memory to be executed
Disadvantages
 Once the memory is allocated for modules
they cannot vary in size. This restriction
results in either wastage or shortage of
memory.
 In paging system, stack is put at the top of
its logical address space; data and code
are put at the bottom. The gap between
them requires a page table that is too big.
Segmentation
 the program is divided into functional
segments such as code segment, stack
segment, data segment…
Segmentation
 some computer systems have their main
memory divided into many independent
address spaces. Each of these address
spaces is called a segment. The address
of each segment begins with 0 and
segments may be compiled separately.
Segmentation
 Each segment in the program can be
transferred into segments in main memory.
However, it may happen that the program
segment is too big to fit in main memory
segment.
Segmentation with Paging
 Some operating systems allow for the
combination of segmentation with paging.
If the size of a segment exceeds the size
of main memory, the segment may be
divided into equal size pages.
Segmentation with Paging
 Each segment has its own page table.
 The used gap in the address space would
not be represented by any page table.
Virtual Address
 The address consists of three parts:
 (1) segment number
 (2) the page within the segment
 (3) the offset within the page.
 The segment number is used to find the
segment descriptor and the address within
the segment is used to find the page frame
and the offset within that page.
Comparison between Paging and
Segmentation
 SEGMENTATION
 Involves
programmer
 Separate compiling
 Separate
protection
 Shared code
 PAGING
 Transparent to
programmer
 No separate compiling
 No separate protection
 No shared code