Virtual Memory in Ubuntu 8.04 LTS Desktop Edition
Swap Partition
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.
Swap file
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.
Swap-In and Swap-Out
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.
Available From: http://www.bytetrap.com/blog/2008/06/02/swap_space.png
Demand Paging
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)