Junior — Middle
How does the Linux kernel manage process termination when there is a memory shortage through the OOM Killer mechanism?
sobes.tech AI
Answer from AI
In Linux, when memory is insufficient, the OOM Killer (Out-Of-Memory Killer) mechanism is triggered, which selects and terminates processes to free up memory and keep the system operational.
How it works:
- When free memory becomes critically low, the kernel activates the OOM Killer.
- It evaluates all processes based on a 'cost' of termination, considering:
- The amount of memory used by the process.
- The importance of the process (system processes are given lower priority for termination).
- The runtime of the process and other parameters.
- The process with the highest 'score' is chosen for termination.
- The kernel sends a SIGKILL signal to the selected process, freeing its memory.
Thus, the OOM Killer helps prevent total system crash due to memory exhaustion by sacrificing less important processes.