Main memory is central to the operation of a modern computer system. Main memory is a large array of bytes, each with its own address. The CPU reads instructions from main memory and reads/writes data to it. The Operating System's memory manager is responsible for allocating space to processes and ensuring they do not interfere with one another.
Early operating systems allocated memory contiguously. This means that a process was given a single, continuous block of memory.
The Problem: Fragmentation
Paging is a memory-management scheme that eliminates the need for contiguous allocation of physical memory. This scheme permits the physical address space of a process to be noncontiguous.
Advantage of Paging: Paging avoids external fragmentation completely and the need for compaction. Any free frame can be allocated to a process that needs it.
Virtual memory is a technique that allows the execution of processes that are not completely in memory. One major advantage of this scheme is that programs can be larger than physical memory.
Virtual memory is commonly implemented by Demand Paging. In demand paging, a page is not loaded into main memory until it is needed. When a process tries to access a page that was not brought into memory, a Page Fault occurs. The OS then traps the interrupt, loads the required page from disk into a free frame in memory, updates the page table, and restarts the instruction.