Create SWAP on ZFS ZVOL
ZFS with it’s default options is not great for SWAP usage.
If you run “Root on ZFS” you want to create a ZVOL with the right options.
This means limiting arc to metadata, disabling l2arc, forcing sync writes, setting logbias to throughput and disabling autosnapshots.
Adjust 8G to the swap size you want. Adjust rpool if your pool has a different name.
zfs create -V 8G -b $(getconf PAGESIZE) -o compression=zle \
-o primarycache=metadata -o secondarycache=none
-o sync=always -o logbias=throughput \
-o com.sun:auto-snapshot=false rpool/swap
Initiate SWAP on the ZVOL.
mkswap -f /dev/zvol/rpool/swap
Set SWAP to enable at boot.
cat << 'EOF' >> /etc/fstab
/dev/zvol/rpool/swap none swap defaults 0 0
EOF
Enable SWAP.
swapon -av
Comments