Virtual Memory in OS: What is it and How it Works

Virtual Memory in OS: What is it and How it Works-feature image

As individuals, we are always juggling work in different spheres of our lives. The same is true when we are working on a computer. We load multiple applications or browser tabs at once.

However, RAM, the part of memory that stores actively running applications, is finite. Hence, there is a limit on loading applications as RAM eventually runs out. This is where virtual memory in computer architecture comes in.

It is a feature of any operating system in which a portion of secondary memory is temporarily treated as additional RAM. This way, virtual memory allows you to compensate for the shortage of actual RAM.

Virtual memory is quite important given the complexity and size of applications these days. Let us discuss what virtual memory is and have a better understanding of this concept.

What is Virtual Memory in Operating System (OS): An Overview

Virtual Memory or virtual RAM is a mechanism for memory management by any operating system (OS) where a section of secondary or volatile memory is treated as main memory temporarily. It does this by swapping data that has been recently unused from RAM to disk storage, like hard drive or solid-state drive. When the data is needed, it is copied back into the original RAM.

This happens when RAM is running low, and several processes are going on simultaneously. Virtual storage enables users to load larger volumes of computational processes than the actual available primary memory, thus it is beneficial for large programs. The operating system is also able to load different parts of separate processes in the main memory, which is required for multitasking.

However, if the data needs to be swapped often, your computer system can slow down. Virtual memory is normally implemented by demand segmentation and demand paging. Knowledge of demand paging is essential to explain virtual memory implementation.

Basic Terminologies

  • Program: A set of instructions for the execution of tasks in a computer

  • Process: A process in operating system is any activity for execution of program code sequentially.

  • Thread: Path followed during the execution of a program. An operating system has multithreading ability to manage multiple requests by one user optimally.

  • Page: In an operating system, the memory is divided into units known as pages. These pages are used for storing programs.

Suggested Read: What Are Storage Devices and How Do They Work

What is Demand Paging?

Demand Paging is the process of storing all pages in a computational process in the secondary memory for virtual memory management. Deciding what pages should be a part of main memory and which ones should be under virtual memory can be difficult to predict before the actual requirement. So, no page is loaded in the main memory beforehand.

In the main memory, when a page is referred initially, it will be present in the secondary memory. The pages to be replaced are determined through different available page replacement algorithms. Hence, the page may or may not be available in the main memory later on.

Only pages that are required by a computational process at the moment are loaded and other pages are swapped either on demand or on undesirable occurrence of page fault. Virtual memory is usually implemented by this technique.

Explaining Virtual Memory Working in OS

how virtual memory works

Now that you know what virtual memory in operating systems is, let’s understand its working too.

Whenever during a process execution, the main memory is not available for the programs that need to be loaded, the operating system (OS) automatically makes space for storing these programs in the form of pages.

It does this by copying the least used or referenced areas in the RAM into a section of secondary memory. Hence, your virtual memory consists of this data.

When a portion or page is required, it is loaded into the main memory. The operating system partitions the memory with a defined number of addresses into swap or page files. Its memory management unit translates the virtual address into real address while copying the data.

The memory manager tracks all the shifts between physical and virtual memory. This way, processes that cannot be fully loaded into the physical memory also get executed.

Suggested Read: List of 12 Best Free Android Data Recovery Software in 2022

For instance, suppose there is X MB of available physical memory on RAM but the OS needs Y MB more memory to store running programs. Then, Y MB of virtual memory will be set up and addressed by the operating system. A file of Y MB Size on hard disk or SSD will store extra memory. The size of the virtual memory depends on the available disk storage.

If virtual memory in computer architecture starts running low, you might need to increase the paging file’s size or purchase extra RAM.

How to Manage Virtual Memory in an Operating System?

explain virtual memory in operating system

Virtual memory consists of disk storage getting used as additional RAM. The amount of hard drive space that can be defined as virtual memory in OS for processes and applications is determined by the default settings.

However, if you have several hard disks or applications that rely on rapid response times, you can do virtual memory management in OS manually by resetting the amount of disk space allocation.

For those who are wondering how to increase virtual memory in manual reset, you must specify the maximum and minimum amount of drive space. It must be an optimal range to ensure that the virtual memory is sufficient for your system needs.

Check the RAM size on your system to know what the virtual RAM’s optimal range is. The size of virtual memory depends on what times the actual RAM value is recommended for your operating system. For instance, it is between 1.5 to 3 times the actual RAM size in Windows OS. However, if virtual memory management in OS does not fulfill your requirement, you should consider adding RAM.

