Zswap is a lightweight compressed cache for swap pages. It takes pages that are in the process of being swapped out and attempts to compress them into a dynamically allocated RAM-based memory pool. Older pages can be evicted to disk making this a sort of write-behind cache. zswap basically trades CPU cycles for potentially reduced swap I/O.
Benefits of usage
- Systems with limited RAM capacities can have the performance impact of swapping mitigated.
- Systems with SSDs as swap devices can extend the life of the device by drastically reducing life-shortening writes.
How to enable/disable Zswap
Zswap is disabled by default but can be enabled at boot time by setting the enabled attribute to 1 at boot time. ie: zswap.enabled=1. Zswap can also be enabled and disabled at runtime using the sysfs interface. An example command to enable zswap at runtime, assuming sysfs is mounted at /sys, is:
echo 1 > /sys/module/zswap/parameters/enabled
Similar results as with Zswap can be achieved with Zram. Zram though eliminates the need for physical swap device.