Pages

1 August 2010

Swap basics for ubuntu users....


What is swap?
Swap space is the area on a hard disk which is part of the Virtual
Memory of your machine, which is a combination of accessible physical
memory (RAM) and the swap space. Swap space temporarily holds memory
pages that are inactive.

How much swap do you need?
it's highly recommended that the swap space should be equal to the
amount of physical memory (RAM). Also, it's recommended that the swap
space is twice the amount of physical memory (RAM) depending upon the
amount of hard disk space available for the system.

Creating swap
At the time of installing ubuntu we can specify how much swap we will use. But it is also possible to add more swap without partitioning any of the HD space. We can create a swap file and allow the os to use that as virtual memory. This is possible because Linux treats everything as a file (like - directory). Now, lets create a swap file and tell our UBUNTU to use that-

First of all we will create a 512MB .swap file

Code:
sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512

Formatting that file to create a swapping device

Code:
sudo mkswap /mnt/512Mb.swap

Adding the swap to the running system:

Code:
sudo swapon /mnt/512Mb.swap

The additional swap is now available and can be seen by

Code:
cat /proc/meminfo

To make the change permanent -

Code:
gksudo gedit /etc/fstab

and add this line at the end of the file

Code:
/mnt/512Mb.swap  none  swap  sw  0 0   

1 comment: