Zswap
Related articles
"Zswap is a Linux kernel feature providing a compressed write-back cache for swapped pages. Instead of moving memory pages to a swap device when they are to be swapped out, zswap performs their compression and then stores them into a memory pool dynamically allocated inside system's RAM." - Wikipedia
zswap is a compressed RAM cache for swap devices. Pages which would otherwise be swapped out to disk will instead be compressed and maintained in RAM until RAM is exhausted, after which the least recently used (LRU) pages will be sent to disk. This is in contrast to zram, which is a swap device in RAM and does not require a backing swap device. The long and the short of it is that you need to set up a Swap device in order to use zswap.
Contents
Enabling zswap
To enable zswap at runtime, execute the following command:
# echo 1 > /sys/module/zswap/parameters/enabled
To enable zswap permanently, add this to your kernel boot parameters Kernel parameters#Configuration:
zswap.enabled=1
Customizing zswap
By design, zswap has relatively few customizable parameters.
Customize the maximum allowed size
zswap does not use a preallocated pool of memory to hold compressed and swapped data. If you want to put a maximum bound on the percentage of memory that zswap can use, add this to your kernel boot parameters:
zswap.max_pool_percent=25
This can also be set in sysfs
.
Changing the compression algorithm
zswaps compression algorithm can also be set as a kernel boot parameter:
zswap.compressor=lzo #deflate #lz4
it can also be set at runtime by writing it to /sys/module/zswap/parameters/compressor, e.g:
echo lz4 > /sys/module/zswap/parameters/compressor
Enable LZ4 compression (faster than lzo and deflate, less compression)
- Add
lz4 lz4_compress
to the Mkinitcpio#MODULES array. - Rerun
mkinitcpio
. - Add
zswap.compressor=lz4
to your kernel parameters. - Reboot
- Check dmesg :
$ dmesg | grep zswap: [ 0.918052] zswap: loaded using pool lz4/zbud