Tune a Process's OOM Preference Safely with choom

Linux decides who dies when memory runs out using a score you can nudge with choom, one process at a time. You will inspect a process's current out-of-memory preference, change it for a controlled test, and restore the original value. You will also see how to apply an adjustment only to a command you launch. Allow about ten minutes. The examples use the choom shipped with util-linux 2.41.3 on this machine; option names are taken from the installed choom(1) manual.

This is a process-level setting, not a general memory limit. It influences which task the kernel considers for termination when an out-of-memory event occurs. Changing it can affect service availability, so test on a disposable process before touching a long-running service.

1. Check the installed command

Confirm which executable will run and record its version before relying on an example. These checks do not change process state:

$ command -v choom
/usr/bin/choom
$ choom --version
choom from util-linux 2.41.3
$ choom --help
Usage:
 choom [options] -p pid
 choom [options] -n number -p pid
 choom [options] -n number [--] command [args...]

Your help text may be formatted differently on another util-linux release. The useful forms are -p or --pid to select a process, and -n or --adjust to set its adjustment value.

2. Read a process's current values

Use a real process ID. The shell expands $$ to the current shell's PID, so this is a convenient read-only check:

$ choom --pid $$
pid 3989363's current OOM score: 666
pid 3989363's current OOM score adjust value: 0

The PID and score vary. The first line is the kernel's current OOM score, while the second is the adjustment value. Do not treat a score such as 666 as a percentage or a fixed process priority. It is derived from current memory conditions and the kernel's badness heuristic.

Checkpoint: write down the adjustment value before changing a process. If you cannot identify the process confidently with ps -p PID -o pid,comm,args, stop here.

3. Make a reversible test change

Choose a process you own and a small value for the first test. The following changes the current shell's adjustment to 1, reads it back, then restores 0:

$ choom --pid $$ --adjust 1
pid 3989363's OOM score adjust value changed from 0 to 1
$ choom --pid $$
pid 3989363's current OOM score: 667
pid 3989363's current OOM score adjust value: 1
$ choom --pid $$ --adjust 0
pid 3989363's OOM score adjust value changed from 1 to 0
$ choom --pid $$
pid 3989363's current OOM score: 666
pid 3989363's current OOM score adjust value: 0

The exact score depends on the host. The important checks are that the adjustment changes and that the final read reports the value you recorded. A positive adjustment makes a task more exposed to OOM selection; a negative adjustment makes it less exposed.

Warning: do not experiment on a database, supervisor, shell session running important work, or production service without an explicit rollback plan. The adjustment is state on the process and is lost when that process exits, but it can still alter which task is killed while it lasts. Reading another user's process or changing a protected process may require elevated privileges, and sudo does not make an incorrect PID safe.

4. Apply an adjustment to a new child

For a one-off command, put the adjustment before the command. Use -- when the boundary between choom's options and the child's arguments should be obvious:

$ choom --adjust -200 -- /bin/sh -c 'printf "child is running\n"'
pid 3991000's OOM score adjust value changed from 0 to -200
child is running

The child inherits the adjustment when it starts, and there is no persistent file to edit. The child command's exit status is still the result you need to check in a script:

$ choom --adjust -200 -- /usr/bin/true
pid 3991001's OOM score adjust value changed from 0 to -200
$ printf 'exit status: %s\n' "$?"
exit status: 0

Use an absolute command path when you are writing a service wrapper. Quote paths and arguments that can contain whitespace. Do not put untrusted text directly into a shell command string; pass it as an argument or avoid the shell.

5. Understand the boundaries

The adjustment accepts values from -1000 through 1000. The manual describes -1000 as disabling OOM killing for that task by forcing its resulting badness score to zero. That is a strong operational claim: it does not create memory, prevent allocation failure, or guarantee that the whole service survives. It can move pressure onto other tasks.

The raw badness score ranges from 0 to 1000 and depends on the memory allowed in the relevant context, such as a cgroup, cpuset, mempolicy or the whole system. A value read by choom is therefore a current observation, not a permanent ranking. A negative adjustment can also be rejected or behave differently in a restricted environment if the process is not yours or the kernel policy forbids the write.

Check a deliberate invalid value without changing anything:

$ choom --pid $$ --adjust 1001
choom: failed to set score adjust value: Invalid argument

If a write fails, keep the error and exit status. Check the PID, ownership and the process's current value before trying with privileges. If you changed a value and lost track of the original, read it with choom --pid PID; do not guess a restoration value on a service.

Done means