From patchwork Fri Jul 13 11:55:52 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: 10523121 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 B8C5E6032C for ; Fri, 13 Jul 2018 11:56:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A70A929A0C for ; Fri, 13 Jul 2018 11:56:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B33C29A4F; Fri, 13 Jul 2018 11:56:07 +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 C69C029A0C for ; Fri, 13 Jul 2018 11:56:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE9B86B0003; Fri, 13 Jul 2018 07:56:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A9A0B6B0006; Fri, 13 Jul 2018 07:56:05 -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 9B1726B0007; Fri, 13 Jul 2018 07:56:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 591D56B0003 for ; Fri, 13 Jul 2018 07:56:05 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id j25-v6so20608256pfi.20 for ; Fri, 13 Jul 2018 04:56:05 -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=iY9vtiCUoNjcIBjXS93SLPG9IVxANB8ZjhPGf1wvAus=; b=D6W95DO0S3jZPv9ak4tuFa/WONxna89Ai4/X2voJ2mlk2B1NWSs/zJJ3JL8FwhE/Rq MI/gLGQFqs1nk4LJfYLD4Mu6NfnWz5k1eYzO82p+2J0PTQriQrOzEH+liZw2NosJuA/R FhvqFvnJ65EfUr9Jhlh2zsjuTAXhzdG5Dcj0FLfT6/y0T7+gcdpOhBHejHCqL+PRn0Ha or5aNNpRCoakduCf2exZu30zeIkA4mGgimS4EFabQQr2z4OBBOylu6WjD6r4oOBznmvb BJvWalGaNg5Nu6yX23igPyrM4DDFOpVDsH3LUqBeOqGP7U1Li9daHBck2yHyt0WjVivv Lrag== X-Gm-Message-State: AOUpUlGEa5BB8rq61yxh0nUTghyLCzslpoyH07frHzajzx04XnFb+ocu SiDdLT6hNdSBNTsMWZu5D1YRhhnbgql/PxgSGtaIGAI5ebPmxQDqSb2MR92sOxkzdYFUZGuf1ny 0MR9HAlRv5bMrtLS1yTF/+jAdIf/NlnYXz2QIzCI4l7++/N3wriJmTWtFwRWrCDWSmRwife7WmH S57wRZSeQM38r9jlhKPnEyd4es88FI6W94pfCLiNCL2dL/BYDmOqSKl0kG63BLs/0YKhzsX08A9 auIXaYQu+PbI+fKqSb6ezJctO+NqHZ7Z/YCN2tk42MwA5aeskrKDnfcc+bsZx7IWlYSnQ8o7GjY BoStgHpp6FSmLZVszZKt7mgGxz5eo91fuxQ5BxINTwhZD6OdWz5huioXWia1b6Q/IN5siJdk6Jr G X-Received: by 2002:a63:714a:: with SMTP id b10-v6mr5651160pgn.73.1531482965027; Fri, 13 Jul 2018 04:56:05 -0700 (PDT) X-Received: by 2002:a63:714a:: with SMTP id b10-v6mr5651117pgn.73.1531482964069; Fri, 13 Jul 2018 04:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531482964; cv=none; d=google.com; s=arc-20160816; b=HBwbxW8//Y4pSzm9aDHXLvm06GSzPunt7yNKtTVf6XjZ4VT/Wo58/B7mczvoNpwPyc 6k5fQYNELEIOIc7BJg0C+K+tL9zUDEH8O5Xp7AQqBszlr/nVWXrrB2V6f5+GwSyHJRgb uC+k5Ld1nkBEnWGh+DYq/DOO5Td57Jt6dku4vaMHmp4Yw69sBvfmdz7dK3ahViG0mwDd 3cPZwOZ+NRmo/IK2Kgdo9NrBqMRWEb6F3CiL34b8qg/b2X1HKfhO0yU7R+MCcnL/LKWr rZYL+tW+Pmaz3bxbioV7KjIFddFXnPXHuyLttk0pzoAH0kEZ8k51YHvAb2DzopsA0fwl Pwpw== 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=iY9vtiCUoNjcIBjXS93SLPG9IVxANB8ZjhPGf1wvAus=; b=KdYR19qTL+6RRBOv0zYtdptNaU9QwfrhxjdKVztzmyjq+uo7Ykz0dBSGQ5cveOesT4 4Q/+LUSQaGaydAqgjI0n5XN723LLOy+/a3KLFRKtcZ7U6Nk/+qZSevE3NLylw7V7METp 0OiwnLwxBrqqv+dtONDaPsukelTLwp57qx9LjMD+FZ3sUCiYDMSC+gmCw9fqpOak1XHf 5WcFA/Xee3LzqKeIe4zc6s4EYZTFfaP7BogwTyiHzQlluFyZ905R2qK9c168Oc4pmzbF iMRoIGX4pTK3dshsxcPobwsno6NIn1dzeRegDDsvqmYKsgfyEuSaC2fssfCbrrZZ6igp 42Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MD9TmxyS; 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 x202-v6sor6062848pgx.300.2018.07.13.04.56.03 for (Google Transport Security); Fri, 13 Jul 2018 04:56:04 -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=MD9TmxyS; 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=iY9vtiCUoNjcIBjXS93SLPG9IVxANB8ZjhPGf1wvAus=; b=MD9TmxyS2dy8NaW3NtsgHBLYhFW1s8xB21vKONdou5jH8tsZrTOuQvKq5fbr4UR50r IC0HM48WybX2UiVhoY1GH3zX+f94c1YEZVHTmoIVylOu3a9m/gFaofrfQ/NQApZQPh5V Uh0149TFFmoqS6Fwp/k/8fuDxnfMafYOHoqD2WQqHirkh00HKrXbXALXaXTcseHejFtg m2puR+MysOiwNImeTnSikWdbywZkgrIy0qVPMrCKBloehqGq/ARX1/MBTqcO/uO2ahYh A69Z/TKOoTs8Iz6B0DhVdnG9yNhT33357U1Uy8jVLTrc4m7+BrcFgyP8M0Pcvui4ksb9 L8xg== X-Google-Smtp-Source: AAOMgpdnUm64OvF+WH0mfMN5fcUDjwOpSU5BSCM5lb3/v3koGuxkKIh0hkFkXlf5GDZfUsSoUoTtcg== X-Received: by 2002:a65:608c:: with SMTP id t12-v6mr5938950pgu.159.1531482963736; Fri, 13 Jul 2018 04:56:03 -0700 (PDT) Received: from dest.didichuxing.com ([168.63.150.120]) by smtp.gmail.com with ESMTPSA id z8-v6sm3650447pfe.163.2018.07.13.04.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 04:56:02 -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 v13 2/2] Add oom victim's memcg to the oom context information Date: Fri, 13 Jul 2018 19:55:52 +0800 Message-Id: <1531482952-4595-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 The current oom report doesn't display victim's memcg context during the global OOM situation. While this information is not strictly needed, it can be really helpful for containerized environments to locate which container has lost a process. Now that we have a single line for the oom context, we can trivially add both the oom memcg (this can be either global_oom or a specific memcg which hits its hard limits) and task_memcg which is the victim's memcg. Below is the single line output in the oom report after this patch. - global oom context information: oom-kill:constraint=,nodemask=,cpuset=,mems_allowed=,global_oom,task_memcg=,task=,pid=,uid= - memcg oom context information: oom-kill:constraint=,nodemask=,cpuset=,mems_allowed=,oom_memcg=,task_memcg=,task=,pid=,uid= Signed-off-by: yuzhoujian Acked-by: Michal Hocko --- Changes since v12 - print cpuset information before memcg info. include/linux/memcontrol.h | 14 +++++++++++--- mm/memcontrol.c | 36 ++++++++++++++++++++++-------------- mm/oom_kill.c | 3 ++- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 6c6fb116e925..96a73f989101 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -491,8 +491,10 @@ void mem_cgroup_handle_over_high(void); unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg); -void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, - struct task_struct *p); +void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, + struct task_struct *p); + +void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg); static inline void mem_cgroup_oom_enable(void) { @@ -903,7 +905,13 @@ static inline unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg) } static inline void -mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) +mem_cgroup_print_oom_context(struct mem_cgroup *memcg, + struct task_struct *p) +{ +} + +static inline void +mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e6f0d5ef320a..18deea974cfd 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1119,32 +1119,40 @@ static const char *const memcg1_stat_names[] = { #define K(x) ((x) << (PAGE_SHIFT-10)) /** - * mem_cgroup_print_oom_info: Print OOM information relevant to memory controller. - * @memcg: The memory cgroup that went over limit + * mem_cgroup_print_oom_context: Print OOM context information relevant to + * memory controller. + * @memcg: The origin memory cgroup that went over limit * @p: Task that is going to be killed * * NOTE: @memcg and @p's mem_cgroup can be different when hierarchy is * enabled */ -void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) +void mem_cgroup_print_oom_context(struct mem_cgroup *memcg, struct task_struct *p) { - struct mem_cgroup *iter; - unsigned int i; + struct cgroup *origin_cgrp, *kill_cgrp; rcu_read_lock(); - + if (memcg) { + pr_cont(",oom_memcg="); + pr_cont_cgroup_path(memcg->css.cgroup); + } else + pr_cont(",global_oom"); if (p) { - pr_info("Task in "); + pr_cont(",task_memcg="); pr_cont_cgroup_path(task_cgroup(p, memory_cgrp_id)); - pr_cont(" killed as a result of limit of "); - } else { - pr_info("Memory limit reached of cgroup "); } - - pr_cont_cgroup_path(memcg->css.cgroup); - pr_cont("\n"); - rcu_read_unlock(); +} + +/** + * mem_cgroup_print_oom_meminfo: Print OOM memory information relevant to + * memory controller. + * @memcg: The memory cgroup that went over limit + */ +void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) +{ + struct mem_cgroup *iter; + unsigned int i; pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memory)), diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 531b2c86d4db..7fbd389ea779 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -434,10 +434,11 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) oom_constraint_text[oc->constraint], nodemask_pr_args(oc->nodemask)); cpuset_print_current_mems_allowed(); + mem_cgroup_print_oom_context(oc->memcg, p); pr_cont(",task=%s,pid=%5d,uid=%5d\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); + mem_cgroup_print_oom_meminfo(oc->memcg); else { show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask); if (is_dump_unreclaim_slabs())