From patchwork Tue Jul 17 11:05:48 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: 10528967 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 97EDF600F4 for ; Tue, 17 Jul 2018 11:06:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8494428C3B for ; Tue, 17 Jul 2018 11:06:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7834928AEF; Tue, 17 Jul 2018 11:06:09 +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 DC05728AEF for ; Tue, 17 Jul 2018 11:06:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D972C6B026B; Tue, 17 Jul 2018 07:06:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D1D4C6B026C; Tue, 17 Jul 2018 07:06:07 -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 BBF3A6B026D; Tue, 17 Jul 2018 07:06:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 79E396B026B for ; Tue, 17 Jul 2018 07:06:07 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id g5-v6so313488pgv.12 for ; Tue, 17 Jul 2018 04:06:07 -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:in-reply-to:references; bh=98aunOgdIZ+Da1fqkL4HwjdfG3ncTDJtNSrUoK6+k1k=; b=So1bPFNttDo9hoLE1ZzWgU1spdsLvLxIlsm86ZFrzC1r+EBDSmTCpaunA9CZMVhlUR YzJAPCoHcP1mZ8uuFm8ODXLZnZSfoOKRFauk62CAqsTnpf5T2hfF3QDCvSVca3oVGLEZ HpPDl9dzmoO6TMdSBDyTm1bbL5HFUsOUOQ2eQII5+CiZiP90QUX3oov1pwbYY3MRAY62 pvQCmYHsWAu77ze6a0YeUzNpxUmhIpmCbimp1THMCYi0btp/IL2e9Y3wgxaswHoS7s2A N1IY0RWnHkWC4ZdTaBiZ9scL+/lWee4w5uY2oyKvxfP/m/SZUJ030vfFXZbHVEME6+rv wl0g== X-Gm-Message-State: AOUpUlGxAYoLhNCn0c75R2Q6Owwp35xy2hI2tAD0rRz8ADCngDTzr76a 23ealSPSvHgI4RO45oefCGW2rgh8lwn1wJ24k+b4m85Ug3buOISq5+bFUvpcRqBnnI35CbBN33A iqyjRian8hP2AQCD9n8TqvHSVamOKgxDZb/l9bdmqhfEqbPoVJTapYM0bkN8scDw4YBSr1pRzIJ 5nGNCc+lqo+b9yPuzDpodMuEcOhTF4MhUamG+VTfEu332jU4ymAmefK1A+JEoLQ/9LnEj2YsCPL Uo2bndeaVojb6cxIl/79mJ7eSDmVMhvKR0k0Az6/lHFPA+7WeDD5S6vUHfnbI0lJJiqMbWDNUgm 2E/Mokm3QKX78ADYRRCpq5COgN9c6EY6Cyts1ZnJTb54sGI7cSvbrJc1lU4j/EBivDEIAOxLVJR q X-Received: by 2002:a65:4c41:: with SMTP id l1-v6mr1182336pgr.310.1531825567173; Tue, 17 Jul 2018 04:06:07 -0700 (PDT) X-Received: by 2002:a65:4c41:: with SMTP id l1-v6mr1182287pgr.310.1531825566279; Tue, 17 Jul 2018 04:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531825566; cv=none; d=google.com; s=arc-20160816; b=NFMGMhXoP8vd2PXkUFkVuytSd+RUvfX4WXCmID8Y+q/lU6hJ1StPxlAUk8f2kMy0+J nYqI824nYcVcqlroY6Cvr8iWm9jT4AoFsPxjKrGTOTFvvJTqDzzXteKReszacESCDr6D 8ROWYXsnWnrSUeXdcR199G9Kpg9OqbQjwCPLNgU9l8RyX/GcGelZ6lksZXxIvzVxd/3q QOPzscRDjimVTZ70tOE/mC8GWHvY6+eGxp4NswDvYWpbET95v9OioVyF+Uggn7sWV4gp 9bBNpoCM1/Bye+u2LuMiK4tF3AZ0AzctPaKRq2BaAA7K6A3Rj0mtoSTvApD6TCXY4UG+ SqzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=98aunOgdIZ+Da1fqkL4HwjdfG3ncTDJtNSrUoK6+k1k=; b=ysaZ4LPKa7W2/nqUZcVkDc0Gnscx0+CaIDHuL5hwyhsoofKM0kRnL9FZQ+iT1jD35j stkYnrixbsWlw+t+0rrGqKSNrZxvFinQGcuwex1PSVs/BV7s7/NGnym32gSK+56rL2Zl ycKpNKmrZz+qd9iqp5LSuDpj3id7iZRJtex3JsD9efI7d05c2vOrHDvsVYGCQNHPuT6W 9i4WYKHqX/aHE5yYSvUqegkobhzHMQ636u0T7qja4J4iP9mzGNtzS3LIkU5wbyO2wSyb iOizKZ01WzB28IchT7Wsnly7EbggjIqqsXhXgpmdOkoj8Oz9rxHFUTaM3ZS40sW6J2xt 9kNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=koaDy+5A; 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 d1-v6sor186385pge.309.2018.07.17.04.06.06 for (Google Transport Security); Tue, 17 Jul 2018 04:06:06 -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=koaDy+5A; 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:in-reply-to:references; bh=98aunOgdIZ+Da1fqkL4HwjdfG3ncTDJtNSrUoK6+k1k=; b=koaDy+5AYIz9MQW/WY1NUGQt7o3WD2F3ZY+0SR7Wl1XRHi+X5JcAgysRBoHCxlhYah JbimJpnanJWDEja85VtredjCfumtKNEFZmSZ3zBHRlxZShv9EnQdOiceC+zbGYUKXtJF IaAtzSYC9XtrFEbwMBkQsyGP/UKQZQ2b1Lwq6f1jHeWaT5TQ9gP+UZ2qtrmATP1DD1CU sJuXz4g4+sNA52ASld6Al9rvwXBXwMBjglUi46BPCG3hQsyTlhkY4BqD/wE9iRlR3+e2 cbBIMYilBOzyNACz66Y5yQgjKqHColLGXPQerxi4IdnMBu4Zahl4ZTguHHlTf4dZUnBH dbHQ== X-Google-Smtp-Source: AAOMgpczk/w1G76vRmUUkYmjGgxVWQ71v7yyxplV4HL4zYOMSNUSSKobGydMSgZRCl6yWTZA8CW4tw== X-Received: by 2002:a63:8f03:: with SMTP id n3-v6mr1169149pgd.166.1531825566027; Tue, 17 Jul 2018 04:06:06 -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.06.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:06:05 -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 2/2] Add oom victim's memcg to the oom context information Date: Tue, 17 Jul 2018 19:05:48 +0800 Message-Id: <1531825548-27761-2-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1531825548-27761-1-git-send-email-ufo19890607@gmail.com> References: <1531825548-27761-1-git-send-email-ufo19890607@gmail.com> 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 --- 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 4e18b69fd464..4f3e4382900f 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=%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); + mem_cgroup_print_oom_meminfo(oc->memcg); else { show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask); if (is_dump_unreclaim_slabs())