*/
 static struct task_struct *select_bad_process(unsigned int *ppoints,
                unsigned long totalpages, struct mem_cgroup *memcg,
-               const nodemask_t *nodemask)
+               const nodemask_t *nodemask, bool force_kill)
 {
        struct task_struct *g, *p;
        struct task_struct *chosen = NULL;
                if (test_tsk_thread_flag(p, TIF_MEMDIE)) {
                        if (unlikely(frozen(p)))
                                __thaw_task(p);
-                       return ERR_PTR(-1UL);
+                       if (!force_kill)
+                               return ERR_PTR(-1UL);
                }
                if (!p->mm)
                        continue;
                        if (p == current) {
                                chosen = p;
                                *ppoints = 1000;
-                       } else {
+                       } else if (!force_kill) {
                                /*
                                 * If this task is not being ptraced on exit,
                                 * then wait for it to finish before killing
        check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL);
        limit = mem_cgroup_get_limit(memcg) >> PAGE_SHIFT;
        read_lock(&tasklist_lock);
-       p = select_bad_process(&points, limit, memcg, NULL);
+       p = select_bad_process(&points, limit, memcg, NULL, false);
        if (p && PTR_ERR(p) != -1UL)
                oom_kill_process(p, gfp_mask, 0, points, limit, memcg, NULL,
                                 "Memory cgroup out of memory");
  * @gfp_mask: memory allocation flags
  * @order: amount of memory being requested as a power of 2
  * @nodemask: nodemask passed to page allocator
+ * @force_kill: true if a task must be killed, even if others are exiting
  *
  * If we run out of memory, we have the choice between either
  * killing a random task (bad), letting the system crash (worse)
  * don't have to be perfect here, we just have to be good.
  */
 void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
-               int order, nodemask_t *nodemask)
+               int order, nodemask_t *nodemask, bool force_kill)
 {
        const nodemask_t *mpol_mask;
        struct task_struct *p;
                goto out;
        }
 
-       p = select_bad_process(&points, totalpages, NULL, mpol_mask);
+       p = select_bad_process(&points, totalpages, NULL, mpol_mask,
+                              force_kill);
        /* Found nothing?!?! Either we hang forever, or we panic. */
        if (!p) {
                dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
 void pagefault_out_of_memory(void)
 {
        if (try_set_system_oom()) {
-               out_of_memory(NULL, 0, 0, NULL);
+               out_of_memory(NULL, 0, 0, NULL, false);
                clear_system_oom();
        }
        if (!test_thread_flag(TIF_MEMDIE))