Change oom_kill.c to use for_each_thread() rather than the racy
while_each_thread() which can loop forever if we race with exit.
Note also that most users were buggy even if while_each_thread() was
fine, the task can exit even _before_ rcu_read_lock().
Fortunately the new for_each_thread() only requires the stable
task_struct, so this change fixes both problems.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Sergey Dyasly <dserrg@gmail.com>
Tested-by: Sergey Dyasly <dserrg@gmail.com>
Reviewed-by: Sameer Nanda <snanda@chromium.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mandeep Singh Baines <msb@chromium.org>
Cc: "Ma, Xindong" <xindong.ma@intel.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: "Tu, Xiaobing" <xiaobing.tu@intel.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
{
struct task_struct *start = tsk;
{
struct task_struct *start = tsk;
+ for_each_thread(start, tsk) {
if (mask) {
/*
* If this is a mempolicy constrained oom, tsk's
if (mask) {
/*
* If this is a mempolicy constrained oom, tsk's
if (cpuset_mems_allowed_intersects(current, tsk))
return true;
}
if (cpuset_mems_allowed_intersects(current, tsk))
return true;
}
- } while_each_thread(start, tsk);
*/
struct task_struct *find_lock_task_mm(struct task_struct *p)
{
*/
struct task_struct *find_lock_task_mm(struct task_struct *p)
{
- struct task_struct *t = p;
+ for_each_thread(p, t) {
task_lock(t);
if (likely(t->mm))
return t;
task_unlock(t);
task_lock(t);
if (likely(t->mm))
return t;
task_unlock(t);
- } while_each_thread(p, t);
unsigned long chosen_points = 0;
rcu_read_lock();
unsigned long chosen_points = 0;
rcu_read_lock();
+ for_each_process_thread(g, p) {
unsigned int points;
switch (oom_scan_process_thread(p, totalpages, nodemask,
unsigned int points;
switch (oom_scan_process_thread(p, totalpages, nodemask,
chosen = p;
chosen_points = points;
}
chosen = p;
chosen_points = points;
}
- } while_each_thread(g, p);
if (chosen)
get_task_struct(chosen);
rcu_read_unlock();
if (chosen)
get_task_struct(chosen);
rcu_read_unlock();
{
struct task_struct *victim = p;
struct task_struct *child;
{
struct task_struct *victim = p;
struct task_struct *child;
- struct task_struct *t = p;
struct mm_struct *mm;
unsigned int victim_points = 0;
static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
struct mm_struct *mm;
unsigned int victim_points = 0;
static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
* still freeing memory.
*/
read_lock(&tasklist_lock);
* still freeing memory.
*/
read_lock(&tasklist_lock);
+ for_each_thread(p, t) {
list_for_each_entry(child, &t->children, sibling) {
unsigned int child_points;
list_for_each_entry(child, &t->children, sibling) {
unsigned int child_points;
get_task_struct(victim);
}
}
get_task_struct(victim);
}
}
- } while_each_thread(p, t);
read_unlock(&tasklist_lock);
rcu_read_lock();
read_unlock(&tasklist_lock);
rcu_read_lock();