Compared to the compressed RAM solution, ZSWAP is a kernel-space solution that allows compressing pages before storing them to RAM.
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:
appended to the file.
/etc/initramfs-tools/module is updated, issue:
update-initramfs -k all -u
to update the image.
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.
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
zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=50
zswap.compressorselects the compression to use,
zswap.max_pool_percentis the percent of RAM reserved to the compression pool (default 20%).
on the command line and reboot for the changes to take effect.
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.