Table of Contents

About

Compared to the compressed RAM solution, ZSWAP is a kernel-space solution that allows compressing pages before storing them to RAM.

Preparations

In order to use lz4 compression, initramfs has to be updated to include a few modules.

On Debian, install initramfs-tools which will create a tree under /etc/initramfs-tools. The file /etc/initramfs-tools/module needs to be edited and the following modules:

lz4
lz4_compress

appended to the file.

Once /etc/initramfs-tools/module is updated, issue:

update-initramfs -k all -u

to update the image.

Finally, issue:

update-grub

Upon reboot, the status of the zswap module can be checked by issuing:

dmesg | grep zswap

and a line similar to:

zswap: loaded using pool lz4/zbud

should indicate that lz4 has been loaded.

Updating the Kernel Parameters

zswap is initialized on boot and controlled by kernel parameters. Using GRUB, the file /etc/default/grub has to be edited and the following parameters appended to GRUB_CMDLINE_LINUX_DEFAULT:

zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=50

where:

Finally, issue:

update-grub

on the command line and reboot for the changes to take effect.

ZRAM and ZSWAP

Note that ZRAM creates a swap device(s) using RAM and instructs the kernel to swap on the created device(s). In case plenty of RAM is available, then the swap mark may never be hit. With ZSWAP, given the zswap.max_pool_percent setting, the kernel will always compress RAM up to some proportion.