The operating system uses virtual memory to manage the memory requirements of its processes by combining physical memory with secondary memory ( swap space) on disk. The swap area is usually located on a local disk drive. Diskless systems use a page server to maintain their swap areas on its local disk.
The amount of swap space is usually configured to be larger than physical memory; the sum of physical memory and swap space defines the total virtual memory that is available to the system.
Having swap space on disk means that the CPU's access to it is very much slower than to physical memory. Conventionally, the swap area uses an entire division on a hard disk. It is also possible to configure a regular file from within a filesystem for use as swap. Although this is intended for use by diskless workstations, a server can also increase its swap area in this way.
The swap area is used as an additional memory resource for processes that are too large for the available physical user memory. In this way, it is possible to run a process whose entire executable image will not fit into physical memory. However, a process does not have to be completely loaded into physical memory to run, and in most cases is unlikely to be completely loaded anyway.
The virtual address space of a process is divided into separate areas known as regions that it uses to hold its text, data, and stack pages. When a program is loaded, its data region consists of data pages that were initialized when the program was compiled. If the program creates uninitialized data (often known as bss for historical reasons) the kernel adds more pages of memory to the process' data region.
If the operating system is running low on physical memory, it can start to write pages of physical memory belonging to processes out to the swap area. See ``Paging'' and ``Swapping'' for more details.
``How the virtual memory of a process relates to physical memory and disk'' illustrates how a process' virtual memory might correspond to what exists in physical memory, on swap, and in the filesystem. The u-area of a process consists of two 4KB pages (displayed here as U and U) of virtual memory that contain information about the process needed by the system when the process is running. In this example, these pages are shown existing in physical memory. The data pages, D and D, are shown as being paged out to the swap area on disk. The text page, T, has also been paged out but it is not written to the swap area as it exists in the filesystem. Those pages which have not yet been accessed by the process (D, T, and T) do not occupy any resources in physical memory or in the swap area.
How the virtual memory of a process relates to physical memory and disk