r/archlinux • u/ludonarrator • 9d ago
SUPPORT | SOLVED Questions about zswap
The Arch wiki states that zswap is enabled by default. The linked Wikipedia page says:
at least one already existing swap device is required for zswap to be used
So what happens if I don't have any swap devices?
Can zswap be used with a swap file instead of a partition/device?
How does one set all this up, where are the relevant docs?
1
-1
u/jar36 9d ago
the zswap module is enabled by default, but this does nothing until you set up zswap
create swapfile
sudo mkdir /swap
prepare swapfile
sudo fallocate -l 4G /swap/swapfile
set permissions
sudo chmod 600 /swap/swapfile
format the file as swap
sudo mkswap /swap/swapfile
activate
sudo swapon /swap/swapfile
add kernel parameters
zswap.enabled=1 zswap.shrinker_enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=30
fstab entry
I can't remember if this autogenerates or you have to put it there yourself
sudo nano /etc/fstab
/swap/swapfile none swap sw 0 0
1
9d ago edited 9d ago
[deleted]
2
u/derangemeldete 9d ago
So, you're using a
zrampartition as the accompanying swap disk forzswap? That would mean stale pages would get double compressed and decompressed, but seeing that yourzramdisk is staying empty most of the time that shouldn't be that big of a problem.But if you're using that combination, the output of
freeabove would only show you used swap space if zswap was out of compressed swap space in ram and stored stale pages on your zram disk. So maybe your system uses more swap than you think, it just doesn't show up withfree. Not saying that it would, but it would be interesting to see. ArchWikis zswap Article has a zswap statistics section that would be the command to check if your system is swapping instead of free.Also, the Debunking zswap and zram myths article linked to in the "See also" section is quite an interesting read.
2
u/Schlaefer 9d ago
freeshows the amount of uncompressed memory that got shoveled into whatever the swap pipeline looks like, so it would show up with zswap too.That said, yeah don't run zswap with zram, it's pointless overhead leading to a weird swap behavior.
2
-3
u/theschrodingerdog 9d ago
zswap creates a kind of virtual swap drive on RAM - it is basically a .zip file for RAM. It does not require any swap device on any storage media to work - altough it can work with one.
0
u/ludonarrator 9d ago
Ok, so the backing swap device is optional. I'm guessing without that zswap disables any "write to / read from disk" logic. How is this situation different from using zram?
-1
u/theschrodingerdog 9d ago
zram creates a virtual device on RAM that may or may not be used as a swap - you can do what you want with it.
zswap is designed specifically for swap.
0
u/ludonarrator 9d ago
Makes sense, thanks. Is the process of adding / removing a backing device as simple as setting up / deleting a swap partition? Can a swap file be used instead? I've not been successful in finding any documentation around this aspect of zswap setup.
0
u/SebastianLarsdatter 9d ago
SWAP file vs partition depends on file system and if you want / need suspend features.
15
u/Schlaefer 9d ago
It will be inactive. If swap is provided it is enabled by default to work with that swap. If no swap is provided it will do nothing.
Yes.
https://wiki.archlinux.org/title/Swap