mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-28 09:31:14 +00:00
[PATCH] oom-kill: mm locking fix
Dave Peterson <dsp@llnl.gov> points out that badness() is playing with mm_structs without taking a reference on them. mmput() can sleep, so taking a reference here (inside tasklist_lock) is hard. Fix it up via task_lock() instead. Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
parent
75129e297e
commit
97c2c9b84d
1 changed files with 18 additions and 8 deletions
|
@ -46,15 +46,25 @@
|
||||||
unsigned long badness(struct task_struct *p, unsigned long uptime)
|
unsigned long badness(struct task_struct *p, unsigned long uptime)
|
||||||
{
|
{
|
||||||
unsigned long points, cpu_time, run_time, s;
|
unsigned long points, cpu_time, run_time, s;
|
||||||
struct list_head *tsk;
|
struct mm_struct *mm;
|
||||||
|
struct task_struct *child;
|
||||||
|
|
||||||
if (!p->mm)
|
task_lock(p);
|
||||||
|
mm = p->mm;
|
||||||
|
if (!mm) {
|
||||||
|
task_unlock(p);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The memory size of the process is the basis for the badness.
|
* The memory size of the process is the basis for the badness.
|
||||||
*/
|
*/
|
||||||
points = p->mm->total_vm;
|
points = mm->total_vm;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* After this unlock we can no longer dereference local variable `mm'
|
||||||
|
*/
|
||||||
|
task_unlock(p);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Processes which fork a lot of child processes are likely
|
* Processes which fork a lot of child processes are likely
|
||||||
|
@ -64,11 +74,11 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
|
||||||
* child is eating the vast majority of memory, adding only half
|
* child is eating the vast majority of memory, adding only half
|
||||||
* to the parents will make the child our kill candidate of choice.
|
* to the parents will make the child our kill candidate of choice.
|
||||||
*/
|
*/
|
||||||
list_for_each(tsk, &p->children) {
|
list_for_each_entry(child, &p->children, sibling) {
|
||||||
struct task_struct *chld;
|
task_lock(child);
|
||||||
chld = list_entry(tsk, struct task_struct, sibling);
|
if (child->mm != mm && child->mm)
|
||||||
if (chld->mm != p->mm && chld->mm)
|
points += child->mm->total_vm/2 + 1;
|
||||||
points += chld->mm->total_vm/2 + 1;
|
task_unlock(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue