Memory
16 GB fills up quickly with a browser, an editor and containers. Instead of freezing, the system should compress what is idle, and if memory really runs out, close the hungriest app, not the whole desktop.
zswap
zswap keeps a compressed copy of pages that are about to be swapped out, in RAM. Most of them never
reach the disk. On the kernel command line (/etc/default/grub):
zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=20sysctl
files/99-memory.conf in the playbook → /etc/sysctl.d/
vm.swappiness = 100 # swapping to zswap is cheap, so swap idle pages early
vm.page-cluster = 0 # read swap one page at a time (right for compressed swap)
vm.watermark_boost_factor = 0
vm.watermark_scale_factor = 125 # start reclaiming a little earlier, avoid stalls
vm.dirty_bytes = 268435456 # 256 MB of unwritten data at most…
vm.dirty_background_bytes = 134217728 # …start writing at 128 MB (no long write freezes)systemd-oomd
With uwsm every app runs in its own systemd scope. A drop-in for the user session lets
systemd-oomd kill the app that is causing memory pressure, before the kernel's OOM killer picks something at random:
# /etc/systemd/system/user@.service.d/oomd.conf
[Service]
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=50%sudo systemctl enable --now systemd-oomd
Before and after
-GRUB_CMDLINE_LINUX_DEFAULT='quiet loglevel=3 … nowatchdog nvme_load=YES'
+GRUB_CMDLINE_LINUX_DEFAULT='quiet loglevel=3 … nowatchdog nvme_load=YES zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=20'Then sudo grub-mkconfig -o /boot/grub/grub.cfg and reboot.
+vm.swappiness = 100
+vm.page-cluster = 0
+vm.watermark_boost_factor = 0
+vm.watermark_scale_factor = 125
+vm.dirty_bytes = 268435456
+vm.dirty_background_bytes = 134217728Check it
cat /sys/module/zswap/parameters/enabled # Y
grep -r . /sys/kernel/debug/zswap/ 2>/dev/null | head # (as root) pool size and stored pages
sysctl vm.swappiness # 100