Monday, July 9, 2012

Shrinking swap

Things change or an overestimation may happen.
To reduce the swap space portion backed by disk:
 
Verify that disk-based swap is not in use (blocks == free):
  
# swap -l
swapfile                   dev  swaplo   blocks     free
/dev/zvol/dsk/rpool/swap 256,1      16 62914544 62914544
 
Remove the swap device from the VMM:
  
# swap -d  /dev/zvol/dsk/rpool/swap
 
Confirm the old device is gone:
  
# swap -l
No swap devices configured
 
Reduce the size or create a smaller ZFS volume for the new swap device:
  
# zfs destroy rpool/swap
# zfs create -V 4G -b $(pagesize) rpool/swap

# zfs set primarycache=metadata rpool/swap
 
Add the swap device to the VMM:
  
# swap -a /dev/zvol/dsk/rpool/swap
 
Verify the new disk-based swap info:
  
# swap -l
swapfile                   dev  swaplo   blocks    free
/dev/zvol/dsk/rpool/swap 256,1      16  8388592 8388592  

Note that we may have to invert the order of operations.
That is, begin by adding a new (smaller) device and then remove the old (larger) device.
In any case, don't forget to adjust changes accordingly in /etc/vfstab.