Ubuntu - Memory - Out of Memory Killer

If the system runs out of memory, Linux normally regards all processes equally.

However it is easy to configure the system to change the priority of processes so that they are either killed before anything else is killed or left alone to not be killed.


Out of Memory (oom) score

Linux has an “Out of Memory” killer facility.

Normally the OOM killer regards all processes equally, this stanza advises the kernel to treat this job differently.

The “adjustment” value provided to this stanza may be an integer value from -999 (very unlikely to be killed by the OOM killer) up to 1000 (very likely to be killed by the OOM killer).

Example:

# This application is a “resource hog” oom score 1000

expect daemon respawn exec /usr/bin/leaky-app

The OOM-killer is buried deep inside the kernel and has a very obscure algorithm,

How do I use oom_score_adj?

/proc/[pid] contains oom_score_adj

Adjust the score using the /proc/$(pidof mysqld)/oom_score_adj file to give the kernel some clue

Check the man page for the old oom_adj.

man proc

This is possible in Ubuntu using Upstart and the oom score configuration option.

Example log file extry of a kill process:

killing the process see: OOM killed process 659 (java) vm:4973220kB, rss:2066504kB, swap:0kB