Virtual Memory

 Virtual memory provides a way of running more processes than can physically fit within a computer's physical address space.

 Each process that is a candidate for running on a processor is allocated it's own virtual memory area which defines the logical set of addresses that a process can access to carry out it's required task. As this total virtual memory area  is very large (typically constrained by the number of address bits the processor has and the maximum number of processes it supports), each process can be allocated a large logical address space (typically 3Gb) in which to operate.

 It is the job of a virtual memory manager to ensure that active processes and the areas they wish to access are remapped to physical memory as required. This is achieved by a method of swapping or paging the required sections (pages) into and out of physical memory as required.   Swapping involves replacing a complete process with another in memory whereas paging involves removal of a 'page' (typically 2-4kbytes) of the process's mapped memory and replacing it with a page from another process.  As this may be a computer intensive and time consuming task, care is taken to minimise the overhead that it has. This is done by usage of a number of algorithms designed to take advantage of the common locality of related sections of code and also  only carrying out some operations such as memory duplication or reading when absolutely required ( techniques known as copy on write, lazy paging and demand paging).

The virtual memory owned by a process may contain code and data from many sources. Executable code may be shared between processes in the form of shared libraries, as these areas are read-only there is little chance of them becoming corrupted. Processes can allocate and link virtual memory to use during their processing,

 Some of the memory management techniques used by many operating systems, including Linux and Windows NT include :

Page based protection mechanism Each virtual page has a set of flags which determine the types of access allowed in user mode or kernel mode.
Demand paging / lazy reading the virtual memory of a process is brought into physical memory only when a process attempts to use it.
Kernel and User modes of operation Unrestricted access to process's memory in kernel mode but access only to it's own memory for a process in user mode.
Mapped files Memory is extended by allowing disk files to be used as a staging area for pages swapped out of physical memory.
Copy on write memory When two processes require access to a common area of code the virtual memory manager does not copy the section immediately as if only read access is required the section may be used safely by both processes. Only when a write is requested does the copy take place.
Shared memory An area of memory may be mapped into the address space of more than one process by the calling of privileged operations.
Memory Locking To ensure a critical page can never be swapped out of memory it may be locked in, the vritual memory manager will not then remove it.
For Windows NT : Object based Memory Protection The NT security reference checks access permissions for any process attempting to open a handle to that memory section or map a view of it.