Monday, July 21, 2008

ATAD #2 - linux swap space

Swap space is used when a system requires memory greater the physical memory (RAM) available. Physical memory is divided into chunks of memory called pages. When the amount of RAM is full, a page of memory which is relatively less used is moved to a preconfigured swap space on the hard drive (HDD).

Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files. The combined sizes of the physical memory and the swap space constitute the amount of virtual memory available.

RedHat recommends swap size be equal to 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB.

So, if:

M = Amount of RAM in GB, and S = Amount of swap in GB, then

If M < 2
then
S = M * 2
else
S = M + 2
fi

However, if you think you will be upgrading the RAM sometime in the near future, consider the total amount of RAM you would be having after your upgrade and decide on the swap space during install time. swap space can also be altered post installation by

1. creating a new swap partition
# lvm lvcreate -n -L (size_in_mb)M


2. creating a new swap file
# dd if=/dev/zero of=/swapfile bs=1024 count=(size)

3. extend swap on an existing logical volume (recommended)
# lvm lvresize (lvol) -L +(size_in_mb)M

Remember to boot the system in rescue mode before altering the swap space as the swap space can not be in used when being modified.
Further reading: swapoff, mkswap, swapon

__tipped__

No comments: