Rarely we may pushed in a such a situation to add the additional swap space while system is in production.Sometimes due to applications ,system may in to memory bottle neck.As a workaround,we will add additional swap space to avoid the system hung/panic.Here i would like to demonstrate couple of ways of adding swap.
1.Adding the physical disk directly as swap.
2.If we don;t have free disk, how to create swap space in ZFS and activate.
1.Adding the physical disk directly as swap.
2.If we don;t have free disk, how to create swap space in ZFS and activate.
Using dedicated physical disk:
To check current swap devices:
bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568
Here the free disk is c1t2d0 and adding as swap
bash-3.00# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
0. c1t0d0
/pci@0,0/pci15ad,1976@10/sd@0,0
1. c1t1d0
/pci@0,0/pci15ad,1976@10/sd@1,0
2. c1t2d0
/pci@0,0/pci15ad,1976@10/sd@2,0
Specify disk (enter its number):
bash-3.00# swap -a /dev/dsk/c1t2d0s2
To check current swap devices:
bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568
/dev/dsk/c1t2d0s2 30,194 8 2091000 2091000
To add entry in Vfstab:
# vi /etc/vfstab
/dev/zvol/dsk/rpool/swap - - swap - no -
/dev/dsk/c1t2d0s2 - - swap - no -
To remove the added disk from swap space use the following command:
bash-3.00# swap -d /dev/dsk/c1t2d0s2
Note:You cannot deactivate when the swap in use.
Always recommend to remove the additional swap from vfstab and reboot the server.
How can we add new swap to system using zfs dataset?
Create a emulated zfs dataset for swap:
bash-3.00# zfs create -V 900M rpool/swap1
Listing zfs filesystems:
bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool 4.59G 3.22G 34.5K /rpool
rpool/ROOT 3.58G 3.22G 21K legacy
rpool/ROOT/new_stage3 126K 3.22G 3.58G /.alt.new_stage3
rpool/ROOT/sol_stage2 3.58G 3.22G 3.57G /
rpool/ROOT/sol_stage2@new_stage3 1.53M - 3.58G -
rpool/dump 512M 3.22G 512M -
rpool/swap 528M 3.74G 16K -
swappool 929M 47.3M 21K /swappool
rpool/swap1 929M 929M 16K -
To activate New swap:
bash-3.00# swap -a /dev/zvol/dsk/rpool/swap1
bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568
/dev/zvol/dsk/swappool/swap1 181,3 8 1843192 1843192
After activating the swap,if you want to make it permanent then make sure you have added entry in vfstab for zfs swap.The same way you can deactivate the swap by removing it vfstab and rebooting the server.
Thank you for reading this article.Please leave a comment if you have any doubt ,i will get back to you as soon as possible.
santosh b says
how to increase the swapvol in vxvm