Menu Close

Chapter 18. Improving system performance with zswap

You can improve system performance by enabling the zswap kernel feature.

18.1. What is zswap

This section explains what zswap is and how it can lead to system performance improvement.

zswap is a kernel feature that provides a compressed RAM cache for swap pages. The mechanism works as follows: zswap takes pages that are in the process of being swapped out and attempts to compress them into a dynamically allocated RAM-based memory pool. When the pool becomes full or the RAM becomes exhausted, zswap evicts pages from compressed cache on an LRU basis (least recently used) to the backing swap device. After the page has been decompressed into the swap cache, zswap frees the compressed version in the pool.

The benefits of zswap
  • significant I/O reduction
  • significant improvement of workload performance

In Red Hat Enterprise Linux 9, zswap is enabled by default.

Additional resources

18.2. Enabling zswap at runtime

You can enable the zswap feature at system runtime using the sysfs interface.

Prerequisites

  • You have root permissions.

Procedure

  • Enable zswap:

    # echo 1 > /sys/module/zswap/parameters/enabled

Verification step

  • Verify that zswap is enabled:

    # grep -r . /sys/kernel/debug/zswap
    
    duplicate_entry:0
    pool_limit_hit:13422200
    pool_total_size:6184960 (pool size in total in pages)
    reject_alloc_fail:5
    reject_compress_poor:0
    reject_kmemcache_fail:0
    reject_reclaim_fail:13422200
    stored_pages:4251 (pool size after compression)
    written_back_pages:0

Additional resources

18.3. Enabling zswap permanently

You can enable the zswap feature permanently by providing the zswap.enabled=1 kernel command-line parameter.

Prerequisites

  • You have root permissions.
  • The grubby or zipl utility is installed on your system.

Procedure

  1. Enable zswap permanently:

    # grubby --update-kernel=/boot/vmlinuz-$(uname -r) --args="zswap.enabled=1"
  2. Reboot the system for the changes to take effect.

Verification steps

  • Verify that zswap is enabled:

    # cat /proc/cmdline
    
    BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-70.5.1.el9_0.x86_64
    root=/dev/mapper/rhel-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M
    resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root
    rd.lvm.lv=rhel/swap rhgb quiet
    zswap.enabled=1