LinuxCommandLibrary

choom

Forcefully kill a process if memory low

TLDR

Display the OOM-killer score of the process with a specific ID

$ choom [[-p|--pid]] [pid]
copy

Change the adjust OOM-killer score of a specific process
$ choom [[-p|--pid]] [pid] [[-n|--adjust]] [-1000..+1000]
copy

Run a command with a specific adjust OOM-killer score
$ choom [[-n|--adjust]] [-1000..+1000] [command] [argument1 argument2 ...]
copy

SYNOPSIS

choom [options] [command [args...]]

PARAMETERS

-p, --protect
    Protects the specified process from being OOM-killed. This sets the oom_score_adj to -1000, the lowest possible value, making the process highly unlikely to be chosen by the OOM killer.

-n <value>, --oom-score-adj <value>
    Sets the oom_score_adj for the process to the specified <value>. The valid range for this value is from -1000 (most protected) to 1000 (most vulnerable). Positive values increase vulnerability, negative values decrease it.

-h, --help
    Displays a brief help message and exits.

-V, --version
    Displays version information for the choom utility and exits.

DESCRIPTION

choom is a Linux command-line utility used to modify a process's Out-Of-Memory (OOM) killer score adjustment (oom_score_adj) or to entirely protect a specific process and its children from being OOM-killed. The Linux kernel's OOM killer is invoked when the system runs out of memory. It selects and terminates processes based on their OOM score, a dynamic value indicating memory consumption and criticality. A higher OOM score means a process is more likely to be killed.

choom allows administrators and users to influence this behavior, making a process either more or less likely to be killed by the OOM killer. Using the -p (protect) option sets the oom_score_adj to its lowest possible value (-1000), effectively making the process almost immune to the OOM killer. This is crucial for critical services that must remain running even under severe memory pressure.

CAVEATS

Using choom, especially with the -p option or a very low oom_score_adj value, requires careful consideration. Protecting a process from the OOM killer means that if the system runs critically low on memory, other, potentially more critical processes might be killed instead, or the system could experience a hard lock-up if no processes can be killed to free memory.

Modifying oom_score_adj for processes not owned by the current user, or for system-wide processes, typically requires root privileges. Not all Linux distributions include choom by default; it is often part of the util-linux package.

THE LINUX OOM KILLER

The Out-Of-Memory (OOM) killer is a crucial component of the Linux kernel's memory management. Its purpose is to prevent system crashes when physical memory and swap space are exhausted. When activated, it identifies and terminates one or more processes to reclaim memory, allowing the system to continue operating. The selection algorithm aims to kill processes that consume significant memory and are considered less critical, based on various heuristics including the process's oom_score.

UNDERSTANDING <B>OOM_SCORE_ADJ</B>

The oom_score_adj value acts as an adjustment to a process's calculated oom_score. This file, located at /proc/<pid>/oom_score_adj, allows administrators to make a process more or less attractive to the OOM killer. A value of 0 (the default) means no adjustment. A negative value (e.g., -500) reduces the process's effective OOM score, making it less likely to be killed. A positive value (e.g., 500) increases the score, making it more vulnerable. The extreme value of -1000 (used by choom's -p option) effectively ensures the process will not be killed by the OOM killer unless there are absolutely no other options or severe kernel misconfiguration.

HISTORY

choom is a relatively recent addition to the suite of Linux command-line utilities, typically distributed as part of the util-linux package since versions around 2.27. It provides a user-friendly wrapper for the underlying /proc/[pid]/oom_score_adj kernel interface, which has existed for a longer period. Its development aimed to simplify and standardize the method for adjusting OOM killer behavior for processes, making it more accessible for system administrators to manage application resilience during memory pressure situations.

SEE ALSO

prlimit(1), nice(1), renice(1), /proc/[pid]/oom_score_adj, /proc/[pid]/oom_score, /proc/sys/vm/oom_kill_allocating_task

Copied to clipboard