Swap memory is required when system requires more memory than it is physically available, the kernel swaps out less used pages and gives memory to the current process that needs the memory immediately. So a page of memory is copied to the pre-configured space on the hard disk. Disk speed is much slower compared to memory speed. Swapping pages give more space for current application in the memory (RAM) and make application run faster.
In some scenarios, system admin need to increase swap space. Below commands help you to expand the existing swap space.
Check if you have enough space on disk to create new partition for swap.
Create new partition using tool like fdisk:
Make the new partition as swap. Change toggle id to 82 (for swap).
Run mkswap command on the newly created swap partition:
Setting up swapspace version 1, size = 6004416 kB
Run swapon commad to enable swap space:
Verify the newly added swap space using below commands:
Add newly created swap partition to fstab file. It should look as below:
/dev/cciss/c0d0p9 swap swap defaults 0 0
Somebody was asking me how to create/remove swap partiton for lvm. Below command helps for that. Assuming swap partiton was created on lvm partition.
Follow the below steps to increase the Swap for LVM
# swapoff -v /dev/rootvg/swapvol
# lvm lvresize /dev/rootvg/swapvol -L +8G (increase from 8 GB to 16 GB)
# mkswap /dev/rootvg/swapvol
# swapon -va
Follow the below steps to delete/ remove the Swap partition for LVM
swapoff -v /dev/VolGroup00/LogVol01
Then you need to delete the swap partition entirely.
Remove the following entry from your /etc/fstab file.
/dev/VolGroup00/LogVol01 swap swap defaults 0 0