[WATCHDOG] w83697hf/hg WDT driver - patch 4
[powerpc.git] / mm / oom_kill.c
index 991bf0c..20f41b0 100644 (file)
@@ -215,6 +215,18 @@ static struct task_struct *select_bad_process(unsigned long *ppoints)
                if (is_init(p))
                        continue;
 
+               /*
+                * This task already has access to memory reserves and is
+                * being killed. Don't allow any other task access to the
+                * memory reserve.
+                *
+                * Note: this may have a chance of deadlock if it gets
+                * blocked waiting for another task which itself is waiting
+                * for memory. Is there a better alternative?
+                */
+               if (test_tsk_thread_flag(p, TIF_MEMDIE))
+                       return ERR_PTR(-1UL);
+
                /*
                 * This is in the process of releasing memory so wait for it
                 * to finish before killing some other task by mistake.
@@ -223,16 +235,15 @@ static struct task_struct *select_bad_process(unsigned long *ppoints)
                 * go ahead if it is exiting: this will simply set TIF_MEMDIE,
                 * which will allow it to gain access to memory reserves in
                 * the process of exiting and releasing its resources.
-                * Otherwise we could get an OOM deadlock.
+                * Otherwise we could get an easy OOM deadlock.
                 */
-               if ((p->flags & PF_EXITING) && p == current) {
+               if (p->flags & PF_EXITING) {
+                       if (p != current)
+                               return ERR_PTR(-1UL);
+
                        chosen = p;
                        *ppoints = ULONG_MAX;
-                       break;
                }
-               if ((p->flags & PF_EXITING) ||
-                               test_tsk_thread_flag(p, TIF_MEMDIE))
-                       return ERR_PTR(-1UL);
 
                if (p->oomkilladj == OOM_DISABLE)
                        continue;
@@ -260,14 +271,11 @@ static void __oom_kill_task(struct task_struct *p, const char *message)
                return;
        }
 
-       task_lock(p);
-       if (!p->mm || p->mm == &init_mm) {
+       if (!p->mm) {
                WARN_ON(1);
                printk(KERN_WARNING "tried to kill an mm-less task!\n");
-               task_unlock(p);
                return;
        }
-       task_unlock(p);
 
        if (message) {
                printk(KERN_ERR "%s: Killed process %d (%s).\n",
@@ -301,7 +309,7 @@ static int oom_kill_task(struct task_struct *p, const char *message)
         * However, this is of no concern to us.
         */
 
-       if (mm == NULL || mm == &init_mm)
+       if (mm == NULL)
                return 1;
 
        __oom_kill_task(p, message);