Apart from the physically installed memory, a computer also has some extra memory which is known as virtual memory. It is a storage scheme that allows the secondary memory to be addressed as a part of the main memory. It is a part of the hard disk, set up to copy the RAM.

This uses hardware and software to compensate for physical memory shortages and transfers data from RAM to disk storage temporarily. Though it is slower than RAM it increases system performance and multiprogramming.

It is a technique that allows the execution of processes that may not be compiled within the primary memory.

  • It separates the user’s logical memory from the physical memory.
  • This separation allows an extremely large memory to be provided for the program when only a small physical memory is available.
  • Virtual memory makes the task of programming much easier because the programmer no longer needs to work about the amount of physical memory is available or not.
  • Virtual memory allows files and memory to be shared by different processes through page sharing.
  • It is most commonly implemented by demand paging.

Virtual memory functions as extra memory, providing system support like additional RAM. Virtually memory swaps non-essential data to a temporary file in the hard disc or permanent storage. It can call the data later when necessary. Virtual memory can be super handy when a device or processor needs a memory boost. It’s also less costly than the actual RAM. However, such memories are not without disadvantages. One must be aware of the pros and cons of virtual memory to avoid unexpected consequences.

The conditions, when an entire program needs not to be fully loaded in main memory are:

  • If an error occurs in data or computation, then user-written error handling routines are used to dissolve this error.
  • Certain options and features of a program are quite rare to see and are not used commonly.
  • Multiple tables, even though only a small amount of these tables is used, have a fixed amount of address space addressed to them.
  • The ability to execute a program that is only partially in memory counters a lot of benefits.
  • It requires a lesser number of I/O to load or swap each user program into memory.
  • A program is no longer bound by the amount of available physical memory.
  • User programs take less physical memory, and multiple programs are run in one go. This increases CPU utilization and throughput.

How virtual memory works in OS

RAM helps store the data of a program in a physical address, when it is in use. A memory management unit maps this address to RAM and translates addresses automatically. When the RAM needs to be free for a more urgent task than the one currently running that data is swapped out of the RAM into virtual memory.

The memory manager keeps track of these shifts between physical and virtual memory in case the data is needed again for resuming execution. When the OS copies virtual memory into physical memory, it divides the memory into either pagefiles or swap files and stores these pages on a disk. When needed, the OS copies the pages back into the main memory and translates the virtual addresses into real addresses.

Types of Virtual Memory/ RAM?

The first step in knowing about virtual memories is to learn their classification. Computers handle virtual memory either through paging or segmentation. So, the type of virtual memory depends on how it’s being handled. Below is a bigger picture about them:

1. Paging

This kind of virtual memory operates by partitioning memory into parts known as paging files. When RAM is full, it moves any unused pages to the specific part of a hard drive designated for virtual memory. This procedure is executed by the computer utilizing a swap file. A swap file is a predefined area on the hard drive for expanding the virtual memory of the RAM. Moving unnecessary data to the hard drive makes some free RAM space for necessary activities and guarantees that the system never runs out of actual memory.

The computer utilizes page tables to convert virtual addresses into physical addresses. This is done as only a part of the instruction processing system by the Memory Management Unit of the computer.

For more information: Paging

2. Segmenting

Another technique of controlling virtual memory is called ‘segmenting’. This process splits virtual memory into segments of different lengths and transfers unused segments from the virtual memory of the computer to the hard drive. Segment tables, like page tables, keep track of whether a segment is stored in the memory or as a physical address.

The difference between segmenting and paging is that segmenting parts of memory into different lengths, while paging divides memory into equal-sized pieces. In paging, the computer’s hardware decides section size, while in segmentation, the user may choose segment length.

Advantages of Virtual Memory in OS

The following are the advantages of Virtual Memory in Operating System:

  • We can run multiple applications at the same time.
  • We can fit many large programs into smaller programs.
  • Implementing a multiprogramming environment is easier.
  • It ensures effective utilization of the processor.
  • We can read data from the disk when required.
  • It is easy to share common data between memories.
  • It speeds up a process when only a particular segment of the program is required for the execution.
  • The process size can be larger than that of the physical memory.

Disadvantages of Virtual Memory in Operating System

The following are the drawbacks of Virtual Memory in OS:

  • It reduces system stability.
  • Poor performance as compared to that of RAM.
  • Applications run slower.
  • It affects the overall performance of a system negatively.
  • This occupies the storage space that can be used for long-term data storage
  • It takes a lot of time to switch between applications.

How to manage virtual memory in Operating System

There are default settings in a system to manage as they can determine the amount of hard drive space to allocate for virtual memory. These settings work for almost all the applications and processes, but there are times when manual intervention is required to reset the amount of hard drive space.

It is necessary to specify the minimum and maximum amount of hard drive space while resetting as allocating too little space can make the system run out of RAM. But if the system continuously demands more virtual memory space, then it is better to add more RAM. Some OSes often recommend not increasing the virtual memory beyond 1 ½ time the amount of RAM.

Virtual memory management differs in every OS. RAM cells have a limited number of writes which may reduce the lifespan of the drive. To configure virtual memory manually:

  1. Open the ‘Control Panel’ on your computer and double-click on the ‘System’. In the system, click on the ‘Performance’ tab and select ‘Virtual Memory’.
  2. There you will see an option saying, ‘Let me specify my own virtual memory settings’. Click on it and the options below it will become active.
  3. A drop-down list beside ‘Hard disk:’ appears. Select any hard drive for which you want to configure virtual memory. Make sure that you divide the virtual memory equally.
  4. Enter the smallest amount of hard drive space in the ‘Minimum:’ box and the value in ‘Maximum:’ can be anything less than twice the physical RAM.
  5. 12 megabytes is usually the Windows default. Restart your computer to put the new settings into effect.

Virtual Memory vs Physical Memory in OS

Virtual RAMRAM
A part of RAMPhysical memory
SlowerFaster
Uses pagingUses segmentation
Indirect access to CPUDirect access to CPU
Limited by the size of RAM and computer hard driveLimited to the RAM chip size

Leave a Reply