Zswap is a kernel feature which provides a compressed RAM cache for swap pages, it works in conjunction with swap space.
If swap partition is not present then we can create a swapfile and activate it:
dd if=/dev/zero of=/mnt/swapfile bs=1024 count=2097152
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile
free -h
Add entries in fstab to make changes persistent across reboot:
/mnt/swapfile swap swap defaults 0 0
After the swap partition setup now we can proceed with zswap configuration. Zswap requires a compression algorithm to be set, we will be using lz4 compression method.
Enabling zswap at runtime:
echo 1 > /sys/module/zswap/parameters/enabled
To enable zswap permanently use grub parameters:
GRUB_CMDLINE_LINUX="rhgb quiet video=SVIDEO-1:d elevator=noop console=tty0 console=ttyS0,115200n8 zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4"
Update grub configuration after making changes:
grub2-mkconfig -o /boot/grub2/grub.cfg
Set zswap to use 25% of the ram:
echo 25 > /sys/module/zswap/parameters/max_pool_percent
Enabling lz4 algorithm:
modprobe lz4 lz4_compress
cat /etc/dracut.conf.d/lz4.conf << EOF
modprobe lz4 lz4_compress
EOF
Regenerate initramfs images:
dracut --regenerate-all --force
Check if zswap is active:
cat /sys/module/zswap/parameters/enabled
dmesg | grep -i zswap
grep -R . /sys/module/zswap
Related Articles
Asciinema a screen recording tool
How to use Asciinema to record and share terminal screen recordings on Linux.
Renaming lv and vg
How to rename Logical Volumes (LV) and Volume Groups (VG) in LVM on Linux.
DNS Demystified 4: Troubleshooting DNS Issues
A systematic approach to diagnosing DNS problems โ from NXDOMAIN to SERVFAIL, slow resolution, and misconfigured zones.