You are on page 1of 2

VIRTUAL MEMORY

What is virtual memory:


➢ Virtual memory is memory management technique that give illusion to user that system
has much larger memory than actually available memory.
➢ The basic idea behind the technique is that the combined size of code, data and stack
exceed the amount of physical memory.
➢ This virtual memory is free program from the constraints of physical memory
limitation.
➢ Virtual memory cam be implemented by demand paging or demand segmentation.
➢ Demand paging is commonly used as it easier to implement.
Need of virtual memory:

• Whenever a program needs to executed, it must reside in the main memory.


a) The program with smaller size than the size of memory can be fitted entirely
in the memory at once for execution. However, the same is not possible for
larger programs.
b) When a program come for execution, it has all necessary program for
execution. In addition, some portion of the program is rarely or never
executed. Thus, keeping such code segment in the memory, the result is
wastage of memory.
Solution of wastage of memory:
A technique is called virtual memory tends to avoid such wastage of memory.
As per technique, the operation system loaded into the memory only those part of the program
that are currently needed for execution of the process. The rest is kept on the disk and is loaded
only when needed.
The main advantages of this scheme are that the programmers get the illusion of much larger
memory than physical memory, thus the size of user program would ni longer be constrained
by the amount of available physical memory.
Since each user utilizes less physical memory, multiple user are allowed to keep their program
simultaneously in the memory. The result in increased utilization and throughput of the CPU.

Demand paging:
Def^- It is a memory management technique used by operating system to manage physical
memory more efficiently. It allows the operating system to load only the required parts of a
program into memory at the time of execution. Page that never accessed are never loaded into
the memory
A demand paging system combines the feature of paging and swapping. Thus, it requires the
same hardware as required in paging and swapping. That is, it needs a secondary storage and
page table.
Secondary storage- To facilitate swapping, the entire virtual address space of a process is
stored contiguously on a secondary storage device (usually a disk).
Whenever a process to be executed, an area on secondary storage device is allocated to it on
which its pages are copied. The area known as swap space of the process.
During the execution of a process, whenever a page is required, it is loaded into the main
memory from the swap space. Similarly, when the process is to be removed from main memory,
it is return back into the swap space if it has been modified.
Page table- To differentiate the page that are in memory from those on the disk, and an
additional bit valid is maintained in each page table entry to indicate whether the page is in the
memory or not.
If a page is valid (that is, it
exists in the virtual address space of the process) and is in the memory, the associated valid bit
is set to 1, otherwise it is set to 0.
7
6
5
Page 1
Frame valid 4
Number bit 3
Page 3 Page 3
12M-16M 0 0 2
8M-12M Page 2 1 4 1 1
Page 1 0
4M- 8M 2 0
Page 0 2 1
0M- 4M 3
Logical memory Page table physical memory
[page table in demand paging system]
Whenever a process requests for a paging

You might also like