Virtual memory or paging refers to a technique in which not all of the memory corresponding to a given virtual address space has to be 'resident', i.e. in actual physical main memory, while the computation which is using that address space is running. When a reference it made to a memory location which is not resident, the computation is stopped while the missing memory is made resident; once it is resident, the computation is allowed to proceed.
This is usually done by dividing the address space into pages, identically-sized blocks of address space; similarly, the physical main memory is also divided into similarly-sized 'page frames'. A selected subset of the pages of a given computation's address space are assigned to page frames at any given time.
The advantages of virtual memory are several-fold:
- It allows a computation to use more memory than the amount of actual physical memory on the machine; this oftem simplifies the coding, over having to work within the confines of a more limited amount of memory.
- The obverse face of the above is that instead of having to explicitly manage which data is kept in main memory, and which is in secondary storage (i.e. disk), the operating system automatically performs this work on the user's behalf.
- The use of fixed-size pages, and the usual practise of allowing any page of the address space to be allocated to any page frame, means there is no 'breakage' of main memory, and no need to move data around in main memory to coalesce free space (which was usually necessary on systems which did not use virtual memory).
There is no requirement that a virtual memory system have only two levels of storage; some systems (e.g. Multics used a three-level virtual memory system, with core, drum and disk memories; later modified to semi-conductor main memory, slower bulk core, and disk memory.