Enable systemd-oomd

Prerequisites Link to heading

Make sure you have systemd installed with at least version 248:

pacman -Ss systemd | grep "core/systemd "

# core/systemd 248.2-1.1 [installed]

Setup Link to heading

Check if the service is active:

systemctl status systemd-oomd.service

Enable and start it with:

sudo systemctl enable systemd-oomd.service
sudo systemctl start  systemd-oomd.service

Trial Link to heading

Check it’s working properly by starting htop in a terminal window:

htop

And in another fill up your memory with a process:

systemd-run --user tail /dev/zero

If all goes well that process will be killed an you won’t notice any slowdown of your machine. Worst case, and common before systemd-oomd, your machine would have been usuable and you needed a forced restart.

Config Link to heading

Edit /etc/systemd/oomd.conf with your custom settings:

[OOM]
SwapUsedLimit=90%
DefaultMemoryPressureLimit=60%
DefaultMemoryPressureDurationSec=30s