From patchwork Tue Jul 17 11:05:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?56a56Iif6ZSu?= X-Patchwork-Id: 10528963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F27366020A for ; Tue, 17 Jul 2018 11:06:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D184A28AEF for ; Tue, 17 Jul 2018 11:06:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4ED228C3B; Tue, 17 Jul 2018 11:06:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC02628AEF for ; Tue, 17 Jul 2018 11:06:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A60006B0003; Tue, 17 Jul 2018 07:06:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E8A56B0005; Tue, 17 Jul 2018 07:06:03 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88A046B026B; Tue, 17 Jul 2018 07:06:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 41DD76B0003 for ; Tue, 17 Jul 2018 07:06:03 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 31-v6so423849plf.19 for ; Tue, 17 Jul 2018 04:06:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=ZdyFYavJmcZk9bMPt4b76/bdG3TwmXm1wHCXCeqIC3o=; b=cLvhVU/tZ7FVqniPx6ajyFEXrAuBcXOXnWWK26m7mJUpj8O+nB7ipi6SHLFiikG+HJ zoiDYgX4HFSDZTvMgKwz0pL7s4ALNj40lMvzNoGDLjmtpS1NJ02jPX2t+lnNGbGhWuP5 FxO4GCFG5ibIa/8j+Rr5olGQjk2ylhx0w9wX6bwJ/rBoEE7iW51RRlyCuyImLN7qmqD1 LqJ/axUl2jHQ6vfxqlAEVJpaNDy0tnBvbe3VbaJaSHuhXTP+Ge9budQPWOof+dtC53EQ f8R7PU4li6PmwLQHP48nhkeEL+WiGrl3N8XGkekDueuZHvEB0ZSJN43WJmOeoJTYeUB5 kAMQ== X-Gm-Message-State: AOUpUlH5HP0PDh9CZq12Uv70PEPJLOACnMwU5FvAnjMlKXhKBxjwNthI PT/26LEOIQlRMX9ZBskxwo3+EPUNGSyarRBLbr3ahyT8KvjSe0rrCMLKhizWSQtFpwFTFeANQMA E0sRmtqko4NksmwTg9HDbBrnQpsgS7sQ8gmJRi9kWkCX4F82QhN9g2Q5BsbISmRwBA8jjE/bvQ6 CqqgsuzleemmVpMVH5PFDhApLWr+JhX4bNaQ+487dUz3d0aEJGtcNn/FjqjZ+us7/XQX6d7n6Fk 7mtjqf062TvobO3IdxwCX8ZH0pW5jozHddyo0rGi8EzOyB/C1yYOnROTdkrINFA1kZYkR8BP3CE Sjp2UALilOO4gUHzu/SRwvs4339TNb1sTLfWzEVNHa46fd8YWR3pWTbPvgrChoR5XX8QKYyt3Oe 4 X-Received: by 2002:a62:3cd7:: with SMTP id b84-v6mr185288pfk.183.1531825562904; Tue, 17 Jul 2018 04:06:02 -0700 (PDT) X-Received: by 2002:a62:3cd7:: with SMTP id b84-v6mr185207pfk.183.1531825561737; Tue, 17 Jul 2018 04:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531825561; cv=none; d=google.com; s=arc-20160816; b=yCW1jGH8aJ29rgZqiVt9sSSNioPgVmDBm12FwnfoIeGhhNyH7NljfsGDFs/Ks+rqcz EOp2qjESo9mWFQAolCIO3I2hbtq9vLsRYH0Z+fFbJ7DSz87P40TG+l7PWSnSg/D6fvN9 rSsEzS8M8g3swlLJtXl3h4Qnom8y/THC0pCL1fjcJU5pgj4eROdXdFnwkt62Y1Ve6p+E xW0aWrpOvZFmE9gp5/RpuPKNGnDjS3eHAp96/lFlbTEIH4fnFcSnMaoPl7DUUN/NHWH0 X2iBlNKP/6VrWXlVbhq/q6TdS5YLmt6VKxw0dtP8RBO9N9LtZISU/NnL6W55Zbxp+Qex MJIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ZdyFYavJmcZk9bMPt4b76/bdG3TwmXm1wHCXCeqIC3o=; b=iIr6tEYA7eVRKh5IpI4ItCjHV2ir1EezgwyJ0ezMCByTMMwhyd7J3wmLbAv6pbUJ2a CXJU2wlA11lyhPOjFbz0QqrnBoKZ77B09HdB/ViCUbSNWax89WVIdL5lMemFDA8t9Ivk JSEp1/zPoCj6RCkTdfi8en9ri/15vWcq0uuRR3XdOBC3xx2nZT3q/dA5LCCp5uA4iX7H /v2yuklsuM5tDi1QcEthw4ND7NjdA11C4cLzTgezZmIQGPgjoQJMOjHNWzIrWFpzQbjv ZmPYCPNxU6wfypeul/HDf/CwK31ps85n3bn4Reqy810Q28xg8sDQZ0tPD6dWbV0eTlOF S8fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WQuIFQ+a; spf=pass (google.com: domain of ufo19890607@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ufo19890607@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y2-v6sor246336plr.76.2018.07.17.04.06.01 for (Google Transport Security); Tue, 17 Jul 2018 04:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ufo19890607@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WQuIFQ+a; spf=pass (google.com: domain of ufo19890607@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ufo19890607@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZdyFYavJmcZk9bMPt4b76/bdG3TwmXm1wHCXCeqIC3o=; b=WQuIFQ+aEIG7LlQ3f9l+wn9Msg2vzzVdv8SfEyXhx4ml+4eGR0cWALelnjiWqf7teO uNO5WgwiR54RRstuvRjmD2P0twN9Zn+h+B/ZCgSdvK+rQn1xTiDkPyFfZcw9yAYTunmi zXxigOCyEDUy8nW9jCh/tEiEYvhIDT/Tk+5SWv20gzXH2H8rZfT9zVkzuem5txvAxYI4 NdVVf1aUM85Dfyp/BMNLUDL0oyoW1KUtjdQYF45V8DB96NTReRSRCSVXZ4ANBmwFlrra H7Wl9Sk59qQG9kkpEki7Mxf0fzGUwYk9GQULLkxh9VEY695jy1o5AK+oY4iQy9DRY7+q yXBw== X-Google-Smtp-Source: AAOMgpdeV5qsoE1o9nWF/D72Y1OCoPDqyQ45lvx8tHrj/jGz+NWHuqhtksES9EtYB7DOFL/JOa0jiQ== X-Received: by 2002:a17:902:8f83:: with SMTP id z3-v6mr1163737plo.111.1531825561357; Tue, 17 Jul 2018 04:06:01 -0700 (PDT) Received: from dest.didichuxing.com ([168.63.150.120]) by smtp.gmail.com with ESMTPSA id y12-v6sm1371324pfe.139.2018.07.17.04.05.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:06:00 -0700 (PDT) From: ufo19890607@gmail.com To: akpm@linux-foundation.org, mhocko@suse.com, rientjes@google.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, penguin-kernel@i-love.sakura.ne.jp, guro@fb.com, yang.s@alibaba-inc.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuzhoujian@didichuxing.com Subject: [PATCH v14 1/2] Reorganize the oom report in dump_header Date: Tue, 17 Jul 2018 19:05:47 +0800 Message-Id: <1531825548-27761-1-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: yuzhoujian OOM report contains several sections. The first one is the allocation context that has triggered the OOM. Then we have cpuset context followed by the stack trace of the OOM path. Followed by the oom eligible tasks and the information about the chosen oom victim. One thing that makes parsing more awkward than necessary is that we do not have a single and easily parsable line about the oom context. This patch is reorganizing the oom report to 1) who invoked oom and what was the allocation request [ 131.751307] panic invoked oom-killer: gfp_mask=0x6280ca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0, oom_score_adj=0 2) OOM stack trace [ 131.752399] CPU: 16 PID: 8581 Comm: panic Not tainted 4.18.0-rc5+ #48 [ 131.753154] Hardware name: Inspur SA5212M4/YZMB-00370-107, BIOS 4.1.10 11/14/2016 [ 131.753806] Call Trace: [ 131.754473] dump_stack+0x5a/0x73 [ 131.755129] dump_header+0x53/0x2dc [ 131.755775] oom_kill_process+0x228/0x420 [ 131.756430] ? oom_badness+0x2a/0x130 [ 131.757063] out_of_memory+0x11a/0x4a0 [ 131.757710] __alloc_pages_slowpath+0x7cc/0xa1e [ 131.758392] ? apic_timer_interrupt+0xa/0x20 [ 131.759040] __alloc_pages_nodemask+0x277/0x290 [ 131.759710] alloc_pages_vma+0x73/0x180 [ 131.760388] do_anonymous_page+0xed/0x5a0 [ 131.761067] __handle_mm_fault+0xbb3/0xe70 [ 131.761749] handle_mm_fault+0xfa/0x210 [ 131.762457] __do_page_fault+0x233/0x4c0 [ 131.763136] do_page_fault+0x32/0x140 [ 131.763832] ? page_fault+0x8/0x30 [ 131.764523] page_fault+0x1e/0x30 3) oom context (contrains and the chosen victim). [ 131.771164] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0-1,task=panic,pid=8608,uid=0 An admin can easily get the full oom context at a single line which makes parsing much easier. Signed-off-by: yuzhoujian Acked-by: Michal Hocko --- Changes since v13: - remove the spaces for printing pid and uid. Changes since v12: - print the cpuset and memory allocation information after oom victim comm, pid. Changes since v11: - move the array of const char oom_constraint_text to oom_kill.c - add the cpuset information in the one line output. Changes since v10: - divide the patch v8 into two parts. One part is to add the array of const char and put enum oom_constaint into oom.h; the other adds a new func to print the missing information for the system- wide oom report. Changes since v9: - divide the patch v8 into two parts. One part is to move enum oom_constraint into memcontrol.h; the other refactors the output info in the dump_header. - replace orgin_memcg and kill_memcg with oom_memcg and task_memcg resptively. Changes since v8: - add the constraint in the oom_control structure. - put enum oom_constraint and constraint array into the oom.h file. - simplify the description for mem_cgroup_print_oom_context. Changes since v7: - add the constraint parameter to dump_header and oom_kill_process. - remove the static char array in the mem_cgroup_print_oom_context, and invoke pr_cont_cgroup_path to print memcg' name. - combine the patchset v6 into one. Changes since v6: - divide the patch v5 into two parts. One part is to add an array of const char and put enum oom_constraint into the memcontrol.h; the other refactors the output in the dump_header. - limit the memory usage for the static char array by using NAME_MAX in the mem_cgroup_print_oom_context. - eliminate the spurious spaces in the oom's output and fix the spelling of "constrain". Changes since v5: - add an array of const char for each constraint. - replace all of the pr_cont with a single line print of the pr_info. - put enum oom_constraint into the memcontrol.c file for printing oom constraint. Changes since v4: - rename the helper's name to mem_cgroup_print_oom_context. - rename the mem_cgroup_print_oom_info to mem_cgroup_print_oom_meminfo. - add the constrain info in the dump_header. Changes since v3: - rename the helper's name to mem_cgroup_print_oom_memcg_name. - add the rcu lock held to the helper. - remove the print info of memcg's name in mem_cgroup_print_oom_info. Changes since v2: - add the mem_cgroup_print_memcg_name helper to print the memcg's name which contains the task that will be killed by the oom-killer. Changes since v1: - replace adding mem_cgroup_print_oom_info with printing the memcg's name only. include/linux/oom.h | 10 ++++++++++ kernel/cgroup/cpuset.c | 4 ++-- mm/oom_kill.c | 37 +++++++++++++++++++++---------------- mm/page_alloc.c | 4 ++-- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index 6adac113e96d..3e5e01619bc8 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -15,6 +15,13 @@ struct notifier_block; struct mem_cgroup; struct task_struct; +enum oom_constraint { + CONSTRAINT_NONE, + CONSTRAINT_CPUSET, + CONSTRAINT_MEMORY_POLICY, + CONSTRAINT_MEMCG, +}; + /* * Details of the page allocation that triggered the oom killer that are used to * determine what should be killed. @@ -42,6 +49,9 @@ struct oom_control { unsigned long totalpages; struct task_struct *chosen; unsigned long chosen_points; + + /* Used to print the constraint info. */ + enum oom_constraint constraint; }; extern struct mutex oom_lock; diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 266f10cb7222..9510a5b32eaf 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2666,9 +2666,9 @@ void cpuset_print_current_mems_allowed(void) rcu_read_lock(); cgrp = task_cs(current)->css.cgroup; - pr_info("%s cpuset=", current->comm); + pr_cont(",cpuset="); pr_cont_cgroup_name(cgrp); - pr_cont(" mems_allowed=%*pbl\n", + pr_cont(",mems_allowed=%*pbl", nodemask_pr_args(¤t->mems_allowed)); rcu_read_unlock(); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 84081e77bc51..4e18b69fd464 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -237,11 +237,11 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, return points > 0 ? points : 1; } -enum oom_constraint { - CONSTRAINT_NONE, - CONSTRAINT_CPUSET, - CONSTRAINT_MEMORY_POLICY, - CONSTRAINT_MEMCG, +static const char * const oom_constraint_text[] = { + [CONSTRAINT_NONE] = "CONSTRAINT_NONE", + [CONSTRAINT_CPUSET] = "CONSTRAINT_CPUSET", + [CONSTRAINT_MEMORY_POLICY] = "CONSTRAINT_MEMORY_POLICY", + [CONSTRAINT_MEMCG] = "CONSTRAINT_MEMCG", }; /* @@ -421,15 +421,21 @@ 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), nodemask=%*pbl, order=%d, oom_score_adj=%hd\n", - current->comm, oc->gfp_mask, &oc->gfp_mask, - nodemask_pr_args(oc->nodemask), oc->order, + 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, 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(); + + /* one line summary of the oom killer context. */ + pr_info("oom-kill:constraint=%s,nodemask=%*pbl", + oom_constraint_text[oc->constraint], + nodemask_pr_args(oc->nodemask)); + cpuset_print_current_mems_allowed(); + pr_cont(",task=%s,pid=%d,uid=%d\n", p->comm, p->pid, + from_kuid(&init_user_ns, task_uid(p))); if (is_memcg_oom(oc)) mem_cgroup_print_oom_info(oc->memcg, p); else { @@ -973,8 +979,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message) /* * Determines whether the kernel must panic because of the panic_on_oom sysctl. */ -static void check_panic_on_oom(struct oom_control *oc, - enum oom_constraint constraint) +static void check_panic_on_oom(struct oom_control *oc) { if (likely(!sysctl_panic_on_oom)) return; @@ -984,7 +989,7 @@ static void check_panic_on_oom(struct oom_control *oc, * does not panic for cpuset, mempolicy, or memcg allocation * failures. */ - if (constraint != CONSTRAINT_NONE) + if (oc->constraint != CONSTRAINT_NONE) return; } /* Do not panic for oom kills triggered by sysrq */ @@ -1021,8 +1026,8 @@ EXPORT_SYMBOL_GPL(unregister_oom_notifier); bool out_of_memory(struct oom_control *oc) { unsigned long freed = 0; - enum oom_constraint constraint = CONSTRAINT_NONE; + oc->constraint = CONSTRAINT_NONE; if (oom_killer_disabled) return false; @@ -1057,10 +1062,10 @@ bool out_of_memory(struct oom_control *oc) * Check if there were limitations on the allocation (only relevant for * NUMA and memcg) that may require different handling. */ - constraint = constrained_alloc(oc); - if (constraint != CONSTRAINT_MEMORY_POLICY) + oc->constraint = constrained_alloc(oc); + if (oc->constraint != CONSTRAINT_MEMORY_POLICY) oc->nodemask = NULL; - check_panic_on_oom(oc, constraint); + check_panic_on_oom(oc); if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task && current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) && diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a790ef4be74e..892f51e630c8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3416,13 +3416,13 @@ void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...) va_start(args, fmt); vaf.fmt = fmt; vaf.va = &args; - pr_warn("%s: %pV, mode:%#x(%pGg), nodemask=%*pbl\n", + pr_warn("%s: %pV,mode:%#x(%pGg),nodemask=%*pbl", current->comm, &vaf, gfp_mask, &gfp_mask, nodemask_pr_args(nodemask)); va_end(args); cpuset_print_current_mems_allowed(); - + pr_cont("\n"); dump_stack(); warn_alloc_show_mem(gfp_mask, nodemask); }