At some point your Proxmox host is going to run low on memory. Maybe you spun up one too many VMs on an 8 GB mini PC, maybe a backup job or a ZFS scrub is eating RAM at the worst possible moment, and now the host is sluggish or the OOM killer is picking off processes at random. The usual first question people ask on the forums is "how do I add swap?" — and the honest answer depends entirely on what kind of storage your Proxmox install is sitting on.
This guide walks through checking your current swap, adding more of it the right way on a standard LVM install, and why the process is genuinely different — and riskier — if your root filesystem is ZFS. We'll also cover the one setting almost nobody touches after installation: swappiness.
What You Will Learn
You'll learn how to check how much swap your Proxmox VE host currently has and whether it's actually being used, how to extend an existing swap volume on a standard LVM install, how to add a swap file safely on ext4 or XFS, and why you should not put swap on a ZFS zvol. By the end you'll also know how to tune vm.swappiness so the kernel doesn't reach for swap more aggressively than you'd like.
What Is This Feature?
Swap is disk space the Linux kernel uses as an overflow when physical RAM fills up. Instead of crashing a process the moment memory runs out, the kernel moves less-used memory pages ("cold" pages that haven't been touched recently) out to disk, freeing up RAM for whatever actually needs it right now. It's slower than RAM by a wide margin — even on fast NVMe, swap access is an order of magnitude slower than accessing memory directly — but it's a lot better than the alternative, which is the kernel's out-of-memory killer terminating processes to free up space.
On a fresh Proxmox VE install, swap gets set up automatically, but how much you get — and how it's stored — depends on the filesystem you picked during installation. With the default LVM (ext4 or XFS) layout, the installer creates a dedicated swap logical volume. With ZFS, the installer doesn't create any swap device unless you specifically reserved space for one in the advanced options.
Why Would You Use It?
Homelab and small business Proxmox boxes are usually memory-constrained in a way enterprise deployments aren't. You're not running a 512 GB server with headroom to spare — you're running a NUC, an old desktop, or a budget dedicated server, and every VM's RAM allocation is a real tradeoff. Swap gives you a safety margin: instead of a VM refusing to start because you're 300 MB short, or the host itself locking up under memory pressure, the kernel has somewhere to put the least-important pages temporarily.
It's also useful during specific operations that spike memory briefly — package upgrades, `pvestatd` restarts after a config change, or a burst of backup activity — without leaving hundreds of megabytes of RAM permanently idle "just in case." Swap is cheap insurance for occasional pressure. It's a poor substitute for RAM if your host is under memory pressure constantly — that's a sign you need more physical memory, not more swap.
Prerequisites
- Root or sudo access to the Proxmox VE host's shell, either via SSH or the Shell button in the web UI (Datacenter → your node → Shell).
- A recent Proxmox VE install (8.x or 9.x) — the commands here work the same on both.
- Some free, unpartitioned disk space if you're extending an LVM swap volume, or free space on the root filesystem if you're adding a swap file.
- A basic comfort level running commands as root. None of this is destructive if you follow the steps in order, but skipping the "check first" steps is how people end up wiping the wrong volume.
Step-by-Step Tutorial
Step 1: Check what you currently have
Before changing anything, see what's actually there. Run:
free -h
This prints memory and swap usage in human-readable units (GB/MB instead of raw kilobytes). Look at the Swap row — the total column tells you how much swap exists, and used tells you how much of it is actively in use right now. It's completely normal to see a few hundred MB of swap "used" even when you have plenty of free RAM; the kernel proactively swaps out cold pages ahead of time. That's not a problem by itself.
To see exactly which swap devices are active and their priority, run:
swapon --show
On a default LVM install this usually shows something like /dev/dm-1 or /dev/pve/swap. On a ZFS install with no reserved swap, this command returns nothing at all — which tells you upfront that you're starting from zero.
Step 2: Figure out which storage layout you're running
The path you take next depends on this. Run:
lsblk
and:
pvs
If pvs returns a volume group (typically named pve), you're on the standard LVM layout and can extend your existing swap volume — that's the easiest path. If pvs returns nothing and instead zpool status shows a pool named rpool, your root filesystem is ZFS, and you'll want to skip to Step 3C below rather than fighting with a zvol.
Step 3A: Extend swap on a standard LVM install
Proxmox's installer sizes the default swap volume based on installed RAM — by the installer's own defaults, that's a minimum of 4 GB and a maximum of 8 GB, capped at one-eighth of your total disk size. If you've got more free space in the volume group, you can grow it.
First, check how much free space is left in the volume group:
vgs
Look at the VFree column. If it shows 0, there's nothing to extend into and you'll need the swap file approach instead (Step 3B). If there's free space, turn off swap before resizing it — resizing an active swap volume is asking for trouble:
swapoff /dev/pve/swap
Now extend the logical volume. This example adds 4 GB; adjust to whatever you actually have free:
lvresize --size +4G /dev/pve/swap
Rebuild the swap signature on the now-larger volume (this step is required — a resized swap volume needs to be reformatted as swap, but this does not touch any other data) and turn it back on:
mkswap /dev/pve/swap
swapon /dev/pve/swap
Run free -h again to confirm the new total shows up.
Step 3B: Add a swap file (ext4 or XFS only — not ZFS)
If there's no free space to extend the LVM volume, or you just want a quick, separate chunk of swap without touching the existing volume, a swap file works well on ext4 or XFS. Don't use this method on a ZFS root — we'll get to why in a moment.
Create a 4 GB file (change the size to suit your needs):
fallocate -l 4G /swapfile
Lock down the permissions — swap files need to be readable only by root, otherwise the kernel refuses to use them and mkswap will warn you about it:
chmod 600 /swapfile
Format it as swap and activate it:
mkswap /swapfile
swapon /swapfile
Make it persistent across reboots by adding it to /etc/fstab:
echo '/swapfile none swap sw 0 0' >> /etc/fstab
Confirm it's active with swapon --show and free -h.
Step 3C: If you're running ZFS, do this instead
Proxmox's own ZFS documentation is blunt about this: swap on a ZFS zvol can cause the server to lock up or generate heavy I/O load under memory pressure — precisely the situation you're adding swap to protect against. ZFS's copy-on-write design and its ARC memory cache don't play well with the kernel's swap subsystem; you can end up in a situation where the system needs to write to swap to free memory, but ZFS needs more memory to complete that very write. It's a real deadlock risk, not a theoretical one, and it's why the official guidance is to avoid it.
If you genuinely need swap on a ZFS host, the supported approach is a plain partition on a physical disk — not a zvol, not a file on the ZFS filesystem itself (which isn't supported at all). If you have a spare disk or unpartitioned space, create a partition with fdisk or parted, then format and activate it the same way:
mkswap /dev/sdb1
swapon /dev/sdb1
Then add it to /etc/fstab using its UUID rather than the device name, since device names like /dev/sdb1 can shift around after a reboot if you add or remove drives:
blkid /dev/sdb1
Copy the UUID from the output and add a line like this to /etc/fstab:
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx none swap sw 0 0
If you don't have a spare disk, the officially recommended path is honestly just to not run swap on that host and instead make sure you have enough physical RAM for your workload — combined with lowering swappiness (Step 4) so the little swap you might configure later is used only as a last resort.
Step 4: Tune swappiness
The vm.swappiness kernel parameter controls how eagerly the kernel reaches for swap versus reclaiming page cache. It's a scale from 0 to 100 (some newer kernels allow up to 200). The default on most Linux systems, including Proxmox, is 60 — tuned for desktop responsiveness, not server workloads. A lower value tells the kernel to hold off on swapping until it's genuinely needed.
Check your current value:
cat /proc/sys/vm/swappiness
Set it to 10 for the current session (this resets on reboot):
sysctl vm.swappiness=10
To make it stick permanently, create a config file:
echo 'vm.swappiness = 10' > /etc/sysctl.d/99-swappiness.conf
sysctl --system
This matters more on ZFS hosts, where you generally want the kernel leaning on ARC and page cache reclaim before it ever touches swap, if you have swap configured at all.
Commands Explained
| Command | What it does |
|---|---|
free -h | Shows RAM and swap totals/usage in human-readable form (GB/MB). |
swapon --show | Lists active swap devices, their size, used amount, and priority. |
lsblk | Lists all block devices (disks and partitions) attached to the host. |
pvs / vgs | Show LVM physical volumes and volume groups, including free space. |
lvresize --size +4G /dev/pve/swap | Grows an existing LVM logical volume by the given amount. |
mkswap | Writes a swap signature to a device or file so the kernel recognizes it as usable swap space. |
swapon / swapoff | Activates or deactivates a swap device or file. |
fallocate -l 4G /swapfile | Instantly allocates a 4 GB file on disk without writing zeros byte by byte. |
blkid | Prints the UUID and filesystem type of a block device — used to reference disks reliably in /etc/fstab. |
sysctl vm.swappiness=10 | Changes how aggressively the kernel swaps, for the current boot only. |
Common Errors
"insecure permissions 0644, 0600 suggested" — you'll see this from mkswap if you ran it against a swap file before locking down its permissions. Run chmod 600 /swapfile first, then mkswap again.
"Insufficient free extents" from lvresize — the volume group doesn't have enough unallocated space to grow the swap volume by the amount you requested. Check vgs for the actual VFree value and request less, or use the swap file method instead.
"swapon: /swapfile: swapon failed: Invalid argument" — this almost always means you tried to activate a swap file on ZFS or Btrfs, neither of which supports classic swap files. It's not a permissions issue and increasing the file size won't fix it; you need a raw partition instead.
Swap doesn't come back after a reboot — nearly always a missing or wrong /etc/fstab entry. Double check the UUID with blkid matches what's written in /etc/fstab exactly, since a typo here fails silently at boot rather than throwing an obvious error.
Troubleshooting
If free -h still shows the old swap total after resizing an LVM volume, you probably forgot to run mkswap after the lvresize — the volume is bigger, but the swap signature at the start of it still reflects the old size until you rewrite it.
If the host feels sluggish even with plenty of swap configured, check whether swap usage is actually climbing with watch -n 2 free -h while the system is under load. High swap total doesn't mean much — what matters is whether used keeps growing under normal operation. If it does, you have a genuine memory shortage that swap is only papering over, and the real fix is adding RAM or trimming how much you've allocated to VMs and containers.
On ZFS hosts specifically, if you're seeing high memory pressure and no swap, check how much RAM the ZFS ARC cache is holding onto before assuming you need swap at all:
arc_summary
ARC is designed to shrink under pressure and release memory back to the system, but on hosts with limited RAM it's worth checking zfs_arc_max in /etc/modprobe.d/zfs.conf to cap it, rather than adding risky zvol-based swap to compensate.
Best Practices
Don't treat swap as a substitute for enough RAM — it buys you a safety margin for spikes, not a long-term fix for an undersized host. If your VMs are configured with more total RAM than the host physically has, swap will get hammered constantly and performance will suffer badly; fix the overcommit instead.
On ZFS, avoid zvol-based swap entirely. If you can plan ahead, reserve a small unpartitioned slice of disk during installation specifically for a future swap partition — it's much easier than repartitioning a live system later.
Keep swap modest. A 4-8 GB swap volume is plenty for most homelab and small-business hosts; going much bigger rarely helps and just wastes disk space that could go to VM storage. And set swappiness to something lower than the default 60 on any server workload — you want the kernel treating swap as a last resort, not a first response to memory pressure.
Frequently Asked Questions
Do I need swap on Proxmox VE at all?
Not strictly, if you have comfortable RAM headroom and don't overcommit VM memory. But a small amount of swap is cheap insurance against the OOM killer during unexpected spikes, and costs you almost nothing in disk space.
Can I put swap inside a VM instead of on the host?
Yes, and that's a separate, unrelated decision — guest VMs manage their own swap independently of the Proxmox host's swap. This guide is specifically about the host itself, not the guests running on it.
Why didn't my ZFS install get any swap automatically?
Because the installer doesn't create swap by default on ZFS unless you explicitly reserved space for it in the advanced installation options. This is intentional, given the known issues with swap on ZFS.
Is a 0 swappiness value safe?
It tells the kernel to swap only when it absolutely has to, to avoid an out-of-memory kill. It's a reasonable choice on a host with plenty of RAM, but don't confuse it with disabling swap entirely — it still activates under real pressure.
How do I remove swap if I added too much?
Run swapoff on the device or file, remove its line from /etc/fstab, and then either lvremove the logical volume or delete the swap file with rm.
Conclusion
Adding swap on Proxmox VE isn't complicated once you know which storage layout you're dealing with — extending an LVM volume or adding a swap file takes a couple of minutes on ext4 or XFS. ZFS is the one case where the easy path is actually the wrong one, and it's worth the extra step of using a real partition instead of a zvol. Pair whatever swap you end up with a sane swappiness value, and treat it as a buffer for the occasional spike rather than a fix for a host that's consistently short on memory.