]> rtime.felk.cvut.cz Git - can-eth-gw-linux.git/blobdiff - mm/oom_kill.c
mm, oom: remove redundant sleep in pagefault oom handler
[can-eth-gw-linux.git] / mm / oom_kill.c
index 37ab4c5ab6e8fc2210bc4442693b05bafa884cb1..0399f146ae49900a92c52ea158823cef1ad18ff2 100644 (file)
@@ -44,48 +44,6 @@ int sysctl_oom_kill_allocating_task;
 int sysctl_oom_dump_tasks = 1;
 static DEFINE_SPINLOCK(zone_scan_lock);
 
-/*
- * compare_swap_oom_score_adj() - compare and swap current's oom_score_adj
- * @old_val: old oom_score_adj for compare
- * @new_val: new oom_score_adj for swap
- *
- * Sets the oom_score_adj value for current to @new_val iff its present value is
- * @old_val.  Usually used to reinstate a previous value to prevent racing with
- * userspacing tuning the value in the interim.
- */
-void compare_swap_oom_score_adj(short old_val, short new_val)
-{
-       struct sighand_struct *sighand = current->sighand;
-
-       spin_lock_irq(&sighand->siglock);
-       if (current->signal->oom_score_adj == old_val)
-               current->signal->oom_score_adj = new_val;
-       trace_oom_score_adj_update(current);
-       spin_unlock_irq(&sighand->siglock);
-}
-
-/**
- * test_set_oom_score_adj() - set current's oom_score_adj and return old value
- * @new_val: new oom_score_adj value
- *
- * Sets the oom_score_adj value for current to @new_val with proper
- * synchronization and returns the old value.  Usually used to temporarily
- * set a value, save the old value in the caller, and then reinstate it later.
- */
-short test_set_oom_score_adj(short new_val)
-{
-       struct sighand_struct *sighand = current->sighand;
-       int old_val;
-
-       spin_lock_irq(&sighand->siglock);
-       old_val = current->signal->oom_score_adj;
-       current->signal->oom_score_adj = new_val;
-       trace_oom_score_adj_update(current);
-       spin_unlock_irq(&sighand->siglock);
-
-       return old_val;
-}
-
 #ifdef CONFIG_NUMA
 /**
  * has_intersects_mems_allowed() - check task eligiblity for kill
@@ -257,7 +215,7 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
         * the page allocator means a mempolicy is in effect.  Cpuset policy
         * is enforced in get_page_from_freelist().
         */
-       if (nodemask && !nodes_subset(node_states[N_HIGH_MEMORY], *nodemask)) {
+       if (nodemask && !nodes_subset(node_states[N_MEMORY], *nodemask)) {
                *totalpages = total_swap_pages;
                for_each_node_mask(nid, *nodemask)
                        *totalpages += node_spanned_pages(nid);
@@ -310,6 +268,13 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
        if (!task->mm)
                return OOM_SCAN_CONTINUE;
 
+       /*
+        * If task is allocating a lot of memory and has been marked to be
+        * killed first if it triggers an oom, then select it.
+        */
+       if (oom_task_origin(task))
+               return OOM_SCAN_SELECT;
+
        if (task->flags & PF_EXITING && !force_kill) {
                /*
                 * If this task is not being ptraced on exit, then wait for it
@@ -626,43 +591,6 @@ void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
        spin_unlock(&zone_scan_lock);
 }
 
-/*
- * Try to acquire the oom killer lock for all system zones.  Returns zero if a
- * parallel oom killing is taking place, otherwise locks all zones and returns
- * non-zero.
- */
-static int try_set_system_oom(void)
-{
-       struct zone *zone;
-       int ret = 1;
-
-       spin_lock(&zone_scan_lock);
-       for_each_populated_zone(zone)
-               if (zone_is_oom_locked(zone)) {
-                       ret = 0;
-                       goto out;
-               }
-       for_each_populated_zone(zone)
-               zone_set_flag(zone, ZONE_OOM_LOCKED);
-out:
-       spin_unlock(&zone_scan_lock);
-       return ret;
-}
-
-/*
- * Clears ZONE_OOM_LOCKED for all system zones so that failed allocation
- * attempts or page faults may now recall the oom killer, if necessary.
- */
-static void clear_system_oom(void)
-{
-       struct zone *zone;
-
-       spin_lock(&zone_scan_lock);
-       for_each_populated_zone(zone)
-               zone_clear_flag(zone, ZONE_OOM_LOCKED);
-       spin_unlock(&zone_scan_lock);
-}
-
 /**
  * out_of_memory - kill the "best" process when we run out of memory
  * @zonelist: zonelist pointer
@@ -743,15 +671,16 @@ out:
 
 /*
  * The pagefault handler calls here because it is out of memory, so kill a
- * memory-hogging task.  If a populated zone has ZONE_OOM_LOCKED set, a parallel
- * oom killing is already in progress so do nothing.  If a task is found with
- * TIF_MEMDIE set, it has been killed so do nothing and allow it to exit.
+ * memory-hogging task.  If any populated zone has ZONE_OOM_LOCKED set, a
+ * parallel oom killing is already in progress so do nothing.
  */
 void pagefault_out_of_memory(void)
 {
-       if (try_set_system_oom()) {
+       struct zonelist *zonelist = node_zonelist(first_online_node,
+                                                 GFP_KERNEL);
+
+       if (try_set_zonelist_oom(zonelist, GFP_KERNEL)) {
                out_of_memory(NULL, 0, 0, NULL, false);
-               clear_system_oom();
+               clear_zonelist_oom(zonelist, GFP_KERNEL);
        }
-       schedule_timeout_killable(1);
 }