Fun with zvols - Swap on a zvol
By scottdickson on Dec 01, 2006
I mentioned recently that I just spent a week in a ZFS internals TOI. Got a few ideas to play with there that I will share. Hopefully folks might have suggestions as to how to improve / test / validate some of these things.
ZVOLs as Swap
The first thing that I thought about was using ZFS as a swap device. Of course, this is right there in the zfs(1) man page as an example, but it still deserves a mention here. There has been some discussion of this on the zfs-discuss list at opensolaris.org (I just retyped that dot four times thinking it was a comma. Turns out there was crud on my laptop screen). The dump device cannot be on a zvol (at least if you want to catch a crash dump) but this still gives a lot of flexibility. With root on ZFS (coming before too long) ZFS swap makes a lot of sense and is the natural choice. We were talking in class that maybe it would be nice if there were a way to turn off ZFS' caching for the swap surface to improve performance, but that remains to be seen.
At any rate, setting up mirrored swap with ZFS is way simple! Much simpler even than with SVM, which in turn is simpler than VxVM. Here's all it takes:
bash-3.00# zpool create -f p mirror c2t10d0 c2t11d0 bash-3.00# zfs create -V 2g p/swap bash-3.00# swap -a /dev/zvol/dsk/p/swap
Pretty darn simple, if you ask me. You can make it permanent by changing the lines for swap in your /etc/vfstab (below). Notice that you use the path to the zvol in the /dev tree rather than the ZFS dataset name.
bash-3.00# cat /etc/vfstab
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
#/dev/dsk/c1t0d0s1 - - swap - no -
/dev/zvol/dsk/p/swap - - swap - no -
I would like to do some performance testing to see what kind of performance you can get with swap on a zvol. I am curious about how this will affect kernel memory usage. I am curious about the effect of things like compression on the swap volume. Thinking about that one, it doesn't make a lot of sense. I am also curious about the ability to dynamically change the size of the swap space. At first glance, changing the size of the volume does not automatically change the amount of available swap space. That makes sense. That makes sense for expanding swap space. But if you reduce the size of the volume and the kernel doesn't notice, that sounds like a it could be a problem. Maybe I should file a bug.
Suggestions for things to try and ways to measure overhead and performance for this are welcomed.