Virtual memory is one of the most significant memory management technique that is used by an operating system. In a common parlance we can say that virtual memory is nothing but the space on the hard disk that is used as Physical Memory address by the operating system. It is very useful technique not only from the performance point of view but also for cutting costs. In this technique hard disk space is used as memory of the of system. The cost of Hard Disk is quite cheap as compared to that of the RAM (Random Access Memory). So using this technique we can have the benefits of much larger RAM even if we have a small sized RAM and enough Hard Disk space.
Virtual memory is also known as swapped memory or swap space in computing terminologies. Thus virtual memory is a combination of RAM and some reserved space on the Hard Disk. This reserved space on the disk is usually termed as the Swap Space.
Why Virtual Memory is needed?
When a program is to be executed by the CPU, it needs to be uploaded in the memory. There is a program called Loader whose job is to load a particular program in the memory. Now think of a program which very large in the size say larger than the size of your physical memory. What would happen then, the CPU won't be able to load the program in the memory as there is not enough space available in the memory. Therefore that program can not be run in your system.
To overcome such a situation the memory management technique like virtual memory came into picture. This helps to execute a program even larger than the size of RAM or physical memory of your system. Virtual memory technique utilizes the hard disk space of the system to load programs.
The researchers have observed that not the whole program needs to be loaded in the RAM on any given point of time. A program can be executed even if a portion that is referenced currently is loaded in the memory. Virtual memory utilizes this and swaps out the portion of the program that are not currently needed to the hard disk.
How Virtual Memory works?
To run a process CPU needs to be loaded into the physical memory. A processes is comprised of the programs ( set of instructions ) and data structures that manage it. Each process is allocated a valid addresses in the memory.
When a program starts its execution memory address is generated for it. These addresses are logical addresses which is translated into the physical address by referring the page allocation table. But the running program doesn't know the difference between the logical and physical address. It thinks that it accessing the physical address.
Virtual memory uses paging technique. Paging is also one of the very important memory management technique. It helps to store and retrieve data from the Hard Disk. The whole memory in divided into equal size of chunks known as a page.One of the most significant benefit of paging is that it allows the memory address to be Non contiguous. If there is not enough space on the physical memory the space from the hard disk is allocated by the memory manager.
How much space should be allocated as Virtual Memory:
You can allocate as much space available from your hard disk to Virtual Memory. But, performance wise it is highly recommended that the Virtual Memory should be Twice the size of your RAM.
For example, if your RAM size is 1GB than the size of your virtual memory should be 2 GB.
Advantages of Virtual Memory:
Disadvantages of Virtual Memory:
The only disadvantage of Virtual Memory is that your program execution become a bit slower. This caused by of the slow speed of Hard Disk as compared to that of the physical memory or RAM.
How to set Virtual Memory of your System:
If you are a windows user you can easily set up the size of Virtual Memory of your system. Just follow the steps mentioned below and you are done:
Step 1: Right Click on "My Computer"
Step 2: Click on Advance Tab.
Step 3: Click on the Setting of the Performance Tab
Step 4: Click on Advance Tab.
Step 5: Under the Virtual Memory Tab you can see the current size of your Virtual Memory of the system
Step 6: Click on Change button.
Step 7: Select the radio button Custom size.
Step 8: Enter the Initial Size and Maximum size in MBs for your Virtual Memory. Click on the radio button for System Manged sized or No paging file whatever you want.
Step 9: Click Ok
Step 10: Restart your system.
That's it you have set the size of Virtual Memory for your system.
More articles: Memory