What is Virtrual Memory?
Virtual memory is the seperation of user logical memory from physical memory.
Vitrual memory can be implemented via Demand Paging & Demand Segmentation.
Why do we need Virtual Memory?
- Code needs to be in memory to execute, but the entire code of program rarely used.
- Program no longer constrained by limits of physical memory.
- Program could be larger than physical memory
The advantages of Virtual Memory
- Only part of the program needs to be in memory for execution
- Logical address space can therefore be much larger than physical address space
- Allows address spaces to be shared by several processes
- Allows for more efficient process creation
- More programs running concurrently
- Less I/O needed to load or swap processes
Vitrual Address Space
- The virtual memory address space for each process is sparse. Enables sparse address spaces with holes left for growth, dynamically linked libraries.
- System libraries shared via mapping into vitual address space.
- Shared memory (for inter-process communication) by mapping pages read-write into virtual address space.
- Pages can be shared during fork( ), speeding process creation
Swapping:
Transfer process from Main Memory to the Backing Store (SWAP parition) and swapped back to the main memory.
What is the diiference between swapping and demand paging?
Comparison | Paging | Swapping |
---|---|---|
Basic | Paging allows the memory address space of a process to be noncontiguous. | Swapping allows multiple programs to run parallelly in the operating system. |
Flexibility | Paging is more flexible as only pages of a process are moved. | Swapping is less flexible as it moves entire process back and forth between main memory and back store. |
Multiprogramming | Paging allows more processes to reside in main memory | Compared to paging swapping allows less processes to reside in main memory. |
- The basic difference between paging and swapping is that paging avoids external fragmentation by allowing the physical address space of a process to be noncontiguous whereas, swapping allows multiprogramming.
- Paging would transfer pages of a process back and forth between main memory, and secondary memory hence paging is flexible. However swapping swaps entire process back and forth between the main and secondary memory and hence swapping is less flexible.
- Paging can allow more processes to be in main memory than the swapping.
Reference
https://techdifferences.com/difference-between-paging-and-swapping-in-os.html