brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: choom tells the Linux OOM killer which process to spare and which to sacrifice

Linux
~/tips/tip-linux-choom-oom-score-adj

choom -p 1234

Protect an important process, or offer up a less important one, when memory runs out.

When memory runs out, the kernel’s OOM killer picks a process to kill, usually the biggest one. That might be your database instead of a runaway script. You can nudge its choice.

choom -p 1234

This shows the current OOM score of process 1234 and its adjust value. The score is what the kernel uses to choose: the highest score goes first. The adjust value runs from -1000 to 1000 and is added to the score. To make a process the preferred victim:

choom -p 1234 -n 500

You can also start a command with a value, which suits batch jobs and test scripts:

choom -n 800 -- ./big-import.sh

A value of -1000 means never kill this one. Going below the current value needs root, or the CAP_SYS_RESOURCE capability, so a normal user can only make their own processes more likely to be killed, not less. That is how I would use it most of the time: raise the score of the things you can afford to lose, instead of shielding the important ones.

For a systemd service, set it in the unit with OOMScoreAdjust=, so it survives restarts. A value set with choom lasts only as long as that process, though children inherit it.

Be careful with -1000 on a big process. If the kernel may not kill it, it has to kill everything else first, and the machine can end up worse off than with a clean kill of that one program.

Further reading: choom(1) manual page, proc_pid_oom_score_adj(5) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link