aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/filesystems/proc.txt
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2010-08-09 20:19:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-09 23:45:02 -0400
commita63d83f427fbce97a6cea0db2e64b0eb8435cd10 (patch)
tree8ac229cdf6e2289d97e82e35774057106fe7f4a2 /Documentation/filesystems/proc.txt
parent74bcbf40546bb7500f2a7ba4ff3cc056a6bd004a (diff)
oom: badness heuristic rewrite
This a complete rewrite of the oom killer's badness() heuristic which is used to determine which task to kill in oom conditions. The goal is to make it as simple and predictable as possible so the results are better understood and we end up killing the task which will lead to the most memory freeing while still respecting the fine-tuning from userspace. Instead of basing the heuristic on mm->total_vm for each task, the task's rss and swap space is used instead. This is a better indication of the amount of memory that will be freeable if the oom killed task is chosen and subsequently exits. This helps specifically in cases where KDE or GNOME is chosen for oom kill on desktop systems instead of a memory hogging task. The baseline for the heuristic is a proportion of memory that each task is currently using in memory plus swap compared to the amount of "allowable" memory. "Allowable," in this sense, means the system-wide resources for unconstrained oom conditions, the set of mempolicy nodes, the mems attached to current's cpuset, or a memory controller's limit. The proportion is given on a scale of 0 (never kill) to 1000 (always kill), roughly meaning that if a task has a badness() score of 500 that the task consumes approximately 50% of allowable memory resident in RAM or in swap space. The proportion is always relative to the amount of "allowable" memory and not the total amount of RAM systemwide so that mempolicies and cpusets may operate in isolation; they shall not need to know the true size of the machine on which they are running if they are bound to a specific set of nodes or mems, respectively. Root tasks are given 3% extra memory just like __vm_enough_memory() provides in LSMs. In the event of two tasks consuming similar amounts of memory, it is generally better to save root's task. Because of the change in the badness() heuristic's baseline, it is also necessary to introduce a new user interface to tune it. It's not possible to redefine the meaning of /proc/pid/oom_adj with a new scale since the ABI cannot be changed for backward compatability. Instead, a new tunable, /proc/pid/oom_score_adj, is added that ranges from -1000 to +1000. It may be used to polarize the heuristic such that certain tasks are never considered for oom kill while others may always be considered. The value is added directly into the badness() score so a value of -500, for example, means to discount 50% of its memory consumption in comparison to other tasks either on the system, bound to the mempolicy, in the cpuset, or sharing the same memory controller. /proc/pid/oom_adj is changed so that its meaning is rescaled into the units used by /proc/pid/oom_score_adj, and vice versa. Changing one of these per-task tunables will rescale the value of the other to an equivalent meaning. Although /proc/pid/oom_adj was originally defined as a bitshift on the badness score, it now shares the same linear growth as /proc/pid/oom_score_adj but with different granularity. This is required so the ABI is not broken with userspace applications and allows oom_adj to be deprecated for future removal. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Nick Piggin <npiggin@suse.de> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Balbir Singh <balbir@in.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation/filesystems/proc.txt')
-rw-r--r--Documentation/filesystems/proc.txt94
1 files changed, 57 insertions, 37 deletions
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 8fe8895894d8..cf1295c2bb66 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -33,7 +33,8 @@ Table of Contents
33 2 Modifying System Parameters 33 2 Modifying System Parameters
34 34
35 3 Per-Process Parameters 35 3 Per-Process Parameters
36 3.1 /proc/<pid>/oom_adj - Adjust the oom-killer score 36 3.1 /proc/<pid>/oom_adj & /proc/<pid>/oom_score_adj - Adjust the oom-killer
37 score
37 3.2 /proc/<pid>/oom_score - Display current oom-killer score 38 3.2 /proc/<pid>/oom_score - Display current oom-killer score
38 3.3 /proc/<pid>/io - Display the IO accounting fields 39 3.3 /proc/<pid>/io - Display the IO accounting fields
39 3.4 /proc/<pid>/coredump_filter - Core dump filtering settings 40 3.4 /proc/<pid>/coredump_filter - Core dump filtering settings
@@ -1234,42 +1235,61 @@ of the kernel.
1234CHAPTER 3: PER-PROCESS PARAMETERS 1235CHAPTER 3: PER-PROCESS PARAMETERS
1235------------------------------------------------------------------------------ 1236------------------------------------------------------------------------------
1236 1237
12373.1 /proc/<pid>/oom_adj - Adjust the oom-killer score 12383.1 /proc/<pid>/oom_adj & /proc/<pid>/oom_score_adj- Adjust the oom-killer score
1238------------------------------------------------------ 1239--------------------------------------------------------------------------------
1239 1240
1240This file can be used to adjust the score used to select which processes 1241These file can be used to adjust the badness heuristic used to select which
1241should be killed in an out-of-memory situation. Giving it a high score will 1242process gets killed in out of memory conditions.
1242increase the likelihood of this process being killed by the oom-killer. Valid 1243
1243values are in the range -16 to +15, plus the special value -17, which disables 1244The badness heuristic assigns a value to each candidate task ranging from 0
1244oom-killing altogether for this process. 1245(never kill) to 1000 (always kill) to determine which process is targeted. The
1245 1246units are roughly a proportion along that range of allowed memory the process
1246The process to be killed in an out-of-memory situation is selected among all others 1247may allocate from based on an estimation of its current memory and swap use.
1247based on its badness score. This value equals the original memory size of the process 1248For example, if a task is using all allowed memory, its badness score will be
1248and is then updated according to its CPU time (utime + stime) and the 12491000. If it is using half of its allowed memory, its score will be 500.
1249run time (uptime - start time). The longer it runs the smaller is the score. 1250
1250Badness score is divided by the square root of the CPU time and then by 1251There is an additional factor included in the badness score: root
1251the double square root of the run time. 1252processes are given 3% extra memory over other tasks.
1252 1253
1253Swapped out tasks are killed first. Half of each child's memory size is added to 1254The amount of "allowed" memory depends on the context in which the oom killer
1254the parent's score if they do not share the same memory. Thus forking servers 1255was called. If it is due to the memory assigned to the allocating task's cpuset
1255are the prime candidates to be killed. Having only one 'hungry' child will make 1256being exhausted, the allowed memory represents the set of mems assigned to that
1256parent less preferable than the child. 1257cpuset. If it is due to a mempolicy's node(s) being exhausted, the allowed
1257 1258memory represents the set of mempolicy nodes. If it is due to a memory
1258/proc/<pid>/oom_score shows process' current badness score. 1259limit (or swap limit) being reached, the allowed memory is that configured
1259 1260limit. Finally, if it is due to the entire system being out of memory, the
1260The following heuristics are then applied: 1261allowed memory represents all allocatable resources.
1261 * if the task was reniced, its score doubles 1262
1262 * superuser or direct hardware access tasks (CAP_SYS_ADMIN, CAP_SYS_RESOURCE 1263The value of /proc/<pid>/oom_score_adj is added to the badness score before it
1263 or CAP_SYS_RAWIO) have their score divided by 4 1264is used to determine which task to kill. Acceptable values range from -1000
1264 * if oom condition happened in one cpuset and checked process does not belong 1265(OOM_SCORE_ADJ_MIN) to +1000 (OOM_SCORE_ADJ_MAX). This allows userspace to
1265 to it, its score is divided by 8 1266polarize the preference for oom killing either by always preferring a certain
1266 * the resulting score is multiplied by two to the power of oom_adj, i.e. 1267task or completely disabling it. The lowest possible value, -1000, is
1267 points <<= oom_adj when it is positive and 1268equivalent to disabling oom killing entirely for that task since it will always
1268 points >>= -(oom_adj) otherwise 1269report a badness score of 0.
1269 1270
1270The task with the highest badness score is then selected and its children 1271Consequently, it is very simple for userspace to define the amount of memory to
1271are killed, process itself will be killed in an OOM situation when it does 1272consider for each task. Setting a /proc/<pid>/oom_score_adj value of +500, for
1272not have children or some of them disabled oom like described above. 1273example, is roughly equivalent to allowing the remainder of tasks sharing the
1274same system, cpuset, mempolicy, or memory controller resources to use at least
127550% more memory. A value of -500, on the other hand, would be roughly
1276equivalent to discounting 50% of the task's allowed memory from being considered
1277as scoring against the task.
1278
1279For backwards compatibility with previous kernels, /proc/<pid>/oom_adj may also
1280be used to tune the badness score. Its acceptable values range from -16
1281(OOM_ADJUST_MIN) to +15 (OOM_ADJUST_MAX) and a special value of -17
1282(OOM_DISABLE) to disable oom killing entirely for that task. Its value is
1283scaled linearly with /proc/<pid>/oom_score_adj.
1284
1285Writing to /proc/<pid>/oom_score_adj or /proc/<pid>/oom_adj will change the
1286other with its scaled value.
1287
1288Caveat: when a parent task is selected, the oom killer will sacrifice any first
1289generation children with seperate address spaces instead, if possible. This
1290avoids servers and important system daemons from being killed and loses the
1291minimal amount of work.
1292
1273 1293
12743.2 /proc/<pid>/oom_score - Display current oom-killer score 12943.2 /proc/<pid>/oom_score - Display current oom-killer score
1275------------------------------------------------------------- 1295-------------------------------------------------------------