Enabling Zswap on fedora 28

Zswap is a kernel feature which provides a compressed RAM cache for swap pages, it works in conjuction with swap space.

If swap partition is not present then we can create a swapfile and activate it.
Making a filebased swap,
Create a 2GB swap partition with “dd” and activate it.

[root@localhost cipher]# dd if=/dev/zero of=/mnt/swapfile bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 33.932 s, 63.3 MB/s

[root@localhost cipher]# chmod 600 /mnt/swapfile
[root@localhost cipher]# mkswap /mnt/swapfile
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=e0c85b8d-4d93-4475-a471-e6e7f47bbfd9
[root@localhost cipher]# swapon /mnt/swapfile
[root@localhost cipher]# free -h 
              total        used        free      shared  buff/cache   available
Mem:           3.8G        1.4G        166M        113M        2.3G        2.1G
Swap:          2.0G          0B        2.0G
[root@localhost cipher]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.8G        1.4G        168M        112M        2.3G        2.1G
Swap:          2.0G          0B        2.0G

Add entries in fstab to make chnages persistent across reboot

#
# /etc/fstab
# Created by anaconda on Wed Nov 21 15:05:32 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=07187215-9cd6-4727-b753-596d69daf9d7 /                       ext4    defaults        1 1
/mnt/swapfile swap swap defaults 0 0

After the swap partiton 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 permanentaly use grub parameters “…zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4”

[root@localhost cipher]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
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"
GRUB_DISABLE_RECOVERY="true"

Updating 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

[root@localhost cipher]# dracut --regenerate-all --force

Checking the current Zswap usagel,cheking if zswap is active.

[root@localhost cipher]# cat  /sys/module/zswap/parameters/enabled
Y

[root@localhost cipher]#     dmesg | grep -i zswap
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.19.2-200.fc28.x86_64 root=UUID=07187215-9cd6-4727-b753-596d69daf9d7 ro rhgb quiet video=SVIDEO-1:d elevator=noop console=tty0 console=ttyS0,115200n8 zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4
[    0.362239] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-4.19.2-200.fc28.x86_64 root=UUID=07187215-9cd6-4727-b753-596d69daf9d7 ro rhgb quiet video=SVIDEO-1:d elevator=noop console=tty0 console=ttyS0,115200n8 zswap.enabled=1 zswap.max_pool_percent=25 zswap.compressor=lz4
[    1.820253] zswap: loaded using pool lz4/zbud


[root@localhost cipher]# grep -R . /sys/module/zswap
grep: /sys/module/zswap/uevent: Permission denied
/sys/module/zswap/parameters/same_filled_pages_enabled:Y
/sys/module/zswap/parameters/enabled:Y
/sys/module/zswap/parameters/max_pool_percent:25
/sys/module/zswap/parameters/compressor:lz4
/sys/module/zswap/parameters/zpool:zbud