Monday, July 9, 2012

Expanding swap

Things change or underestimation may happen.
To increase the swap space 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  8388592 8388592
     
  • If not in use, simply resize the ZFS volume:
     
    # zfs set volsize=30G rpool/swap
     
  • Or, if in use, create another swap device and add it to the VMM:
    (don't forget to adjust /etc/vfstab for persistence upon next reboots).
     
    # zfs create -V 26G -b $(pagesize) rpool/swap-x1
    # zfs set primarycache=metadata rpool/swap-x1

    # swap -a /dev/zvol/dsk/rpool/swap-x1

     
  • Verify the new disk-based swap info:
     
    # swap -l
    swapfile                   dev  swaplo   blocks     free
    /dev/zvol/dsk/rpool/swap 256,1      16 62914544 62914544
     
     
Don't forget to adjust changes accordingly in /etc/vfstab.