Ubuntu Linux based operating system’s virtual memory is known as the swap. Swap describes the transactions of moving memory pages between physical RAM and the hard Disk, and the region of a disk the pages are stored on. Ubuntu Commonly uses a whole partition of a hard disk for swapping. That partition is called swap space. Swap space holds the virtual memory of the system. Swapping is a method that allows a computer to execute programs and process data files larger than it own physical memory.
Swap space is located on hard drives, which have a slower access time than physical memory. Swap space can be in the same partition of the hard disk, as a separate partition dedicated to it on the same disk, a dedicated partition on a second hard disk or even a combination of swap partition and swap file. Ubuntu has two forms of swap spaces, the swap partition and the swap file. The swap partition is an independent section of the hard disk used solely for swapping; no other files can reside there. The swap file is a special file in the file system that resides amongst your system and data files. It is recommended to allocate at least 2x capacity of the actual physical memory. Swap space is also used for system hibernation.
The advantage of using swaps partitions, it can be used by two or more Linux based installations on the same PC. Example - dual boot or triple boot with a Windows based operating system. Also a Swap partition comes in handy when disk is full where the swap file could create incompletely. Swap partitions are faster than swap files, and they are commonly used in Linux systems.
As well as the swap partition, Linux also supports a swap file that you can create, prepare, and mount in a fashion similar to that of a swap partition. The advantage of swap files is that you don't need to find an empty partition or repartition a disk to add additional swap space (Miller, R 2007, p.154). On the other hand swap files are good if you need to change the size of the swap memory regularly as it is easier to resize the swap file through whole partition.
In Ubuntu, the swap space is used when all the physical memory on your computer is reserved by running processes yet an additional demand for memory resources exist. In such scenarios where the physical memory is at full capacity, the kernel allocates inactive pages in the physical memory to the swap space. (Kenny, J, p. 98) This creates additional space in the physical memory to meet the additional demand. When the pages that are in the swap space are needed by the physical memory again, they are swapped backed into the physical memory. These operations are called swapping out and swapping in, respectively.
Ubuntu use this technique to loading virtual pages into physical memory as they are accessed is known as demand paging. Ubuntu uses demand paging to load executable images into a process's virtual memory. Whenever a command is executed, the file containing it is opened and its contents are mapped into the process's virtual memory. This is done by modifying the data structures describing this process' memory map and is known as memory mapping.(Saheed. M, 2008) However, only the first part of the image is actually brought into physical memory. The rest of the image is left on disk. As the image executes, it generates page faults and Linux uses the process's memory map in order to determine which parts of the image to bring into memory for execution. ( L, Friedrich 2008)