UNIX Consulting and Expertise
Golden Apple Enterprises Ltd. » Page 'Growing swap on a ZFS filesystem'

Growing swap on a ZFS filesystem

Looking for UNIX and IT expertise? Why not get in touch and see how we can help?

Recently I had to tackle a badly installed Solaris machine which hadn’t been configured with enough swap space. Luckily it had been built with a ZFS root filesystem, which made dealing with this a lot less painful.

First of all we need to get the details of our current swap setup:

bash-3.00# swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,2      16 4194288 4194288

New step is to increase the size of the ZFS ‘filesystem’ under the root pool (here called the default, rpool).

bash-3.00# zfs set volsize=4G rpool/swap

Once the filesystem size has been increased, we need to actually add it as swap. The normal swap command will do this – we just need to make sure we’re pointing it at the correct ZFS device:

bash-3.00# env NOINUSE_CHECK=1 swap -a /dev/zvol/dsk/rpool/swap $((8+4194288))

Let’s just check the status via ZFS:

bash-3.00# zfs list rpool/swap
NAME         USED  AVAIL  REFER  MOUNTPOINT
rpool/swap     4G  3.16G  2.03G  -

And finally we can see the new swap space we’ve just added:

bash-3.00# swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,2      16 4194288 4194288
/dev/zvol/dsk/rpool/swap 256,2  4194304 4194304 4194304

A simple handful of commands, and no downtime – adding extra swap space using ZFS on Solaris is pretty painless. In another post I’ll explore how to grow ZFS filesystems like /var.

Like this post? Spread the word!
delicious digg google
stumbleupon technorati Yahoo!

One comment to “Growing swap on a ZFS filesystem”

  1. Actually, if all of the swap space is completely free as in your example, you could first delete the existing swap from the system (swap -d /dev/zvol/dsk/rpool/swap), then increase the vol size as you show, then add it back (swap -a /dev/zvol/dsk/rpool/swap 16). This even works if you have active (running) zones on the system.
    However, if you’re at the point of needing to add swap, the likelihood of it being unused is practically nil, so it’s important to know how to calculate and specify the swaplow value for the volume whose size has just been increased.
    Thanks for showing this.

Top of page / Subscribe to new Entries (RSS)