Virtual Memory in Operating System
Virtual Memory in OS
The Primary Memory (such as RAM) is expensive and limited in the system, however, the secondary memory is cheaper and large and can be extended easily.
Virtual memory concept offers unique solution for apparent primary memory expansion, in this we secondary memory can be accessed as if it were the part of the main memory. One of the techniques to extend this is to transfer the inactive RAM storage to secondary storage temporarily.
It essentially with the help of Operating System, and the software and hardware installed on the system, helps to access more memory than what actually is installed on the system, by transferring data from the RAM to the to disk.
- Primary Memory – RAM
- The entry application or program in the system first loads into the RAM (Random Access Memory), this makes the application faster to load and access, than the secondary memory and is readily available
- Secondary Memory – Hard Disk and Storage devices
In what Form Virtual Memory is stored?
The memory is stored in form of units that we call as pages in Operating System, these are atomic units where large programs can be stored.
For a program there may a large set of storage in physical addresses. All of those are not required to be loaded as only certain programs are used, for an application.
Imagine playing a game like FIFA on your desktop. The game itself maybe stored in hard disk (secondary device), but while playing all the installed space would not be loaded into RAM. But only certain programs that are required for the application (Game) to run .
Benefits of having Virtual Memory
- Large programs can be written, as virtual space available is huge compared to physical memory.
- Less I/O required, leads to faster and easy swapping of processes.
- More physical memory available, as programs are stored on virtual memory, so they occupy very less space on actual physical memory.
How it works?
The Addressing scheme that is provided by the system and total available space in the secondary storage device is what limits the size of the virtual storage, not the size of Primary storage as RAM. If the storage is unlimited (as in the case of cloud systems), some applications can behave as if they have unlimited primary memory available to them.
We use both of these of the system –
Both work together to map virtual Addresses to physical addresses, with the help of MMU, i.e. Memory Management Units.
- What system or uses sees are essentially logical addresses not the actual physical address. These logical addresses may be translated dynamically at the load, execute or compile time. Depending on the requirement or definition of the system.
- In actual scenario, the processes and resources stored in the memory are not continuous, however are broken down and are scattered and stored at various places in the physical memory. With the help of dynamic run-time address translation and page or segment table we can easily do this. That even though they actually may be scatterly stored but to the user it looks like they are stored contiguously.
Virtual memory concept is also swiftly enabled by demand paging. Read more about Demand Paging here.
- Memory Management Introduction
- Partition Allocation Method
- Buddy- System Allocator
- Types of Paging
- Mapping Virtual address to Physical Address.
- Virtual Memory
- Demand Paging
- Implementation of Demand paging and page fault
- Page Replacement Algorithms
- Belady’s Anomaly
- Static vs Dynamic Loading
- Static vs Dynamic Linking
- Translational Look Aside Buffer
- Process Address Space
- Difference between Segmentation and Paging