Fri, November 23, 2018 ยท 1 min read

Enabling Zswap on fedora 28

Enabling Zswap on fedora 28

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