Virtual memory is a memory management technique that gives processes the illusion of having more memory than is physically available. It allows the OS to run programs that are larger than the available RAM. This is achieved by using a combination of physical memory (RAM) and secondary storage (e.g., hard disk).
How Virtual Memory Maximises Resource Utilisation
Virtual memory allows multiple processes to share the same physical memory. This reduces the overall memory footprint of the system. Furthermore, it enables processes to access memory locations that are not currently in RAM, storing them on disk. This increases the effective memory available to each process.
Page Tables
A page table is a data structure used by the OS to map virtual addresses (used by the process) to physical addresses (in RAM). Each process has its own page table. The page table contains entries that indicate whether a page is in RAM, on disk, or invalid. If a page is on disk, a page fault occurs, and the OS retrieves the page from disk and loads it into RAM.
Swapping
Swapping is the process of moving pages between RAM and disk. When RAM is full, the OS selects pages to be swapped out to disk, making space for new pages. The selection of pages to swap out is based on various algorithms (e.g., Least Recently Used - LRU). Swapping can significantly impact performance due to the slow access time of disk compared to RAM. However, it allows the system to run more processes than would otherwise be possible.
Table: Page Table Entry
Page Number | Present in RAM? (Yes/No) | Physical Frame Number |
Trade-offs: While virtual memory increases resource utilisation by allowing larger processes and enabling multitasking, swapping can lead to performance degradation if excessive swapping occurs (thrashing). The OS must carefully manage the swapping process to minimise this impact.