To understand how to increase virtual memory better, let’s take an example of the Windows operating system.

To define virtual memory in OS, the steps are:

  • Navigate to Start> Settings.
  • In the search bar, type performance
  • Choose Adjust the appearance and performance of Windows. A window will appear.
  • Select Advanced tab
  • Under Virtual memory section, select Change.
  • In the window, unselect the Automatically manage paging file size for all drives box.
  • Click on Custom size.
  • Enter the values in the Initial Size and Maximum Size boxes.
  • Click OK to save the new virtual memory range definition.

Suggested Read: What is Utility Software: Top 10 Utility Software Examples 2022

Virtual Memory vs Physical Memory in OS

The virtual memory meaning cannot be complete without comparing it with physical memory. When physical memory (RAM) gets filled, virtual memory which is a part of secondary memory is used by an OS. Some of the key differences between the two memory types are:

ParameterVirtual MemoryPhysical Memory
DefinitionA segment of secondary memory acts as virtual storageMain memory: Primary RAM and secondary HDD/ SSD
PurposeStoring data that can be used by RAM whenever it is actively neededPrimary memory for active programs and secondary for storage
SizeDepends on size of hard drive/ SSDDepends on RAM chips; additional chips can be purchased and installed
Technique UsedPaging & segmentationSwapping
Access to CPUNot direct, through RAMDirect

Advantages of Virtual Memory in OS

There are several benefits of virtual memory in a computer. The techniques used in virtual memory management also apply to a virtual machine that needs more resources than it possesses for better performance. Some of the major benefits of virtual RAM are discussed here:

Low-cost extra memory allocation
High security due to data isolation and encryption
Better CPU utilization by running more processes at once
Multiprogramming becomes easier
Can run large programs and load more applications at once

Disadvantages of Virtual Memory in OS

There are certain downsides to using virtual RAM too. To understand what virtual RAM’s effectiveness is, you must know them.

Needs extra hardware for address translation
Lower system stability
Decreases available hard drive storage space
Size is limited by the amount of secondary memory available
Performance degradation as switching between applications is slower

Suggested Read: What is a Utility Program & What Are Its Functions?


Now that you know what the virtual memory in OS is, you can decide the best approach to multitasking. Deciding whether you want to buy additional RAM or manually set virtual memory range is possible after weighing the pros and cons for your system.


  1. What is virtual memory and how does it work?

    Virtual memory is space in the secondary memory that is allocated as RAM. The operating system allocates virtual memory when actual RAM gets filled for reading and writing data for processes and programs.

  2. Why virtual memory is needed?

    Virtual memory is needed to increase the available space in main memory when RAM gets filled and you do not want to buy extra RAM at an additional cost. This allows users to easily run large programs and do multitasking.

  3. Is virtual memory faster than RAM?

    No, virtual memory is slower than RAM as it is a part of secondary memory, where read/ write operations take time.

  4. What is virtual memory of PC?

    Virtual memory of PC is the space allocated on the solid state drive (SSD) or hard drive that acts as additional RAM for actively running apps and programs.

  5. What happens in the virtual memory?

    In virtual memory, the data that is not immediately needed from the RAM gets stored. Whenever a process needs the data, it is copied back into the RAM.

  6. How does virtual memory affect performance?

    Using virtual memory helps run large programs easily. However, it decreases the speed of the PC as opposed to RAM, thereby affecting the performance.

  7. What is virtual memory example?

    A virtual memory example would be when you run multiple applications at once. For example, running a spreadsheet software along with an image processing software while refreshing emails.

  8. How does virtual memory improve security?

    Data in virtual memory is encrypted and isolated from the rest. This prevents apps and individuals from accidental access to sensitive information.

  9. Is virtual RAM effective?

    Yes, virtual RAM makes space for large programs and helps in efficient management of tasks.

  10. How do I manage virtual memory?

    In your device, navigate to Start > Settings > Control Panel. Go to the System Properties dialog box after double clicking on the System icon. Select the Advanced tab>Performance Options. Click Change under Virtual memory. The value must be between 1.5 and 3 times the amount of actual RAM on the device.

Related Categories: Operating System | Server Operating System | Server Solution | Application Virtualization

Was this article helpful?

Would you like to get latest offers on software?

Thank you for your feedback! Soon we will provide you best offers

  • 45
  • 3

Recommended Products

Talk To Tech Expert