What are the sysctl tunables for the OOM Killer configuration, available for RHEL6 and later?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 6 and later

Issue

  • What are the sysctl tunables for the OOM Killer configuration?
  • I want to know if there are any options to customize what process OOM will kill.

Resolution

  • vm.panic_on_oom: enables or disables panic on out-of-memory feature. (default value: 0)
    • Acceptable values:
      • 0: when set to 0, the kernel will kill some rogue process, calling oom_killer, and, usually, system will survive without panics.
      • 1: when set to 1, the kernel panics when out-of-memory happens. However, if a system is using limited nodes by mempolicy/cpusets, and one of those nodes become exhausted on memory, one process may be killed by oom-killer, and no panic occurs in this case. Because other nodes' memory may be free, meaning that the system memory status may not be fatal yet.
      • 2: when set to 2, the kernel panics compulsorily. Even if out-of-memory happens under a memory cgroup, the whole system panics.
    • Setting:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl -w vm.panic_on_oom=1
        vm.panic_on_oom = 1
        
      • via 'echo' command:
        [root@localhost ~]#  echo 1 > /proc/sys/vm/panic_on_oom
        
    • Checking:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl vm.panic_on_oom
        vm.panic_on_oom = 0
        
      • via 'echo' command:
        [root@localhost ~]#  cat /proc/sys/vm/panic_on_oom 
        0
        
  • vm.oom_dump_tasks: enables a system-wide task dump (default value: 1 - since kernel-2.6.32-220.el6)
    • Acceptable values:
      • 0: when set to 0, no extra information on tasks is shown whenever the OOM killer actually kills a memory-hogging task.
      • 1: when set to 1, produces a system-wide task dump when the kernel performs an OOM-killing and includes such information as pid, uid, tgid, vm size, rss, cpu, oom_adj score, and name.
    • Setting:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl -w vm.oom_dump_tasks=1
        vm.oom_dump_tasks = 1
        
      • via 'echo' command:
        [root@localhost ~]#  echo 1 > /proc/sys/vm/oom_dump_tasks
        
    • Checking:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl vm.oom_dump_tasks
        vm.oom_dump_tasks = 0
        
      • via 'echo' command:
        [root@localhost ~]#  cat /proc/sys/vm/oom_dump_tasks 
        0
        
  • vm.oom_kill_allocating_task: enables or disables killing the OOM-triggering task in out-of-memory situations (default value: 0)
    • Acceptable values:
      • 0: when set to 0, the OOM killer will scan through the entire tasklist and select a task based on heuristics to kill.  This normally selects a rogue memory-hogging task that frees up a large amount of memory when killed.
      • 1: when set to 1, the OOM killer simply kills the task that triggered the out-of-memory condition.  This avoids the expensive tasklist scan.
    • Setting:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl -w vm.oom_kill_allocating_task=1
        vm.oom_kill_allocating_task = 1
        
      • via 'echo' command:
        [root@localhost ~]#  echo 1 > /proc/sys/vm/oom_kill_allocating_task
        
    • Checking:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl vm.oom_kill_allocating_task
        vm.oom_kill_allocating_task = 0
        
      • via 'echo' command:
        [root@localhost ~]#  cat /proc/sys/vm/oom_kill_allocating_task 
        0
        
  • vm.would_have_oomkilled: enables or disables killing tasks in out-of-memory situations. (default value: 0)
    • This sysctl tunable has been deprecated in RHEL 7 and later
    • Acceptable values:
      • 0: when set to 0, the OOM killer follows its usual behavior and kills a selected rogue memory-hogging task.
      • 1: when set to 1, the OOM killer does not kill the selected task based on its heuristics. It just prints a kernel log message out to warning about what task would have been killed instead.
    • Setting:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl -w vm.would_have_oomkilled=1
        vm.would_have_oomkilled = 1
        
      • via 'echo' command:
        [root@localhost ~]#  echo 1 > /proc/sys/vm/would_have_oomkilled
        
    • Checking:
      • via 'sysctl' command:
        [root@localhost ~]# sysctl vm.would_have_oomkilled
        vm.would_have_oomkilled = 0
        
      • via 'echo' command:
        [root@localhost ~]#  cat /proc/sys/vm/would_have_oomkilled
        0
        

Root Cause

The oom-killer is a Linux Kernel function, that occurs when a memory request (Page Fault or kernel memory allocation) is made while not enough memory is available.
The function terminates an active task (usually a non-prioritized process utilizing a lot of memory) in order to satisfy the new memory request.

Diagnostic Steps

There could be several reasons why an Out-of-Memory Kill event occurs.
Please refer to How to troubleshoot Out of memory (OOM) killer in Red Hat Enterprise Linux?

SBR
Components

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.