HOWTO use a zvol as a swap device - atomjack/zfs GitHub Wiki
Current ZoL releases support swapping to a zvol.
# zfs create -V 4G -b $(getconf PAGESIZE) \
-o sync=always -o primarycache=metadata \
-o com.sun:auto-snapshot=false \
rpool/swap
You can adjust the size (the 4G part) to your liking.
# mkswap -f /dev/zvol/rpool/swap
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=...
# /etc/fstab: static file system information.
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/zvol/rpool/swap none swap defaults 0 0
Remember: Always use long /dev/zvol
aliases in configuration files. Never use a short /dev/zdX
device name.
# swapon --all --verbose
swapon on /dev/zd0
swapon: /dev/zd0: found swap signature: version 1: page-size 4, same byte order
swapon: /dev/zd0: pagesize=4096, swapsize=4294967296, devsize=4294967296