Merge tag 'gcc-plugins-v4.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / mm / oom_kill.c
index 3b99054..ec9f11d 100644 (file)
@@ -403,9 +403,14 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask)
 
 static void dump_header(struct oom_control *oc, struct task_struct *p)
 {
-       pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
-               current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
+       nodemask_t *nm = (oc->nodemask) ? oc->nodemask : &cpuset_current_mems_allowed;
+
+       pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), nodemask=%*pbl, order=%d, oom_score_adj=%hd\n",
+               current->comm, oc->gfp_mask, &oc->gfp_mask,
+               nodemask_pr_args(nm), oc->order,
                current->signal->oom_score_adj);
+       if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order)
+               pr_warn("COMPACTION is disabled!!!\n");
 
        cpuset_print_current_mems_allowed();
        dump_stack();
@@ -495,6 +500,14 @@ static bool __oom_reap_task_mm(struct task_struct *tsk, struct mm_struct *mm)
                goto unlock_oom;
        }
 
+       /*
+        * Tell all users of get_user/copy_from_user etc... that the content
+        * is no longer stable. No barriers really needed because unmapping
+        * should imply barriers already and the reader would hit a page fault
+        * if it stumbled over a reaped memory.
+        */
+       set_bit(MMF_UNSTABLE, &mm->flags);
+
        tlb_gather_mmu(&tlb, mm, 0, -1);
        for (vma = mm->mmap ; vma; vma = vma->vm_next) {
                if (is_vm_hugetlb_page(vma))
@@ -894,13 +907,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
                        continue;
                if (same_thread_group(p, victim))
                        continue;
-               if (unlikely(p->flags & PF_KTHREAD) || is_global_init(p)) {
-                       /*
-                        * We cannot use oom_reaper for the mm shared by this
-                        * process because it wouldn't get killed and so the
-                        * memory might be still used. Hide the mm from the oom
-                        * killer to guarantee OOM forward progress.
-                        */
+               if (is_global_init(p)) {
                        can_oom_reap = false;
                        set_bit(MMF_OOM_SKIP, &mm->flags);
                        pr_info("oom killer %d (%s) has mm pinned by %d (%s)\n",
@@ -908,6 +915,12 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
                                        task_pid_nr(p), p->comm);
                        continue;
                }
+               /*
+                * No use_mm() user needs to read from the userspace so we are
+                * ok to reap it.
+                */
+               if (unlikely(p->flags & PF_KTHREAD))
+                       continue;
                do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
        }
        rcu_read_unlock();
@@ -1059,16 +1072,6 @@ void pagefault_out_of_memory(void)
 
        if (!mutex_trylock(&oom_lock))
                return;
-
-       if (!out_of_memory(&oc)) {
-               /*
-                * There shouldn't be any user tasks runnable while the
-                * OOM killer is disabled, so the current task has to
-                * be a racing OOM victim for which oom_killer_disable()
-                * is waiting for.
-                */
-               WARN_ON(test_thread_flag(TIF_MEMDIE));
-       }
-
+       out_of_memory(&oc);
        mutex_unlock(&oom_lock);
 }