0% found this document useful (0 votes)
7 views

Notes on Virtual Memory

Uploaded by

aryan rusia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Notes on Virtual Memory

Uploaded by

aryan rusia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Concept of Virtual Memory

 This is the memory management capability of the operating system that


provides an illusion to the user that the system has a very large main
memory (RAM), even though the computer actually has a relatively small
main memory.
 Virtual memory allows several applications running simultaneously on a
system which are having total size larger than the main memory.
 In earlier versions of operating system users were not able to large number
of applications simultaneously because of lack of RAM space.
 This concept belongs to main memory (RAM) and hard disk. As we know,
lack of RAM size makes our system slower; therefore, concept of virtual
memory allows increasing the speed of the systems up to certain extent.
 Concept of virtual memory is based on the swapping of unused files into a
separate partition of hard disk reserved for virtual memory. Swapping of
data between RAM and hard disk also takes some time but it happens so
fast that the user remains unable to recognize it.
 In windows, minimum hard disk space reserved for virtual memory =1.5
times of RAM size and maximum hard disk space can be reserved for virtual
memory = 3 times of minimum virtual memory size.
 In this concept, whole RAM is divided into blocks of equal size.
 Virtual memory space and hard disk is divided into equal size pages and
must be block size of RAM. Each page has its own page table associated
with it.
 Every time whenever the RAM is accessed, processor looks into the page
table to find corresponding page in the RAM.
Hard Disk
Main Memory Page 0
Block 0 Page 1
Block 1
Page 2
Block 2
:
Block 3
: Virtual Memory Portion
:
 Pages are loaded into the blocks of RAM from the disk whenever they are
need by the CPU. Page fault occurs if desired page is not found in the RAM.
 If all the RAM blocks are full, operating system takes decision to swap the
block from disk by using replacement algorithms i.e. first in first out (FIFO),
least recently used (LRU) etc.
 In swapping technique, a process which is not in use currently is moved
from RAM to virtual memory space temporarily and another process is
moved from virtual memory space to RAM to be used by the CPU.
 Virtual memory can be implemented by using paging technique and
segmented paging technique.
 In paging technique, address space of hard disk is divided into equal size of
pages it is like a book of equal size pages without chapter while in
segmented paging technique, unequal size (may be equal also but mostly
unequal) segments containing more than one pages are created.
 Each segment has its own base address which is used to access the desired
number page of virtual memory space.
 Effective address of each page in segmented paging technique becomes
segment base address + page number.
 Paging technique is just like a book with equal size pages without chapters
and segmented paging technique is just like a book with chapters of
unequal number of pages and starting page number of each chapter as base
address of each segment as shown in figure.
Paging in address space Segmented paging in address space

Page 0 Segment-0 Base Page 0


Page 1 Address=0 Page 1
Page 2 Segment-1 Base Page 0
Page-3 Address=2 Page 1
Page-4 Page 2
Page-5 Segment-2 Base Page 0
Page-6 Address=5 Page 1
Page-7 Segment-3 Base Page 0
Page-8 Address=7 Page 1
Page-9 Page 3
 In the virtual memory concept, address mapping of main memory with
address space in hard disk is done with help of virtual (logical) address and
physical (actual) address.
 A virtual memory system provides a mechanism for translating program-
generated addresses into correct main memory locations (by using mapping
tables).

 Address mapping in paging technique : Consider a virtual memory size = 8k


words divided into four equal size pages each of size= 2k (2048) words and
assume main memory of size 4k divided into two blocks each of size =2k
(always page size = block size).

Main Memory Space


Address Space
Page 0 (2k) Block 0 (2k)
Page 1 (2k) Block 1 (2k)
Page 2 (2k)
Page 3 (2k)

 Virtual address bits n =13 (213= 8x1024) and physical address bits m=12
(212= 4x1024).
 Virtual address bits are divided into two parts in paging technique and
mapped to physical address using page table as shown below.
Page No. Word N0. Block bit Word bits
2 20 1 20

Page Table
Block 0 (2k)
Page No. Block No. Valid bit
Block 1 (2k)
0 0 1
1 - 0
2 1 1
3 - 0

 Suppose CPU generates following virtual address of 13 bits. This address


indicates that CPU needs to access 20th word from block-1 of main memory
because page table shows that block-1 is available in page-2 of address
space.

Page bits Word bits


10 00000010100

Therefore, this virtual address is mapped into physical address of 12 bits as

Block bit Word bits


1 00000010100

 Suppose, if the generated address is 01 00000010100 there will be a page


fault because this page does not exist in the main memory and this page
has to be brought from secondary memory. There will also be page
replacement also because at present both of the blocks of main memory is
occupied by page-0 and page-2 of secondary memory.
 In this type of fixed paging technique, frequent page fault may occur if
pages are of smaller size and larger page size may cause under utilization of
physical memory. These two problems have been overcome somehow in
segmented paging technique.
Segmented paging technique: The fixed page size used in the virtual memory
system causes certain difficulties with respect to program size and the logical
structure of programs. It is more convenient to divide programs and data into
logical parts called segments. Segments may be generated by the programmer
or by the operating system. Examples of segments are a subroutine, an array of
data, a table of symbols, or a user's program. The length of each segment is
allowed to grow and contract according to the needs of the program being
executed.
 Address mapping in segmented paging technique: In this technique, logical
address is divided into three parts.

Segment bits Page bits Word bits

 Consider virtual memory space has 16 segments; maximum of 256 pages in


one segment, and each page consists of 256 words.
 Suppose CPU generates 20 bit logical address to access the data from main
memory. This logical address will be converted into physical address for
main memory of 64 blocks each of 256 words by using segment and page
tables.

Segment bits Page bits Word bits


0110 0000 0010 0111 1110
th
(6 segment) (2nd page ) (126th word)

Segment Table Page Table


Segment Base Page No. Block No. Block No. Word No.
No. Address 0 0
0 1
1
1 :
: :
37 19 19 126
6 35
: : :
F 255 63

Effective page no. = Physical address=


Base address+ page no. 10011 01111110
=35+2 =37 (13 bits)

You might also like