Zswap

Zswap is Article description::a lightweight compressed cache for swap pages.

Introduction
Zswap is particularly interesting for Gentoo, because it can help make the most of limited RAM resources when emerging (compiling) large packages. It uses a part of the available RAM as compressed swap space.

Imagine a system with 8 GB of RAM with zswap using up to 25% of it, and zswap reaching a compression ratio of a factor two. The system will them have 25% of 8GB times two is 4GB of swap space in memory, and it only cost 2 GB. Not only is this a very effective use of RAM memory, but it can be faster then swapfiles on older mechanical harddrives.

For systems with swap files on SSD, zswap might help to relieve wear on the SSDs.

Zswap works in conjunction with a normal swap backing store.

Next to zswap there is also something called zram. Zram can also be used to create a swap device for compressed pages in memory. The difference between zswap and zram is that zswap is able to evict pages to a disk based backing store, and zram is not.

Kernel configuration
The kernel needs to have swap, frontswap, options for zswap, and compression algorithms configured:

Interactive configuration
The zswap parameters can be examined as follows:

Enabling zswap can be done by writing "1" to the enabled file:

LZ4 is a popular choice for the compression algorithm:

Using the kernel commandline
Zswap can be configured permanently using the kernel commandline, e.g when using GRUB:

Do not forget to regenerate the GRUB configuration.

Alternative: using local.d
Create a file in /etc/local.d:

Make the file executable:

External resources

 * Arch Linux zswap wiki page
 * Linuxreviews zswap page
 * The Linux kernel user’s and administrator’s guide Zswap page