Out of Memory Killer
The OOM Killers job is to identify and kill the memory-hogger process and its children by sending them the fatal SIGKILL signal.
Quoting directly from the kernel docs:
The OOM killer selects a task to sacrifice for the sake of overall system stability. The selected task is killed in a hope that after it exits enough memory will be freed to continue normal operation.
Invoking the OOM Killer via Sysrq
The kernel provides an interesting feature dubbed Magic SysRq: essentially, certain keyboard combinations result in a callback to some kernel code. For example (assuming it’s enabled), pressing the alt+sysrq+b key combination will result in a full system reset. Read more here: https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
To see the magic sysrq state:
cat /proc/sys/kernel/sysrq
This reveals the current state of the Magic SysRq bitmask. Being positive, it shows that the feature is paritally enabled. To be able to invoke the OOM killer ia the SysRq feature, we need to first enable it fully. To do so, run the following command:
sudo sh -c "echo 1 > /proc/sys/kernel/sysrq"
Now we can use the Magic Sysrq to invoke the OOM killer. To do so, just:
echo f > /proc/sysrq-trigger
Understanding the 3 VM Overcommit Memory Policies
- The linux kernel follows a VM overcommit policy, deliberately over-committing memory. To view the current over-commit setting:
cat /proc/sys/vm/overcommit-memory
0 is the default value. The 3 permissible values are:
- 0 - allow memory over-commit using a heuristic algorithm
- 1 - Always overcommit (i.e. never refuse any
malloc) - 2 - never overcommit
There is also a ‘overcommit extend’, determined by:
cat /proc/sys/vm/overcommit_ratio
These settings are configurable via sysctl