]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - mm/oom_kill.c
userns: Store uid and gid values in struct cred with kuid_t and kgid_t types
[mirror_ubuntu-artful-kernel.git] / mm / oom_kill.c
index 856106036ba2a33266852929cb98d34975fac60d..9f09a1fde9f9954616473e1452c9e7e67c0778b8 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/ptrace.h>
 #include <linux/freezer.h>
 #include <linux/ftrace.h>
+#include <linux/ratelimit.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/oom.h>
@@ -309,7 +310,7 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
  */
 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;
@@ -335,7 +336,8 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
                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;
@@ -353,7 +355,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
                        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
@@ -408,8 +410,8 @@ static void dump_tasks(const struct mem_cgroup *memcg, const nodemask_t *nodemas
                }
 
                pr_info("[%5d] %5d %5d %8lu %8lu %3u     %3d         %5d %s\n",
-                       task->pid, task_uid(task), task->tgid,
-                       task->mm->total_vm, get_mm_rss(task->mm),
+                       task->pid, from_kuid(&init_user_ns, task_uid(task)),
+                       task->tgid, task->mm->total_vm, get_mm_rss(task->mm),
                        task_cpu(task), task->signal->oom_adj,
                        task->signal->oom_score_adj, task->comm);
                task_unlock(task);
@@ -444,6 +446,8 @@ static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
        struct task_struct *t = p;
        struct mm_struct *mm;
        unsigned int victim_points = 0;
+       static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
+                                             DEFAULT_RATELIMIT_BURST);
 
        /*
         * If the task is already exiting, don't alarm the sysadmin or kill
@@ -454,7 +458,7 @@ static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
                return;
        }
 
-       if (printk_ratelimit())
+       if (__ratelimit(&oom_rs))
                dump_header(p, gfp_mask, order, memcg, nodemask);
 
        task_lock(p);
@@ -517,11 +521,11 @@ static void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
                        pr_err("Kill process %d (%s) sharing same memory\n",
                                task_pid_nr(p), p->comm);
                        task_unlock(p);
-                       force_sig(SIGKILL, p);
+                       do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
                }
 
        set_tsk_thread_flag(victim, TIF_MEMDIE);
-       force_sig(SIGKILL, victim);
+       do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
 }
 #undef K
 
@@ -550,7 +554,8 @@ static void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
 }
 
 #ifdef CONFIG_CGROUP_MEM_RES_CTLR
-void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask)
+void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
+                             int order)
 {
        unsigned long limit;
        unsigned int points = 0;
@@ -566,12 +571,12 @@ void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask)
                return;
        }
 
-       check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL);
+       check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, order, 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,
+               oom_kill_process(p, gfp_mask, order, points, limit, memcg, NULL,
                                 "Memory cgroup out of memory");
        read_unlock(&tasklist_lock);
 }
@@ -684,6 +689,7 @@ static void clear_system_oom(void)
  * @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)
@@ -691,7 +697,7 @@ static void clear_system_oom(void)
  * 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;
@@ -735,7 +741,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
                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);
@@ -767,7 +774,7 @@ out:
 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))