On systems where memory is limited – be that a SOC compute or a low-end virtual machine, enable zswap gives you more usable memory. This is similar to Stacker which compress your data and let you have more space. Back in those days, hard drives were measures in MB!
First, check that your kernel supports zswap. If CONFIG_ZSWAP is yes, then you’re good to go with the next steps.
❯ grep -i config_zswap /boot/config-$(uname -r)
Now, configure initramfs to load the lz4 kernel modules
❯ echo lz4 >> /etc/initramfs-tools/modules
❯ echo lz4_compress >> /etc/initramfs-tools/modules
❯ update-initramfs -u
Finally, modify the grub boot parameters to enable zswap. Edit /etc/default/grub, append zswap.enabled=1
to GRUB_CMDLINE_LINUX_DEFAULT
Run update-grub to actually apply that to grub.cfg and then reboot. When the system comes back, check that zswap is enabled by running:
❯ dmesg | grep zswap
If it is, you should be able to see a message like this:
[ 0.804273] zswap: loaded using pool lz4/zbud
To see zswap usage:
❯ grep -R . /sys/kernel/debug/zswap/
/sys/kernel/debug/zswap/same_filled_pages:1
/sys/kernel/debug/zswap/stored_pages:12
/sys/kernel/debug/zswap/pool_total_size:24576
/sys/kernel/debug/zswap/duplicate_entry:0
/sys/kernel/debug/zswap/written_back_pages:0
/sys/kernel/debug/zswap/reject_compress_poor:0
/sys/kernel/debug/zswap/reject_kmemcache_fail:0
/sys/kernel/debug/zswap/reject_alloc_fail:0
/sys/kernel/debug/zswap/reject_reclaim_fail:0
/sys/kernel/debug/zswap/pool_limit_hit:0
To learn more about zswap, take a look at the kernel documentation.