root@PVE1:~# swapon /swapfile
swapon: /swapfile: skipping - it appears to have holes.
zpool list rpool
zfs create -V 8G -b $(getconf PAGESIZE) -o logbias=throughput -o sync=always -o primarycache=metadata -o com.sun:auto-snapshot=false rpool/swap
mkswap -f /dev/zvol/rpool/swap
swapon /dev/zvol/rpool/swap
swapon --show
.echo '/dev/zvol/rpool/swap none swap discard 0 0' >> /etc/fstab
Therefore, use swap on ZFS at your own risk. Based on my personal experience, I've never filled up 8GB of swap, so this isn't a big risk to me. However in a production environment I could see this being a huge issue.Swapping onto a ZFS zvol is possible, but is not a good idea, because of an open bug that can cause your machine to deadlock when low on space.
Swap space is used when the machine is low on memory and trying to free some up by swapping out less-frequently used data.
When ZFS processes writes to a zvol, it can need to allocate new memory inside the kernel to handle updates to various ZFS data structures. If the machine is low on space already, it might need to swap something out to make this space available, but this causes an infinite loop.
So, instead of swapping to ZFS, just allow a small additional partition for swap space. Or for many situations you can just not have swap, and rely on other data being paged out to the filesystem to free up memory.
Can you explain how to create the swap space using the unallocated space? I used 2 240gb ssds to create a raid 1 during install but only allocated 64gb for the host. How do I allocate the rest of this space? The GUI doesn't appear to provide any solutionsOne alternative is to set the hdsize parameter in the installer (needs a complete reinstall though) - to something smaller than the whole disk size (say 8 GB less) - then you have 8 GB of unpartitioned space in the end of the disk, which you can create a swap-partition on
I personally am running quite happily without swap - but of course YMMV
Jup, that only works using the CLI. First you create a new partition (for example usingCan you explain how to create the swap space using the unallocated space? I used 2 240gb ssds to create a raid 1 during install but only allocated 64gb for the host. How do I allocate the rest of this space? The GUI doesn't appear to provide any solutions
fdisk /dev/yourDisk
). Then you can create a swap space on it (for example mkswap /dev/yourDiskYourPartition
). Then you find out the UUID of that swap partition using the command ls -l /dev/disk/by-uuid
. And edit your fstab (nano /etc/fstab
) adding a new line there like UUID=YourSwapPartitionsUUID none swap sw 0 0
. If you don't want to reboot right now you can also run additionally swapon -U YourSwapPartitionsUUID
.Thanks, the part that is confusing me is whether this partition will be mirrored as well or if it only resides on the free space of one disk?Jup, that only works using the CLI. First you create a new partition (for example usingfdisk /dev/yourDisk
). Then you can create a swap space on it (for examplemkswap /dev/yourDiskYourPartition
). Then you find out the UUID of that swap partition using the commandls -l /dev/disk/by-uuid
. And edit your fstab (nano /etc/fstab
) adding a new line there likeUUID=YourSwapPartitionsUUID none swap sw 0 0
. If you don't want to reboot right now you can also run additionallyswapon -U YourSwapPartitionsUUID
.
But make sure you don't wipe your disk/partition creating it.
No not out of the box - you could in theory create a mdraid for swap - however this can lead to (serious) issues in itself - seeThanks, the part that is confusing me is whether this partition will be mirrored as well or if it only resides on the free space of one disk?
Would there be an advantage to having swap partitions on both of the drives in my mirror? Does proxmox just treat them like an extra stick of ram? I assume if that's possible it could speed things up if my system were to start swapping?No not out of the box - you could in theory create a mdraid for swap - however this can lead to (serious) issues in itself - see
https://bugzilla.kernel.org/show_bug.cgi?id=99171
Last time I configured a system with swap - I just created multiple swap-partitions on the drives (and lived with the risk of having the system crash in a situation where swap was used and a disk broke)
Hi,Anecdotally, I ran Proxmox on ZFS swap for about about 6 months without issue.
Only a HW raid1 for swap as far as I know. Mdadm or ZFS as software raid still got these problems.
Yes, swap on top of ZFS shouldn't be done. See my thread discussing mirrored swap: https://forum.proxmox.com/threads/best-way-to-setup-swap-partition.116781/I have 2x 250GB SSDs in a ZFS RAID1 that I am booting from. I'd like to add a swap volume within ZFS. Am I opening myself up to issues? Only using 50GB at the moment so there is plenty of free space.
Option 3.)
Use a zvol as swap partition on an encrypted ZFS mirror. This isn't great because of the feedback loop where swapping will cause ZFS to write more to the RAM, which will increase swapping, which will cause ZFS to write even more to RAM, which will increase swapping ... until you OOM.
See for example here: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=199189
Yes, swap on top of ZFS shouldn't be done. See my thread discussing mirrored swap: https://forum.proxmox.com/threads/best-way-to-setup-swap-partition.116781/
We use essential cookies to make this site work, and optional cookies to enhance your experience.