Advantage of virtual memory in operating system

advantages of virtual memory

In this article, I am describing some issues which make your PC slow and also describing the advantages of virtual memory. But before explaining the advantage of virtual memory first let understand what is virtual memory and why it is required.

It is very important to understand the concept of memory management although Memory management is a very typical topic. A 32-bit (MIPS) processor promises each program to provide the 32-bit address space means that every program has the right to access any bytes between the address of 0 to (2^32 -1).

Note:  32-bit address space means, you have the right to access the 4 GB of memory.

In the initial era of computer processors directly access the physical memory of the system to perform the read and write operation. The main problems arise when the system does not have an adequate amount of physical memory (RAM). In that situation, if the program tries to get access to an address that does not exist in the physical address space then the system could be a crash.

So initially the concept of virtual memory comes to avoid the lesser memory issues but nowadays it plays a vital role and solves many other problems. Virtual memory is part of memory management techniques and it creates an illusion that the system has a sufficient amount of memory. In another word you can say that virtual memory is a layer of indirection. Here I will describe the advantages of virtual memory in detail.

Initially, a computer rarely has 4GB RAM but it is common today for the new generation PC. So initially the concept of virtual memory comes to solve the lesser memory issues in the system but nowadays virtual memory not only solves the lesser memory issues but also solves some other issues which usually come into a PC when there is more than one application running at a time.

 

Some Issues related to memory

1. Lesser memory issues:

It’s the most dangerous issue which generally occurs when your system has a little amount of RAM, I have already described this issue at the beginning of the article. We can solve these issues using the concept of virtual memory, it creates an illusion of there is a lot of memory available in the system using the technique of indirection.
Without the virtual memory program address directly map to the RAM addresses that means there is a one-to-one relationship exists between the program and ram memory addresses. To make more clear this scenario supposes there is any program address like 0x05 and this address directly mapped with the RAM address 0x05 but anyhow if this location not available in RAM then your system will be crash.

mapping of program and ram

We can solve this problem by using the virtual memory, it prevents the one-one mapping between the program and  RAM address and it creates a layer between the RAM and program address which is used to map the program address and RAM address and prevent the system being crash.

Image to show how to virtual memory handles the lesser memory scenario

virtual memory advantages

2. Memory hole:

Suppose there are two programs running simultaneously. The first program required 512 MB and the second program required 1 GB of physical memory for the execution.

virtual memory in operating system
When the first program is terminated by the user then memory occupied by the first program will be released and now we have the total 1GB amount of free space to execute the other program, but there is one drawback, free memory is not continuous.
So if the user runs a third program that has required only 1 GB of physical memory still unable to execute because it wants a continuous 1GB free memory even though we have 1 GB of memory space that’s the cause of memory fragmentation.

benefits of virtual memory

 

We can solve this problem using virtual memory because, with virtual memory, we do not directly access the physical memory MMU plays a vital role and map the program address space to the physical address space. Each program has its own mapping and using the mapping we can put our program data wherever we want in the RAM.

mapping virtual memory

If you want to learn more about the Windows Internals or another technology, here 10 Free days trial for you.

 

3. Keep Program secure:

We know that each program can access any 32bit memory of address. So the problem occurs when two programs share the same address (like 512) of address space to store their result.
In that situation result of one program can be altered by another program and we will not get our desired result. It’s the biggest issue that can be solved by virtual memory.

advantages and disadvantages of virtual memory in computer architecture

I have already described, a virtual memory program address map with RAM address. Here programs 1 and 2 have their own program address space so they can not access each other data and their program addresses space maps with different RAM addresses.

virtual memory map

 

 

There are many advantages of virtual memory I am mentioned a few of them. So let see the list which is describing the advantages of virtual memory.

  • Allocating memory is easy and cheap.
  • It provides a way to increase memory which is less costly than buying more RAM (physical memory).
  • It eliminates external fragmentation which I have described above in the article.
  • Data (page frames) can be scattered all over PM.
  • It resolves the lesser memory issue and allows larger applications to run in systems that do not have enough physical RAM alone to run them.
  • It allows more applications to be run at the same time.
  • Any free page is ok, OS can take the first one out of the list it keeps
  • Pages are mapped appropriately anyway.
  • Allows demand paging and prepaging.
  • More efficient swapping.
  • Just swap out the page least likely to be used.

 

Your opinion matters

Although here, I have tried to discuss a few advantages of virtual memory but I would like to know your opinion on the advantage of virtual memory. So please don’t forget to write a comment in the comment box.

Recommended Post:


7 comments

  1. good job,but for the memory constraint embedded soc system ,tradeoff of virtual memory is too big to use for some os.which run on simple mcu.

  2. Can you please explain in detail like where program will be stored. When it is loaded in to RAM and when it is loaded in to virtual memory. When it loaded back from virtual memory to RAM. What happens when RAM memory is not sufficient to load program. I mean if program size of 4GB, but RAM size is 2GB.

Leave a Reply

Your email address will not be published. Required fields are marked *