What is Virtual Memory?
Definition/ Meaning – Virtual memory is storage container of operating system, and it allows to hardware and software of computer system to support for physical memory on transferring time of data from main memory to secondary memory such as hard disk.
Virtual Memory Diagram
Due to move virtual memory into physical memory, operating system splits own memory into different blocks with fixed number of addresses, and those blocks are known as “Page files or Swap files”. All pages are reserved in the hard disk, and OS moves it from hard disk to primary memory, when they are needed, and finally virtual addresses are translated into real addresses.
Read More – Operating System Tutorial
Need of Virtual Memory
- Main objective of needing is virtual memory is to increase the storage space of running memory, without adding any external memory such as RAM (Random Access Memory).
- If, any time computer’s physical memory is totally occupied for other programs, but same time it needs to some extra memory then requests are forwarded to hard disk for swapping files like as virtual memory.
- If, any time computer requires the extra more main memory (RAM), then it try to install in the machine, and it works as small area of disk for fulfill system needs.
Types of Virtual Memory
Read More – Cache Memory | Locality of Reference in OS
Entire memory operations of computer are managed by the memory management unit (MMU), and it is enabled with handling Virtual Memory. Memory management unit is embedded in the CPU (Center Processing Unit).
Virtual Memory is managed with two techniques such as Paging and Segmentation.
In this way, memory is spited into different small blocks with near about 4 KB in size, and these blocks are known as Paging Files.
The paging is enabled with using the page table, which is help out to translate the virtual addresses for using operating system and other running other applications, and they use those addresses into physical addresses which are used by MMU. When, operating system and other currently using applications are not able to find appropriate address, which are located into RAM, then memory management unit try to response for missing memory reference along page fault. But if Page is occurred into RAM, then its virtual address exists into page table.
Main objective of using the Segmentation is to handle the virtual memory. In this process, virtual memory is divided into various different segments. But these segments are not used into memory because those segments are transferred in the virtual memory on hard drive. Segment table keeps all records of entire information of whole segments.
Sometime virtual memory system tries to merge the paging and segmentation, and after getting combinations of then memory is divided into pages or frames.
How Virtual Memory Works
Read More – Page Fault in Operating System
Now these days, virtual memory is very common word. Virtual memory is very helpful, when anyone page is needed to load into primary memory for its execution, but it has not enough memory for those pages.
Then, virtual memory helps to short out that issue such as – lack of memory.
Now, here we will explain the working of virtual memory with suitable example. Like as –
Example of Virtual Memory
- Suppose, if operating system requires the 200 MB memory’s space to manage the all programs, which are working in currently.
- But, at present having only 100 MB physical memory space that is stored on the Random Access Memory (RAM).
- Then, Operating system will try to create the 200 MB of virtual memory, and VMM (Virtual Memory Manager) helps to handle that memory.
- VMM has to work to arise the new files on the hard disk, which are need (100 MB) such as (200 MB-100 MB) = 100 MB.
- VMM has responsible to deal in real memory, which is only 100 MB.
Advantages of Virtual Memory
Read More – Page Replacement Algorithms in OS
There are several of pros/benefits of enabling virtual memory, such as –
- Assigning the memory is very cheap and effective way.
- Page mapping is done good manner.
- Virtual memory helps to trash the external fragmentation.
- While using of huge virtual space, vast programs can be implemented.
- Virtual memory allows too fast and easy processes.
- Due to store of programs in the virtual memory, not need more memory space.
- All data (page frames) can be distributed on the entire physical memory.
- Allowing the very effective swapping
- It allows the multi programming environment.
- It is capable to operate multiple applications concurrently.
- It allows the flexibility because their large programs can be fitted into small size programs.
- It allows sharing common data between their memories.
- All processes can get large size to physical memory.
- It allows reading all data from hard disk, when to need.
- It allows replacing any code in physical memory without needing relocation.
- It helps to improve the performance of CPU.
- It has no any boundation for all degree of multi programming.
- It allows huge virtual address space to physical memory.
- It allows allotting the specific segment of program for execution of particular program, so it helps to enhance the speed of execution time.
- It allows the protection between two programs.
Disadvantages of Virtual Memory
There are some limitations of virtual memory such as –
- While using of virtual memory, all application’s speed are getting slow.
- It consumes more hard disk space.
- Lack of system stability
- It is not capable to deliver the equal performance like as RAM.
- Due to virtual memory, system gets degrade.
- It consumes more time between switching the applications.
- Increase the software complexity and hardware cost.
- Required the best hardware support
- Kernel developers require a profound understanding of the hardware, if they are using Virtual memory.
Demand Paging In OS (Operating System)
Read More – Operating System Tutorial
Demand paging is a process of swapping in the Virtual Memory system. In this process, all data is not moved from hard drive to main memory because while using this demand paging, when some programs are getting demand then data will be transferred. But, if required data is already existed into memory then not need to copy of data. The demand paging system is done with swapping from auxiliary storage to primary memory, so it is known as “Lazy Evaluation”.
Some Page Replacement Algorithms are used in the demand paging concept to replace different pages – such as FIFO, LIFO, Optimal Algorithm, LRU Page, and Random Replacement Page Replacement Algorithms.
Demand Paging Working
Demand paging system is totally depend on the page table implementation because page table helps to maps logical memory to physical memory. Bitwise operators are implemented in the page table to indication that pages are ok or not (valid or invalid). All valid pages are existed into primary memory, and other side invalid pages are existed into secondary memory.
Now all process go ahead to access all pages, then some things will be happened. Such as –
- Attempt to currently access page.
- If page is ok (Valid), then all processing instructions work as normal.
- If, anyone page is found as invalid, then page- fault issue is arise.
- Now memory reference is determined that valid reference is existed on the auxiliary memory or not. If not existed, then process is terminated, otherwise needed pages are paged in.
- Now disk operations are implemented to fetch the required page into primary memory.
Pure Demand Paging
In this section, we will discuss about difference between demand paging and pure demand paging.
- In the initially stage, if anyone page is not loaded into primary memory then page faults are occurred, and then paged are loaded with on demanding of the process. This process is known as “Pure Demand Paging”.
- Pure demand paging is not able to load single page into main memory, otherwise it will be fired the Page-Fault.
- In pure demand paging, when process will be started up then all memory is swapped from auxiliary memory to primary memory.
Demand Segmentation in OS
Segment table keeps all information related to demand segmentation such as valid bit because on the behalf of valid bit can be specified that segment has existed in the physical memory or not. If, anytime physical memory is not capable to store their segments then to get segment fault, and then it try to fetch required segments from physical memory. Similar to page fault.
Demand segmentation helps to decrease the number of page faults in the paging system.