Skip to content

Commit

Permalink
oom_kill: has_intersects_mems_allowed() needs rcu_read_lock()
Browse files Browse the repository at this point in the history
At least out_of_memory() calls has_intersects_mems_allowed() without
even rcu_read_lock(), this is obviously buggy.

Add the necessary rcu_read_lock().  This means that we can not simply
return from the loop, we need "bool ret" and "break".

While at it, swap the names of task_struct's (the argument and the
local).  This cleans up the code a little bit and avoids the unnecessary
initialization.

Signed-off-by: Oleg Nesterov <[email protected]>
Reviewed-by: Sergey Dyasly <[email protected]>
Tested-by: Sergey Dyasly <[email protected]>
Reviewed-by: Sameer Nanda <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Mandeep Singh Baines <[email protected]>
Cc: "Ma, Xindong" <[email protected]>
Reviewed-by: Michal Hocko <[email protected]>
Cc: "Tu, Xiaobing" <[email protected]>
Acked-by: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jan 22, 2014
1 parent 1da4db0 commit ad96244
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ static DEFINE_SPINLOCK(zone_scan_lock);
#ifdef CONFIG_NUMA
/**
* has_intersects_mems_allowed() - check task eligiblity for kill
* @tsk: task struct of which task to consider
* @start: task struct of which task to consider
* @mask: nodemask passed to page allocator for mempolicy ooms
*
* Task eligibility is determined by whether or not a candidate task, @tsk,
* shares the same mempolicy nodes as current if it is bound by such a policy
* and whether or not it has the same set of allowed cpuset nodes.
*/
static bool has_intersects_mems_allowed(struct task_struct *tsk,
static bool has_intersects_mems_allowed(struct task_struct *start,
const nodemask_t *mask)
{
struct task_struct *start = tsk;
struct task_struct *tsk;
bool ret = false;

rcu_read_lock();
for_each_thread(start, tsk) {
if (mask) {
/*
Expand All @@ -67,19 +69,20 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
* mempolicy intersects current, otherwise it may be
* needlessly killed.
*/
if (mempolicy_nodemask_intersects(tsk, mask))
return true;
ret = mempolicy_nodemask_intersects(tsk, mask);
} else {
/*
* This is not a mempolicy constrained oom, so only
* check the mems of tsk's cpuset.
*/
if (cpuset_mems_allowed_intersects(current, tsk))
return true;
ret = cpuset_mems_allowed_intersects(current, tsk);
}
if (ret)
break;
}
rcu_read_unlock();

return false;
return ret;
}
#else
static bool has_intersects_mems_allowed(struct task_struct *tsk,
Expand Down

0 comments on commit ad96244

Please sign in to comment.