diff options
author | David Rientjes <rientjes@google.com> | 2009-06-16 18:32:56 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-16 22:47:43 -0400 |
commit | 2ff05b2b4eac2e63d345fc731ea151a060247f53 (patch) | |
tree | 1840bc2d3b381eca5d39869499339b0fcc6eabbf /include | |
parent | c9e444103b5e7a5a3519f9913f59767f92e33baf (diff) |
oom: move oom_adj value from task_struct to mm_struct
The per-task oom_adj value is a characteristic of its mm more than the
task itself since it's not possible to oom kill any thread that shares the
mm. If a task were to be killed while attached to an mm that could not be
freed because another thread were set to OOM_DISABLE, it would have
needlessly been terminated since there is no potential for future memory
freeing.
This patch moves oomkilladj (now more appropriately named oom_adj) from
struct task_struct to struct mm_struct. This requires task_lock() on a
task to check its oom_adj value to protect against exec, but it's already
necessary to take the lock when dereferencing the mm to find the total VM
size for the badness heuristic.
This fixes a livelock if the oom killer chooses a task and another thread
sharing the same memory has an oom_adj value of OOM_DISABLE. This occurs
because oom_kill_task() repeatedly returns 1 and refuses to kill the
chosen task while select_bad_process() will repeatedly choose the same
task during the next retry.
Taking task_lock() in select_bad_process() to check for OOM_DISABLE and in
oom_kill_task() to check for threads sharing the same memory will be
removed in the next patch in this series where it will no longer be
necessary.
Writing to /proc/pid/oom_adj for a kthread will now return -EINVAL since
these threads are immune from oom killing already. They simply report an
oom_adj value of OOM_DISABLE.
Cc: Nick Piggin <npiggin@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/mm_types.h | 2 | ||||
-rw-r--r-- | include/linux/sched.h | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 0e80e26ecf21..f4408106fcbc 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h | |||
@@ -232,6 +232,8 @@ struct mm_struct { | |||
232 | 232 | ||
233 | unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */ | 233 | unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */ |
234 | 234 | ||
235 | s8 oom_adj; /* OOM kill score adjustment (bit shift) */ | ||
236 | |||
235 | cpumask_t cpu_vm_mask; | 237 | cpumask_t cpu_vm_mask; |
236 | 238 | ||
237 | /* Architecture-specific MM context */ | 239 | /* Architecture-specific MM context */ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 1048bf50540a..1bc6fae0c135 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1178,7 +1178,6 @@ struct task_struct { | |||
1178 | * a short time | 1178 | * a short time |
1179 | */ | 1179 | */ |
1180 | unsigned char fpu_counter; | 1180 | unsigned char fpu_counter; |
1181 | s8 oomkilladj; /* OOM kill score adjustment (bit shift). */ | ||
1182 | #ifdef CONFIG_BLK_DEV_IO_TRACE | 1181 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
1183 | unsigned int btrace_seq; | 1182 | unsigned int btrace_seq; |
1184 | #endif | 1183 | #endif |