net: phy: dp83848: add dp83822 PHY support
[cascardo/linux.git] / mm / oom_kill.c
index e2a2c35..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))
@@ -559,14 +572,7 @@ static void oom_reap_task(struct task_struct *tsk)
        debug_show_all_locks();
 
 done:
-       /*
-        * Clear TIF_MEMDIE because the task shouldn't be sitting on a
-        * reasonably reclaimable memory anymore or it is not a good candidate
-        * for the oom victim right now because it cannot release its memory
-        * itself nor by the oom reaper.
-        */
        tsk->oom_reaper_list = NULL;
-       exit_oom_victim(tsk);
 
        /*
         * Hide this mm from OOM killer because it has been either reaped or
@@ -580,8 +586,6 @@ done:
 
 static int oom_reaper(void *unused)
 {
-       set_freezable();
-
        while (true) {
                struct task_struct *tsk = NULL;
 
@@ -671,20 +675,29 @@ static void mark_oom_victim(struct task_struct *tsk)
 /**
  * exit_oom_victim - note the exit of an OOM victim
  */
-void exit_oom_victim(struct task_struct *tsk)
+void exit_oom_victim(void)
 {
-       if (!test_and_clear_tsk_thread_flag(tsk, TIF_MEMDIE))
-               return;
+       clear_thread_flag(TIF_MEMDIE);
 
        if (!atomic_dec_return(&oom_victims))
                wake_up_all(&oom_victims_wait);
 }
 
+/**
+ * oom_killer_enable - enable OOM killer
+ */
+void oom_killer_enable(void)
+{
+       oom_killer_disabled = false;
+}
+
 /**
  * oom_killer_disable - disable OOM killer
+ * @timeout: maximum timeout to wait for oom victims in jiffies
  *
  * Forces all page allocations to fail rather than trigger OOM killer.
- * Will block and wait until all OOM victims are killed.
+ * Will block and wait until all OOM victims are killed or the given
+ * timeout expires.
  *
  * The function cannot be called when there are runnable user tasks because
  * the userspace would see unexpected allocation failures as a result. Any
@@ -693,8 +706,10 @@ void exit_oom_victim(struct task_struct *tsk)
  * Returns true if successful and false if the OOM killer cannot be
  * disabled.
  */
-bool oom_killer_disable(void)
+bool oom_killer_disable(signed long timeout)
 {
+       signed long ret;
+
        /*
         * Make sure to not race with an ongoing OOM killer. Check that the
         * current is not killed (possibly due to sharing the victim's memory).
@@ -704,19 +719,16 @@ bool oom_killer_disable(void)
        oom_killer_disabled = true;
        mutex_unlock(&oom_lock);
 
-       wait_event(oom_victims_wait, !atomic_read(&oom_victims));
+       ret = wait_event_interruptible_timeout(oom_victims_wait,
+                       !atomic_read(&oom_victims), timeout);
+       if (ret <= 0) {
+               oom_killer_enable();
+               return false;
+       }
 
        return true;
 }
 
-/**
- * oom_killer_enable - enable OOM killer
- */
-void oom_killer_enable(void)
-{
-       oom_killer_disabled = false;
-}
-
 static inline bool __task_will_free_mem(struct task_struct *task)
 {
        struct signal_struct *sig = task->signal;
@@ -895,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",
@@ -909,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();
@@ -1060,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);
 }