Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Disks and Volumes

Adding Swap with Solaris 11 ZFS

Submitted by on October 22, 2014 – 4:24 pm

With the swap partition residing on a ZFS filesystem, you have an easy way of adding swap on the fly. Reducing swap is not quite so simple, but we’l talk about that later. To check the current swap you can use “top” or “swap -l”:

root@solaris11:~# top -b 1
last pid: 48927;  load avg:  1.08,  1.06,  1.05;  up 7+04:07:48        16:01:28
154 processes: 144 sleeping, 8 zombie, 2 on cpu
CPU states: 99.2% idle,  0.5% user,  0.3% kernel,  0.0% iowait,  0.0% swap
Kernel: 1887 ctxsw, 2 trap, 2192 intr, 502232 syscall
Memory: 128G phys mem, 102G free mem, 4G total swap, 4G free swap

While “top” shows overall amount of swap, the “swap -l” will also show swapfile information:
root@solaris11:~# swap -l
swapfile             dev    swaplo   blocks     free
/dev/zvol/dsk/rpool/swap 287,2        16  8388592  8360496

You can also use the “zfs” command to view the size of the ZFS swap volume:
root@solaris11:~# zfs get volsize rpool/swap
NAME        PROPERTY  VALUE  SOURCE
rpool/swap  volsize   84G    local

Now that we’re done looking at things, let’s make some changes. With ZFS, you have a couple of options of adding swap space: grow an existing swap volume or add a new one. What’s the difference? Well, if you grow an existing volume, you won’t be able to downsize it without adding temporary swap area, disabling the original volume, downsizing it, adding it back, disabling the temporary volume and removing it. This is not difficult and having one swap volume makes for a neater appearance, but it requires some typing.

Here’s how you add space to an existing ZFS swap volume that is currently 4GB and you want to make it 8GB:

zfs set volsize=8g rpool/swap

You can keep doing this many times to grow swap space. The only limiting factor is the available disk space in whatever ZFS pool you’re using for swap. In my example I increased swap incrementally to 84GB. Here’s what “swap -l” shows:
root@solaris11:~# swap -l
swapfile             dev    swaplo   blocks     free
/dev/zvol/dsk/rpool/swap 287,2        16  8388592  8360496
/dev/zvol/dsk/rpool/swap 287,2   8388624  8388592  8388592
/dev/zvol/dsk/rpool/swap 287,2  16777232 16777200 16777200
/dev/zvol/dsk/rpool/swap 287,2  33554448 33554416 33554416
/dev/zvol/dsk/rpool/swap 287,2  67108880 67108848 67108848
/dev/zvol/dsk/rpool/swap 287,2  134217744 41943024 41943024

And “zfs” shows the overall size of the swap partition:
root@solaris11:~# zfs get volsize rpool/swap
NAME        PROPERTY  VALUE  SOURCE
rpool/swap  volsize   84G    local

As I mentioned before, the other option is to add a new swap volume:
# zfs create -V 2G rpool/swap2
# swap -a /dev/zvol/dsk/rpool/swap2
# swap -l
swapfile                  dev  swaplo   blocks   free
/dev/zvol/dsk/rpool/swap  256,1      16 1058800 1058800
/dev/zvol/dsk/rpool/swap2 256,3      16 4194288 4194288

So, here you go: the awesomeness of managing swap with ZFS.

Print Friendly, PDF & Email

Leave a Reply