Merge tag 'ata-5.17-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemo...
[linux-2.6-microblaze.git] / mm / oom_kill.c
index 1ddabef..832fb33 100644 (file)
@@ -793,7 +793,7 @@ static inline bool __task_will_free_mem(struct task_struct *task)
         * coredump_task_exit(), so the oom killer cannot assume that
         * the process will promptly exit and release memory.
         */
-       if (sig->flags & SIGNAL_GROUP_COREDUMP)
+       if (sig->core_state)
                return false;
 
        if (sig->flags & SIGNAL_GROUP_EXIT)
@@ -994,6 +994,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)
         * If necessary, kill all tasks in the selected memory cgroup.
         */
        if (oom_group) {
+               memcg_memory_event(oom_group, MEMCG_OOM_GROUP_KILL);
                mem_cgroup_print_oom_group(oom_group);
                mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member,
                                      (void *)message);
@@ -1057,7 +1058,7 @@ bool out_of_memory(struct oom_control *oc)
 
        if (!is_memcg_oom(oc)) {
                blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
-               if (freed > 0)
+               if (freed > 0 && !is_sysrq_oom(oc))
                        /* Got some memory back in the last second. */
                        return true;
        }
@@ -1169,15 +1170,15 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
                goto put_task;
        }
 
-       if (mmget_not_zero(p->mm)) {
-               mm = p->mm;
-               if (task_will_free_mem(p))
-                       reap = true;
-               else {
-                       /* Error only if the work has not been done already */
-                       if (!test_bit(MMF_OOM_SKIP, &mm->flags))
-                               ret = -EINVAL;
-               }
+       mm = p->mm;
+       mmgrab(mm);
+
+       if (task_will_free_mem(p))
+               reap = true;
+       else {
+               /* Error only if the work has not been done already */
+               if (!test_bit(MMF_OOM_SKIP, &mm->flags))
+                       ret = -EINVAL;
        }
        task_unlock(p);
 
@@ -1188,13 +1189,16 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
                ret = -EINTR;
                goto drop_mm;
        }
-       if (!__oom_reap_task_mm(mm))
+       /*
+        * Check MMF_OOM_SKIP again under mmap_read_lock protection to ensure
+        * possible change in exit_mmap is seen
+        */
+       if (!test_bit(MMF_OOM_SKIP, &mm->flags) && !__oom_reap_task_mm(mm))
                ret = -EAGAIN;
        mmap_read_unlock(mm);
 
 drop_mm:
-       if (mm)
-               mmput(mm);
+       mmdrop(mm);
 put_task:
        put_task_struct(task);
        return ret;