aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/oom_kill.c74
1 files changed, 43 insertions, 31 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 0a6e466155d2..9a686aa35a48 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -52,6 +52,20 @@ static int has_intersects_mems_allowed(struct task_struct *tsk)
52 return 0; 52 return 0;
53} 53}
54 54
55static struct task_struct *find_lock_task_mm(struct task_struct *p)
56{
57 struct task_struct *t = p;
58
59 do {
60 task_lock(t);
61 if (likely(t->mm))
62 return t;
63 task_unlock(t);
64 } while_each_thread(p, t);
65
66 return NULL;
67}
68
55/** 69/**
56 * badness - calculate a numeric value for how bad this task has been 70 * badness - calculate a numeric value for how bad this task has been
57 * @p: task struct of which task we should calculate 71 * @p: task struct of which task we should calculate
@@ -74,8 +88,8 @@ static int has_intersects_mems_allowed(struct task_struct *tsk)
74unsigned long badness(struct task_struct *p, unsigned long uptime) 88unsigned long badness(struct task_struct *p, unsigned long uptime)
75{ 89{
76 unsigned long points, cpu_time, run_time; 90 unsigned long points, cpu_time, run_time;
77 struct mm_struct *mm;
78 struct task_struct *child; 91 struct task_struct *child;
92 struct task_struct *c, *t;
79 int oom_adj = p->signal->oom_adj; 93 int oom_adj = p->signal->oom_adj;
80 struct task_cputime task_time; 94 struct task_cputime task_time;
81 unsigned long utime; 95 unsigned long utime;
@@ -84,17 +98,14 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
84 if (oom_adj == OOM_DISABLE) 98 if (oom_adj == OOM_DISABLE)
85 return 0; 99 return 0;
86 100
87 task_lock(p); 101 p = find_lock_task_mm(p);
88 mm = p->mm; 102 if (!p)
89 if (!mm) {
90 task_unlock(p);
91 return 0; 103 return 0;
92 }
93 104
94 /* 105 /*
95 * The memory size of the process is the basis for the badness. 106 * The memory size of the process is the basis for the badness.
96 */ 107 */
97 points = mm->total_vm; 108 points = p->mm->total_vm;
98 109
99 /* 110 /*
100 * After this unlock we can no longer dereference local variable `mm' 111 * After this unlock we can no longer dereference local variable `mm'
@@ -115,12 +126,17 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
115 * child is eating the vast majority of memory, adding only half 126 * child is eating the vast majority of memory, adding only half
116 * to the parents will make the child our kill candidate of choice. 127 * to the parents will make the child our kill candidate of choice.
117 */ 128 */
118 list_for_each_entry(child, &p->children, sibling) { 129 t = p;
119 task_lock(child); 130 do {
120 if (child->mm != mm && child->mm) 131 list_for_each_entry(c, &t->children, sibling) {
121 points += child->mm->total_vm/2 + 1; 132 child = find_lock_task_mm(c);
122 task_unlock(child); 133 if (child) {
123 } 134 if (child->mm != p->mm)
135 points += child->mm->total_vm/2 + 1;
136 task_unlock(child);
137 }
138 }
139 } while_each_thread(p, t);
124 140
125 /* 141 /*
126 * CPU time is in tens of seconds and run time is in thousands 142 * CPU time is in tens of seconds and run time is in thousands
@@ -256,9 +272,6 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
256 for_each_process(p) { 272 for_each_process(p) {
257 unsigned long points; 273 unsigned long points;
258 274
259 /* skip tasks that have already released their mm */
260 if (!p->mm)
261 continue;
262 /* skip the init task and kthreads */ 275 /* skip the init task and kthreads */
263 if (is_global_init(p) || (p->flags & PF_KTHREAD)) 276 if (is_global_init(p) || (p->flags & PF_KTHREAD))
264 continue; 277 continue;
@@ -385,14 +398,9 @@ static void __oom_kill_task(struct task_struct *p, int verbose)
385 return; 398 return;
386 } 399 }
387 400
388 task_lock(p); 401 p = find_lock_task_mm(p);
389 if (!p->mm) { 402 if (!p)
390 WARN_ON(1);
391 printk(KERN_WARNING "tried to kill an mm-less task %d (%s)!\n",
392 task_pid_nr(p), p->comm);
393 task_unlock(p);
394 return; 403 return;
395 }
396 404
397 if (verbose) 405 if (verbose)
398 printk(KERN_ERR "Killed process %d (%s) " 406 printk(KERN_ERR "Killed process %d (%s) "
@@ -437,6 +445,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
437 const char *message) 445 const char *message)
438{ 446{
439 struct task_struct *c; 447 struct task_struct *c;
448 struct task_struct *t = p;
440 449
441 if (printk_ratelimit()) 450 if (printk_ratelimit())
442 dump_header(p, gfp_mask, order, mem); 451 dump_header(p, gfp_mask, order, mem);
@@ -454,14 +463,17 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
454 message, task_pid_nr(p), p->comm, points); 463 message, task_pid_nr(p), p->comm, points);
455 464
456 /* Try to kill a child first */ 465 /* Try to kill a child first */
457 list_for_each_entry(c, &p->children, sibling) { 466 do {
458 if (c->mm == p->mm) 467 list_for_each_entry(c, &t->children, sibling) {
459 continue; 468 if (c->mm == p->mm)
460 if (mem && !task_in_mem_cgroup(c, mem)) 469 continue;
461 continue; 470 if (mem && !task_in_mem_cgroup(c, mem))
462 if (!oom_kill_task(c)) 471 continue;
463 return 0; 472 if (!oom_kill_task(c))
464 } 473 return 0;
474 }
475 } while_each_thread(p, t);
476
465 return oom_kill_task(p); 477 return oom_kill_task(p);
466} 478}
467 479