mm: compaction: do not mark unmovable pageblocks as skipped in async compaction
[firefly-linux-kernel-4.4.55.git] / mm / oom_kill.c
index 96d7945f75a6ab67292eaf7e83e28e936bd0e307..054ff47c4478ddb6d6ef77cb66f6fd8330bdbea4 100644 (file)
@@ -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) {
                        /*
@@ -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,
@@ -99,14 +102,19 @@ struct task_struct *find_lock_task_mm(struct task_struct *p)
 {
        struct task_struct *t;
 
+       rcu_read_lock();
+
        for_each_thread(p, t) {
                task_lock(t);
                if (likely(t->mm))
-                       return t;
+                       goto found;
                task_unlock(t);
        }
+       t = NULL;
+found:
+       rcu_read_unlock();
 
-       return NULL;
+       return t;
 }
 
 /* return true if the task is not adequate as candidate victim task. */
@@ -458,10 +466,8 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
        }
        read_unlock(&tasklist_lock);
 
-       rcu_read_lock();
        p = find_lock_task_mm(victim);
        if (!p) {
-               rcu_read_unlock();
                put_task_struct(victim);
                return;
        } else if (victim != p) {
@@ -487,6 +493,7 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
         * That thread will now get access to memory reserves since it has a
         * pending fatal signal.
         */
+       rcu_read_lock();
        for_each_process(p)
                if (p->mm == mm && !same_thread_group(p, victim) &&
                    !(p->flags & PF_KTHREAD)) {