diff options
Diffstat (limited to 'mm')
-rw-r--r-- | mm/oom_kill.c | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 1e56076672f5..3a1d46502938 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -6,8 +6,8 @@ | |||
6 | * for goading me into coding this file... | 6 | * for goading me into coding this file... |
7 | * | 7 | * |
8 | * The routines in this file are used to kill a process when | 8 | * The routines in this file are used to kill a process when |
9 | * we're seriously out of memory. This gets called from kswapd() | 9 | * we're seriously out of memory. This gets called from __alloc_pages() |
10 | * in linux/mm/vmscan.c when we really run out of memory. | 10 | * in mm/page_alloc.c when we really run out of memory. |
11 | * | 11 | * |
12 | * Since we won't call these routines often (on a well-configured | 12 | * Since we won't call these routines often (on a well-configured |
13 | * machine) this file will double as a 'coding guide' and a signpost | 13 | * machine) this file will double as a 'coding guide' and a signpost |
@@ -26,7 +26,7 @@ | |||
26 | /** | 26 | /** |
27 | * oom_badness - calculate a numeric value for how bad this task has been | 27 | * oom_badness - calculate a numeric value for how bad this task has been |
28 | * @p: task struct of which task we should calculate | 28 | * @p: task struct of which task we should calculate |
29 | * @p: current uptime in seconds | 29 | * @uptime: current uptime in seconds |
30 | * | 30 | * |
31 | * The formula used is relatively simple and documented inline in the | 31 | * The formula used is relatively simple and documented inline in the |
32 | * function. The main rationale is that we want to select a good task | 32 | * function. The main rationale is that we want to select a good task |
@@ -57,9 +57,9 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Processes which fork a lot of child processes are likely | 59 | * Processes which fork a lot of child processes are likely |
60 | * a good choice. We add the vmsize of the childs if they | 60 | * a good choice. We add the vmsize of the children if they |
61 | * have an own mm. This prevents forking servers to flood the | 61 | * have an own mm. This prevents forking servers to flood the |
62 | * machine with an endless amount of childs | 62 | * machine with an endless amount of children |
63 | */ | 63 | */ |
64 | list_for_each(tsk, &p->children) { | 64 | list_for_each(tsk, &p->children) { |
65 | struct task_struct *chld; | 65 | struct task_struct *chld; |
@@ -143,28 +143,32 @@ static struct task_struct * select_bad_process(void) | |||
143 | struct timespec uptime; | 143 | struct timespec uptime; |
144 | 144 | ||
145 | do_posix_clock_monotonic_gettime(&uptime); | 145 | do_posix_clock_monotonic_gettime(&uptime); |
146 | do_each_thread(g, p) | 146 | do_each_thread(g, p) { |
147 | unsigned long points; | ||
148 | int releasing; | ||
149 | |||
147 | /* skip the init task with pid == 1 */ | 150 | /* skip the init task with pid == 1 */ |
148 | if (p->pid > 1 && p->oomkilladj != OOM_DISABLE) { | 151 | if (p->pid == 1) |
149 | unsigned long points; | 152 | continue; |
150 | 153 | if (p->oomkilladj == OOM_DISABLE) | |
151 | /* | 154 | continue; |
152 | * This is in the process of releasing memory so wait it | 155 | /* |
153 | * to finish before killing some other task by mistake. | 156 | * This is in the process of releasing memory so for wait it |
154 | */ | 157 | * to finish before killing some other task by mistake. |
155 | if ((unlikely(test_tsk_thread_flag(p, TIF_MEMDIE)) || (p->flags & PF_EXITING)) && | 158 | */ |
156 | !(p->flags & PF_DEAD)) | 159 | releasing = test_tsk_thread_flag(p, TIF_MEMDIE) || |
157 | return ERR_PTR(-1UL); | 160 | p->flags & PF_EXITING; |
158 | if (p->flags & PF_SWAPOFF) | 161 | if (releasing && !(p->flags & PF_DEAD)) |
159 | return p; | 162 | return ERR_PTR(-1UL); |
160 | 163 | if (p->flags & PF_SWAPOFF) | |
161 | points = badness(p, uptime.tv_sec); | 164 | return p; |
162 | if (points > maxpoints || !chosen) { | 165 | |
163 | chosen = p; | 166 | points = badness(p, uptime.tv_sec); |
164 | maxpoints = points; | 167 | if (points > maxpoints || !chosen) { |
165 | } | 168 | chosen = p; |
169 | maxpoints = points; | ||
166 | } | 170 | } |
167 | while_each_thread(g, p); | 171 | } while_each_thread(g, p); |
168 | return chosen; | 172 | return chosen; |
169 | } | 173 | } |
170 | 174 | ||
@@ -189,7 +193,8 @@ static void __oom_kill_task(task_t *p) | |||
189 | return; | 193 | return; |
190 | } | 194 | } |
191 | task_unlock(p); | 195 | task_unlock(p); |
192 | printk(KERN_ERR "Out of Memory: Killed process %d (%s).\n", p->pid, p->comm); | 196 | printk(KERN_ERR "Out of Memory: Killed process %d (%s).\n", |
197 | p->pid, p->comm); | ||
193 | 198 | ||
194 | /* | 199 | /* |
195 | * We give our sacrificial lamb high priority and access to | 200 | * We give our sacrificial lamb high priority and access to |