diff options
Diffstat (limited to 'mm/oom_kill.c')
-rw-r--r-- | mm/oom_kill.c | 84 |
1 files changed, 38 insertions, 46 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 92bcf1db16b2..175a67a78a99 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -58,6 +58,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
58 | unsigned long points, cpu_time, run_time; | 58 | unsigned long points, cpu_time, run_time; |
59 | struct mm_struct *mm; | 59 | struct mm_struct *mm; |
60 | struct task_struct *child; | 60 | struct task_struct *child; |
61 | int oom_adj; | ||
61 | 62 | ||
62 | task_lock(p); | 63 | task_lock(p); |
63 | mm = p->mm; | 64 | mm = p->mm; |
@@ -65,6 +66,11 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
65 | task_unlock(p); | 66 | task_unlock(p); |
66 | return 0; | 67 | return 0; |
67 | } | 68 | } |
69 | oom_adj = mm->oom_adj; | ||
70 | if (oom_adj == OOM_DISABLE) { | ||
71 | task_unlock(p); | ||
72 | return 0; | ||
73 | } | ||
68 | 74 | ||
69 | /* | 75 | /* |
70 | * The memory size of the process is the basis for the badness. | 76 | * The memory size of the process is the basis for the badness. |
@@ -148,15 +154,15 @@ unsigned long badness(struct task_struct *p, unsigned long uptime) | |||
148 | points /= 8; | 154 | points /= 8; |
149 | 155 | ||
150 | /* | 156 | /* |
151 | * Adjust the score by oomkilladj. | 157 | * Adjust the score by oom_adj. |
152 | */ | 158 | */ |
153 | if (p->oomkilladj) { | 159 | if (oom_adj) { |
154 | if (p->oomkilladj > 0) { | 160 | if (oom_adj > 0) { |
155 | if (!points) | 161 | if (!points) |
156 | points = 1; | 162 | points = 1; |
157 | points <<= p->oomkilladj; | 163 | points <<= oom_adj; |
158 | } else | 164 | } else |
159 | points >>= -(p->oomkilladj); | 165 | points >>= -(oom_adj); |
160 | } | 166 | } |
161 | 167 | ||
162 | #ifdef DEBUG | 168 | #ifdef DEBUG |
@@ -251,11 +257,8 @@ static struct task_struct *select_bad_process(unsigned long *ppoints, | |||
251 | *ppoints = ULONG_MAX; | 257 | *ppoints = ULONG_MAX; |
252 | } | 258 | } |
253 | 259 | ||
254 | if (p->oomkilladj == OOM_DISABLE) | ||
255 | continue; | ||
256 | |||
257 | points = badness(p, uptime.tv_sec); | 260 | points = badness(p, uptime.tv_sec); |
258 | if (points > *ppoints || !chosen) { | 261 | if (points > *ppoints) { |
259 | chosen = p; | 262 | chosen = p; |
260 | *ppoints = points; | 263 | *ppoints = points; |
261 | } | 264 | } |
@@ -284,22 +287,27 @@ static void dump_tasks(const struct mem_cgroup *mem) | |||
284 | printk(KERN_INFO "[ pid ] uid tgid total_vm rss cpu oom_adj " | 287 | printk(KERN_INFO "[ pid ] uid tgid total_vm rss cpu oom_adj " |
285 | "name\n"); | 288 | "name\n"); |
286 | do_each_thread(g, p) { | 289 | do_each_thread(g, p) { |
287 | /* | 290 | struct mm_struct *mm; |
288 | * total_vm and rss sizes do not exist for tasks with a | 291 | |
289 | * detached mm so there's no need to report them. | ||
290 | */ | ||
291 | if (!p->mm) | ||
292 | continue; | ||
293 | if (mem && !task_in_mem_cgroup(p, mem)) | 292 | if (mem && !task_in_mem_cgroup(p, mem)) |
294 | continue; | 293 | continue; |
295 | if (!thread_group_leader(p)) | 294 | if (!thread_group_leader(p)) |
296 | continue; | 295 | continue; |
297 | 296 | ||
298 | task_lock(p); | 297 | task_lock(p); |
298 | mm = p->mm; | ||
299 | if (!mm) { | ||
300 | /* | ||
301 | * total_vm and rss sizes do not exist for tasks with no | ||
302 | * mm so there's no need to report them; they can't be | ||
303 | * oom killed anyway. | ||
304 | */ | ||
305 | task_unlock(p); | ||
306 | continue; | ||
307 | } | ||
299 | printk(KERN_INFO "[%5d] %5d %5d %8lu %8lu %3d %3d %s\n", | 308 | printk(KERN_INFO "[%5d] %5d %5d %8lu %8lu %3d %3d %s\n", |
300 | p->pid, __task_cred(p)->uid, p->tgid, | 309 | p->pid, __task_cred(p)->uid, p->tgid, mm->total_vm, |
301 | p->mm->total_vm, get_mm_rss(p->mm), (int)task_cpu(p), | 310 | get_mm_rss(mm), (int)task_cpu(p), mm->oom_adj, p->comm); |
302 | p->oomkilladj, p->comm); | ||
303 | task_unlock(p); | 311 | task_unlock(p); |
304 | } while_each_thread(g, p); | 312 | } while_each_thread(g, p); |
305 | } | 313 | } |
@@ -317,11 +325,8 @@ static void __oom_kill_task(struct task_struct *p, int verbose) | |||
317 | return; | 325 | return; |
318 | } | 326 | } |
319 | 327 | ||
320 | if (!p->mm) { | 328 | if (!p->mm) |
321 | WARN_ON(1); | ||
322 | printk(KERN_WARNING "tried to kill an mm-less task!\n"); | ||
323 | return; | 329 | return; |
324 | } | ||
325 | 330 | ||
326 | if (verbose) | 331 | if (verbose) |
327 | printk(KERN_ERR "Killed process %d (%s)\n", | 332 | printk(KERN_ERR "Killed process %d (%s)\n", |
@@ -343,28 +348,13 @@ static int oom_kill_task(struct task_struct *p) | |||
343 | struct mm_struct *mm; | 348 | struct mm_struct *mm; |
344 | struct task_struct *g, *q; | 349 | struct task_struct *g, *q; |
345 | 350 | ||
351 | task_lock(p); | ||
346 | mm = p->mm; | 352 | mm = p->mm; |
347 | 353 | if (!mm || mm->oom_adj == OOM_DISABLE) { | |
348 | /* WARNING: mm may not be dereferenced since we did not obtain its | 354 | task_unlock(p); |
349 | * value from get_task_mm(p). This is OK since all we need to do is | ||
350 | * compare mm to q->mm below. | ||
351 | * | ||
352 | * Furthermore, even if mm contains a non-NULL value, p->mm may | ||
353 | * change to NULL at any time since we do not hold task_lock(p). | ||
354 | * However, this is of no concern to us. | ||
355 | */ | ||
356 | |||
357 | if (mm == NULL) | ||
358 | return 1; | 355 | return 1; |
359 | 356 | } | |
360 | /* | 357 | task_unlock(p); |
361 | * Don't kill the process if any threads are set to OOM_DISABLE | ||
362 | */ | ||
363 | do_each_thread(g, q) { | ||
364 | if (q->mm == mm && q->oomkilladj == OOM_DISABLE) | ||
365 | return 1; | ||
366 | } while_each_thread(g, q); | ||
367 | |||
368 | __oom_kill_task(p, 1); | 358 | __oom_kill_task(p, 1); |
369 | 359 | ||
370 | /* | 360 | /* |
@@ -387,10 +377,11 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, | |||
387 | struct task_struct *c; | 377 | struct task_struct *c; |
388 | 378 | ||
389 | if (printk_ratelimit()) { | 379 | if (printk_ratelimit()) { |
390 | printk(KERN_WARNING "%s invoked oom-killer: " | ||
391 | "gfp_mask=0x%x, order=%d, oomkilladj=%d\n", | ||
392 | current->comm, gfp_mask, order, current->oomkilladj); | ||
393 | task_lock(current); | 380 | task_lock(current); |
381 | printk(KERN_WARNING "%s invoked oom-killer: " | ||
382 | "gfp_mask=0x%x, order=%d, oom_adj=%d\n", | ||
383 | current->comm, gfp_mask, order, | ||
384 | current->mm ? current->mm->oom_adj : OOM_DISABLE); | ||
394 | cpuset_print_task_mems_allowed(current); | 385 | cpuset_print_task_mems_allowed(current); |
395 | task_unlock(current); | 386 | task_unlock(current); |
396 | dump_stack(); | 387 | dump_stack(); |
@@ -403,8 +394,9 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, | |||
403 | /* | 394 | /* |
404 | * If the task is already exiting, don't alarm the sysadmin or kill | 395 | * If the task is already exiting, don't alarm the sysadmin or kill |
405 | * its children or threads, just set TIF_MEMDIE so it can die quickly | 396 | * its children or threads, just set TIF_MEMDIE so it can die quickly |
397 | * if its mm is still attached. | ||
406 | */ | 398 | */ |
407 | if (p->flags & PF_EXITING) { | 399 | if (p->mm && (p->flags & PF_EXITING)) { |
408 | __oom_kill_task(p, 0); | 400 | __oom_kill_task(p, 0); |
409 | return 0; | 401 | return 0; |
410 | } | 402 | } |