VIRTUAL MEMORY and
MEMORY MANAGEMENT
REQUIREMENT
Presented by:
ANKIT SHARMA
NITESH PANDEY
MANISH KUMAR
What is
An
imaginary memory area supported
by some operating system.(e.g
Windows but not DOS)
Virtual memory is an alternate set of
memory addresses.
Programs use these virtual addresses
rather than real addresses to store
instructions and data.
When the program is actually executed,
the virtual addresses are converted into
real memory addresses.
HISTORY
virtual
memory was developed in
approximately 1959 1962, at the University
of Manchester for the Atlas Computer,
completed in 1962.
In
1961, Burroughs released the B5000, the
first commercial computer with virtual
memory.
WHY WE NEED IT..
An operating system needs 120mb of memory
in order to hold all the running programs ,but
there is currently 50mb of available physical
memory stored on the RAM chip so at that
situation what the processer does ?
Answer
At that time the O.S will then set up the 120 mb of
virtual memory and will use a program called the
VMM to manage that 120MB. The vmm will create
a file on hard disk that 70mb in size of account for
the extra memory that is needed
OBJECT..
Multiple
programs can be implemented
efficiently.
Enlarge
the address space, the set of
addresses a program can utilize.
Virtual
memory might contain twice as
many addresses as main memory.
A System with Physical Memory Only
Examples:
most Cray machines, early PCs, nearly all embedded systems, etc.
Memory
Physical
Addresses
0:
1:
CPU
N-1:
Addresses generated by the CPU point directly to bytes in physical
memory
A System with Virtual Memory
Examples:
Memory
workstations, servers, modern PCs, etc.
Virtual
Addresses
0:
1:
Page Table
0:
1:
Physical
Addresses
CPU
P-1:
N-1:
Disk
Address Translation: the hardware converts virtual addresses
into physical addresses via an OS-managed lookup table (page
table)
Implementation of VM
Virtual memory can be implemented via:
Demand paging
Demand segmentation
paging
The VMM create a file on hard disk thats holds the extra memory
that is needed by the O.S which is our case in 70 MB in size this
file is called a paging file
Whenever the O.S need a block of memory that is not in the real
memory ,the VMM takes the block of memory from the paging
file and moved it into the real memory this process is called a
paging and the block of memory that are swapped is called a
page
The number of frame denotes the no of page that can be held in
ram at any given time
Page table..
Each process has its own page table
Each page table entry contains the frame number of the
corresponding page in main memory
A bit is needed to indicate whether the page is in main memory
or not
10
Valid-Invalid Bit
With each page table entry a validinvalid bit is associated
(v in-memory, i not-in-memory)
Initially validinvalid bit is set to i on all entries
Example of a page table snapshot:
Frame #
valid-invalid bit
v
v
v
v
i
.
page table
i
i
During address translation, if validinvalid bit in page table entry
is I page fault
Page fault
If the vailed bit is 1, then the virtual page is in RAM ,and you can
get the physical page for the PTE this is called a page HIT
If the vailed bit is 0, then the virtual page is not in RAM ,this
means we must get the disk page corresponding to the physical
page from disk and place it into a page in RAM this is called a
page fault
Steps in Handling a Page Fault
Performance of Demand Paging
Page Fault Rate 0 p 1.0
if p = 0 no page faults
if p = 1, every reference is a fault
Effective Access Time (EAT)
EAT = (1 p) x memory access
+ p (page fault overhead
+ swap page out
+ swap page in
+ restart overhead
)
EAT=(1-p) x memory access + p(avg. fault service
time)
Demand Paging Example
Memory access time = 200 nanoseconds
Average page-fault service time = 8 milliseconds
EAT = (1 p) x 200 + p (8 milliseconds)
= (1 p) x 200 + p x 8,000,000
= 200 + p x 7,999,800
If one access out of 1,000 causes a page fault, then
EAT = 8.2 microseconds.
This is a slowdown by a factor of 40!!
VIRTUAL ADDRESS
TRANSLATION
What
happens during a memory access?
map
virtual address into physical address
using page table
If
the page is in memory: access physical
memory
If
the page is on disk: page fault
Suspend
Get
program
operating system to load the page from disk
Page translation
Address
bits = page number + page offset
Translate
virtual page number(VPN) into
physical page number(PPN) using page table
Lets assume that we have 1MB of RAM is also called physical
and 10MB of disk memory and size of page is 4k then..
What is page number ?
Thus 1M/4k =256 pages thus our ram has 256 physical pages
which holding 4K
Lets assume we have 10MB of disk thus we have 2560MB of
pages
SEGMENTATION:
Divide
virtual space of the process intosegments. Similar
to paging except we can have segments match with
needed sizes.
virtual
addresses comprised ofsegment
numberandsegment offset
highnbits of virtual address give segment
number
remaining lower bits give the segment offset
number of bits in segment number limit number
of possible segments
virtual addresses bound to physical addresses at
access time
Address translation:
Address
translation makes use ofsegment tables.
A segment table contains an entry for each
segment for a process. Entries contain:
pointer
to start of segment in physical memory
(base)
size
of segment (bounds)
indication
of whether or not segment is currently
in memory
protection
information
HARDWARES ROLE:
The hardware performs the following address translation for
every memory reference:
extract segment number from virtual address
if segment number is greater than max number of segments,
trap with ``illegal segment''.
consult segment table entry.
if segment not present in memory, trap ``missing segment
if segment offset is greater than segment size, trap ``offset
out of range
if process does not have access permissions, trap
``protection violation''
Segment Faults:
When a process references data in a missing segment, the
hardware generates asegment faultthat traps to the kernel.
The fault handler:
tries to find a chunk of free memory into which it can place the
missing segment
if no free chunk is available, it must first swap out an existing
segment to make room
loads the new segment into memory
restarts the process that caused the fault
Segmentation with Paging: Intel
Intel Pentium supports segmentation. A
Pentium
segmentselectoris 16 bits (13 bits to identify a
specific segment).
These
bits map to a segment descriptor, which
contains the base address and size of the segment.
Combined with offset the result is a 32-bit linear
address.
If
paging is disabled this address is a physical
address (pure segmentation).
Contd.
If paging is enabled then address is a virtual address.
Three level scheme:
page directory entry--10 bits
page table entry--10 bits
offset--12 bits (4K page)
Note: can also disable segmentation by mapping
entire address space to same segment and have pure
paging.
MMU (Memory Management Unit)
The hardware base that makes a virtual memory
system possible.
Allows software to reference physical memory by
virtual addresses, quite often more than one.
It accomplishes this through the use of page and page
tables.
Use a section of memory to translate virtual addresses
into physical addresses via a series of table lookups.
HOW DOES IT WORKS
To
facilitate copying virtual memory into
real memory, the operating system divides
virtual memory into pages, each of which
contains a fixed number of addresses.
Each page is stored on a disk until it is
needed.
When the page is needed, the operating
system copies it from disk to main
memory, translating the virtual addresses
into real addresses.
MEMORY MANAGEMENT
REQUIREMENT
:
Memory management should satisfy the following requirements:
[Link]
[Link]
[Link]
[Link]
organization
[Link]
organization.
Relocation:
Relocation is a basic requirement of memory management. For
simplification purposes let us assume that the process image occupies a
contiguous region of main memory. The operating system need to know the
location of:
Process control information
Execution stack
Entry point to begin the execution of a program.
Processor must deal with memory references within the program.
Branch instructions contain an address to reference the instruction to be
executed next.
Data reference instructions contain the address of the byte or word of
data referenced.
SHARING:
Any
protection mechanism must have the flexibility to allow
several processes to access the same portion of main
memory.
E.g., if numbers of processes are executing the same
program then it is advantageous to allow each process to
access the same copy of the program rather than its own
separate copy.
PROTECTION:
Once
we have two programs in memory at the same
time there is a danger that one program can write to
the address space of another program. Every process
should be protected against unwanted interference by
other processes. Satisfaction of the relocation
requirement increases the difficulty of satisfying the
protection [Link] tend to support absolute
addressing which means that code runs differently
when loaded in different places.
It
is not possible to check the absolute address at
compile time. Most of the
programming
languages allow the dynamic calculation of address at
run time.
[Link] organization:
Main
memory is organized as a linear or onedimensional address space that consists of
sequence of bytes or words. Secondary memory
at its physical level is similarly organized. Most of
the programs are organized into modules.
PHYSICAL Organization:
Computer
memory is organized into two
levels:Main memory- Main memory is a volatile
memory and it provides fast access at relatively
high cost.
Secondary
memory- Secondary memory is a
non-volatile memory and it is slower and cheaper
than main memory.