oom: give the dying task a higher priority
[pandora-kernel.git] / mm / oom_kill.c
index 011181e..31bd0c3 100644 (file)
@@ -69,8 +69,8 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
                        if (cpuset_mems_allowed_intersects(current, tsk))
                                return true;
                }
-               tsk = next_thread(tsk);
-       } while (tsk != start);
+       } while_each_thread(start, tsk);
+
        return false;
 }
 #else
@@ -81,6 +81,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
 }
 #endif /* CONFIG_NUMA */
 
+/*
+ * If this is a system OOM (not a memcg OOM) and the task selected to be
+ * killed is not already running at high (RT) priorities, speed up the
+ * recovery by boosting the dying task to the lowest FIFO priority.
+ * That helps with the recovery and avoids interfering with RT tasks.
+ */
+static void boost_dying_task_prio(struct task_struct *p,
+                                 struct mem_cgroup *mem)
+{
+       struct sched_param param = { .sched_priority = 1 };
+
+       if (mem)
+               return;
+
+       if (!rt_task(p))
+               sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}
+
 /*
  * The process p may have detached its own ->mm while exiting or through
  * use_mm(), but one or more of its subthreads may still have a valid
@@ -421,10 +439,10 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 }
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
-static int oom_kill_task(struct task_struct *p)
+static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 {
        p = find_lock_task_mm(p);
-       if (!p || p->signal->oom_adj == OOM_DISABLE) {
+       if (!p) {
                task_unlock(p);
                return 1;
        }
@@ -434,9 +452,17 @@ static int oom_kill_task(struct task_struct *p)
                K(get_mm_counter(p->mm, MM_FILEPAGES)));
        task_unlock(p);
 
-       p->rt.time_slice = HZ;
+
        set_tsk_thread_flag(p, TIF_MEMDIE);
        force_sig(SIGKILL, p);
+
+       /*
+        * We give our sacrificial lamb high priority and access to
+        * all the memory it needs. That way it should be able to
+        * exit() and clear out its resources quickly...
+        */
+       boost_dying_task_prio(p, mem);
+
        return 0;
 }
 #undef K
@@ -460,6 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
         */
        if (p->flags & PF_EXITING) {
                set_tsk_thread_flag(p, TIF_MEMDIE);
+               boost_dying_task_prio(p, mem);
                return 0;
        }
 
@@ -479,9 +506,6 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
                list_for_each_entry(child, &t->children, sibling) {
                        unsigned long child_points;
 
-                       if (child->mm == p->mm)
-                               continue;
-
                        /* badness() returns 0 if the thread is unkillable */
                        child_points = badness(child, mem, nodemask,
                                               uptime.tv_sec);
@@ -492,7 +516,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
                }
        } while_each_thread(p, t);
 
-       return oom_kill_task(victim);
+       return oom_kill_task(victim, mem);
 }
 
 /*
@@ -673,6 +697,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
         */
        if (fatal_signal_pending(current)) {
                set_thread_flag(TIF_MEMDIE);
+               boost_dying_task_prio(current, NULL);
                return;
        }
 
@@ -686,7 +711,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 
        read_lock(&tasklist_lock);
        if (sysctl_oom_kill_allocating_task &&
-           !oom_unkillable_task(current, NULL, nodemask)) {
+           !oom_unkillable_task(current, NULL, nodemask) &&
+           (current->signal->oom_adj != OOM_DISABLE)) {
                /*
                 * oom_kill_process() needs tasklist_lock held.  If it returns
                 * non-zero, current could not be killed so we must fallback to