Virtual Memory
Virtual memory is a memory management technique that uses a combination of hardware and software to allow a computer to run more programs and handle larger applications than its physical RAM would normally allow. It achieves this by using a portion of the hard drive as an extension of RAM, swapping data between the RAM and the hard disk as needed. This process is slower than using RAM directly but makes more memory available for running applications.
How it works
Address translation: When a program runs, it uses virtual addresses. The operating system, with the help of the Memory Management Unit (MMU), translates these virtual addresses into physical addresses in RAM.
Paging: Memory is divided into chunks called "pages". The MMU uses a page table to keep track of which pages are in RAM and which are on the hard disk.
Page fault: If the CPU needs a page that is not in RAM, a "page fault" occurs. The operating system handles this by loading the required page from the hard disk into RAM and updating the page table.
Swapping: To make space for the new page, the OS may move an unused page from RAM to the hard disk. This process is called swapping.