earlyoom terminates processes when RAM and swap are running low to prevent Linux from freezing. Documentation
Installation on Ubuntu/Debian:
sudo apt update
sudo apt install earlyoom
sudo systemctl enable --now earlyoomConfiguration:
sudo nano /etc/default/earlyoomExample configuration:
EARLYOOM_ARGS="-m 2,1 -s 5,2 -r 60 --avoid ^(rubymine|node|Anno5[.]exe|dota2)$"-m 2,1— send SIGTERM when available RAM is ≤2%, and SIGKILL when it is ≤1%.-s 5,2— corresponding free swap thresholds: 5% and 2%. Both RAM and swap conditions must be met at the same time.-r 60— log memory status once per minute.--avoid— processes that should be avoided when selecting a process to terminate; this is not absolute protection.- Lower thresholds mean later intervention.
Apply the changes and verify:
sudo systemctl restart earlyoom
journalctl -u earlyoom -n 15 --no-pager