Skip to content

Latest commit

 

History

History
57 lines (48 loc) · 1.22 KB

zswap-unit.md

File metadata and controls

57 lines (48 loc) · 1.22 KB

How to use zswap with a systemd unit

  1. Create a systemd unit:
    sudo nano /etc/systemd/system/zswap.service

  2. Add the following lines:

[Unit]
Description=Zswap Memory Compression

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/sh -c "\
 modprobe z3fold;\
 echo Y > /sys/module/zswap/parameters/same_filled_pages_enabled;\
 echo 25 > /sys/module/zswap/parameters/max_pool_percent;\
 echo zstd > /sys/module/zswap/parameters/compressor;\
 echo zsmalloc > /sys/module/zswap/parameters/zpool;\
 echo z3fold > /sys/module/zswap/parameters/zpool;\
 echo Y > /sys/module/zswap/parameters/enabled;\
 echo 25 > /proc/sys/vm/swappiness"
ExecStop=/bin/sh -c "\
 echo 25 > /proc/sys/vm/swappiness;\
 echo N > /sys/module/zswap/parameters/enabled"

[Install]
WantedBy=multi-user.target
  1. Enable the systemd unit:
    sudo systemctl enable zswap.service

  2. Start the systemd unit:
    sudo systemctl start zswap.service

  3. See log files for the unit:
    sudo journalctl -f zswap

  4. See status of unit:
    sudo systemctl status zswap.service

  5. To see the zswap parameters at runtime:
    grep -R . /sys/module/zswap/parameters

  6. If you modify the unit's content, disable and enable it to apply the changes.