Home »
Operating System
Physical and Virtual Memory in Operating System
In this tutorial, we will learn about the physical and virtual memory in Operating System.
By Prerana Jain Last updated : May 07, 2023
What is Physical Memory?
Physical memory is referred to the RAM (Random Access Memory) of the system which is attached to the motherboard. Primary memory is the only storage type which is directly addressable to the CPU. Primary memory holds the instructions of the program to execute. When the computer requires memory usage for loading an application program or like opening a document so RAM is the first memory which is used. Physical memory is the linear addressable memory and the memory addresses increase in a linear fashion and in this each byte is directly addressable. Physical memory allocates processor information in first in last out process. Physical memory is the main memory of the system. Any user program which is going to be executed should reside in this.
A process should always in the main memory for the execution. In the main memory, a process can be swapped temporarily out of the memory when it is not in use and brought back into the memory for continue execution. The main memory is allocated for both the operating system and for the user program. So we allocate main memory in the most efficient way possible. The main memory is mainly divided into two partitions one for the operating system and for user processes. The user area of memory may be contiguous or non-contiguous in nature. In the contiguous memory allocation, each process should remain in the single section of main memory. In the main memory, the efficient approach is to divide it into the fixed size block and each block may contain only one memory.
What is Virtual Memory?
When there is a layer of abstraction over the physical memory this is called virtual memory. Using secondary memory as physical memory is virtual memory. The concept of virtual memory is based on the non-contiguous memory allocation of memory. It offers many benefits like the ability to use physical memory as a large cache and the ability to maintain separate address spaces. It makes the physical memory appear limitless from the programmer's view. When the RAM(main memory) is filled the virtual memory is used. Virtual memory is comparatively slower than the physical memory and it can decrease the performance of the CPU. Virtual memory uses the concept of paging in which the process is divided into the equal size of pages and these pages are loaded into the main memory for the execution. When we want to increase the CPU utilization we use the concept of virtual memory. In this system, the operating system gives an illusion to the user. The user thinks that they can write a very big program and its entire process is in the RAM and all the space allocated to the user is contiguous. But the reality is only a small portion of the user program is in the main memory which may or may not be contiguous while the remaining program is in secondary storage.
Virtual memory provides benefits to the system and the degree of multiprogramming is maintained. Virtual memory is a type of technology that allows the execution of the process that may not be completely in memory. All the decision like which section to bring in, where to place them, when to bring them is made by the operating system. Virtual memory allows files and memory to be shared by several different processes through page sharing. The details of virtual memory management are generally transparent to programmers. Programmers are practically relieved of the burden of trying to fit a program into limited memory. Moreover, the same program may run without reprogramming or recompilation on a system with significantly different capabilities of installed memory.