From LinuxReviews
Jump to navigationJump to search

zswap is a Linux kernel feature that allows you to compress memory used by idle applications in order to prevent the system from swapping memory to disk. Compressed memory pages are only swapped to disk when the area set aside for zswap is full. This is specially useful for systems without a fast SSD since swapping to and from disk takes time. The trade-off to be aware of is that the memory pool set aside for zswap will not be available to regular applications which means that the total system memory available for applications is reduced.


A simple way to enable swap is to create a startup-script which configures it.

# We must have the zswap technology so RAM is 
# compressed to a RAM pool before they are swapped
echo 1 > /sys/module/zswap/parameters/enabled

# % of total system memory can be used for compressed
# swap pages. These are sent to disk when zswap pool
# is full.
echo 10 > /sys/module/zswap/parameters/max_pool_percent

## Up to kernel 5.1? (not sure)
# echo lz4 > /sys/module/zswap/parameters/compressor

# Newer kernels have the faster lzo-rle
echo lzo-rle > /sys/module/zswap/parameters/compressor

Do note that the max_pool_percent is set as a percentage of system RAM.

Also note that 4.xx kernels do not have lzo-rle available. It is the best option for 5.x+ kernels.