When your Linux machine runs out of memory, Out of Memory (OOM) killer is called by kernel to free some memory. It is often encountered on servers ...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks Raunak, interestingly in 20+ years of developing for Linux systems I've never played with the oom_score_adj feature, not even experimentally never mind in production :) This path may well end up as a tragedy of the commons, where every process lowers it's score drastically - cf: IP packets have a user-settable priority field, guess what it always is?
I feel that your caveat is worth restating:
"Remember that OOM is a symptom of a bigger problem - low available memory."
I would add that well before the OOM killer does it's thing, you should be getting alerts from your monitoring (you have monitoring in production right?), and the system will likely be swapping madly (you have swap space right?) - it's like working in treacle, but it buys you time to act!
Your fixes are good for keeping the show on the road - throw money at it in the form of more hardware / VMs, to buy more time to resolve the design / implementation errors...
I /have/ had to track down and fix numerous memory leaks (usually me being a lazy C coder), poor allocation strategies (looking at you long running Python apps!), and poor configuration choices (let's allow 1000 Apache instances!) to fix memory issues - eg: recently resorting to scheduled restarts of the Azure Linux agent (waagent) to prevent it eating my small server every 48-72 hours.
May the OOM never strike twice :)
edited to add: Julia (@b0rk) has an excellent series of Linux drawings, including one on memory management: drawings.jvns.ca/
Agreed! There is no substitute for good monitoring. It catches many issues before they become bigger problems. Ultimately, we must be fixing the root cause for high memory which is generally poor design/architecture.
What you said about the tragedy of commons is exactly what happened to
nice
scores for process priority.I toyed with that command a bit - I wanted to get the RSS and username in there, keep the sort, and include how many procs were included and skipped. Something like (fewer than 30 procs are shown due to trimming):
Here's the result. Whether this is an argument for or against bash syntax is an exercise for the reader. The cat/tr calls can probably be obviated :-)
Very interesting.
This must be a linux-specific thing, not *nix in general. My MacOS laptop doesn't seem to have a
/proc
.Edit to add: This article says Mac uses the sysctl function for some things that would otherwise use /proc for.
We've found an interesting issue: specific
oom_score_adj
values in the range [942,999] seem to produce "unexpected"oom_adj
values of 16, which seem to be out of range [-17, 15].That is at least unexpected, any idea where it is coming from and if that could affect the oom_killer behavior (e.g. task with oom_score_adj=940 will be killed before the task with oom_score_adj=999)? At least
/proc/<pid>/oom_score
seem to be "OK" and is higher for oom_score_adj=1000...Thanks for the article. Noticed you can add an OOM column to htop which make it easy to check.
Up Next: I have certain priorities which tasks can be killed and which not. Now checking how I can set the oom_adj values - maybe directly in the systemctl startup scripts?
little typo I spotted : instead of
sudo echo -200 > /proc/42/oom_score_adj
doecho -200 | sudo tee - /proc/42/oom_score_adj
Thanks, corrected