From patchwork Thu Jul 5 13:20:29 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: 10509143 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 0F379600F5 for ; Thu, 5 Jul 2018 13:20:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F137028F65 for ; Thu, 5 Jul 2018 13:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4C3C28FA6; Thu, 5 Jul 2018 13:20:49 +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 67F1028F65 for ; Thu, 5 Jul 2018 13:20:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46E6E6B0007; Thu, 5 Jul 2018 09:20:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4456C6B0008; Thu, 5 Jul 2018 09:20:48 -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 35C0C6B000A; Thu, 5 Jul 2018 09:20:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id EB6296B0007 for ; Thu, 5 Jul 2018 09:20:47 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id b5-v6so4932062pfi.5 for ; Thu, 05 Jul 2018 06:20:47 -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=5tRonMk7uvKJ9ue4p1e3aU3iZ3FZzpu4+uTRzSG0Cw8=; b=V+t1URMNfiAUqNiu5Yaf7oxFlnSv32OJGeKqW4Zoai4y50e7f9f2kDg+Bf4H5n2S8Q KBHW3VLAps2jFOzjfsuVaynjeE3cC5kuWW9p6w96HEZr/H5HcIcnKT29bnxh63tWeZVQ KRjWPqkzJMkEIAhtgoDttjIKIXZyonzXQTqzGtHr0svVf6cvdQF11TOLAsKl1274dRbC STLjKTN3Shd14M8yiI5RkjeDHGHQYPngGMUTTbQjW1ozX8LcftUrjbUqtLvVxDmUEm2d GqS86N9rZzvONbgFyVswhV94W0oHc+88YZSiDO7lM+rHX0PdzoXQfjaBtyvOzH4X6T5y SV9g== X-Gm-Message-State: APt69E1YP5QoKWmJuy0ST0qeTVmeoUrPYBMul9FxsEDx8FiUvAgUtgAv /lcpkKzVK9bgb9sIuioh/ApQIMtUhISnJ/+t2oFWZHjDkPf+VdAKx1/VJf/DFz9+WN3qIcJ/+L9 8IVPHyS8A/01GgZi7sYRHZA24aND2w37XbkUPEi4EGVeVo6gIsz9KZKvVcPoaFmQkCXxOTqcc/p qHOek2lVIoN2r7WAVIy3ZsKzOL9fK/cyiOBWxwWDvLYPI6G29PK3J2StYBfE7LXkObnprzzu3nh iFw9WiA0GWLfE+tcOAAk92KmqP8GAEswPqxxu99WNBA8zSrKU76AKWHh2Ge713a9K+/L2ztt5Kz MI89nDXSpS8J3Wo5neIFaKJEROso77JmMPKJFv/1s8NbU3V4l5kKpeSmRuqpQZev5ur3HUtA0vK T X-Received: by 2002:a62:8d7:: with SMTP id 84-v6mr6438077pfi.172.1530796847596; Thu, 05 Jul 2018 06:20:47 -0700 (PDT) X-Received: by 2002:a62:8d7:: with SMTP id 84-v6mr6438032pfi.172.1530796846846; Thu, 05 Jul 2018 06:20:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530796846; cv=none; d=google.com; s=arc-20160816; b=W0LJyGjOyjM87nlvV0LC6rRj9zdC/iQj18GEJolh+q8fpGh/RIJSuTyV7a0eu+DEJU i3efZR4dT0iNblVGqp3sfUKJrq8rya/gnD37+RRmZ82Ymi+H1h8pWOBFKzPKYK/w+TFV E3SZls9TBUPd+mlaxWoyShV6OAvqpB2UJ8Z9g5fxE/lFt5itvWk9DhNXOnpY0DaLfcHC DzB7OwPQ9awZdpWTCx7p3t7proIUdNbmDRxdnzuHBc9eZ5lY2fRDhpaN8KQcpQHUF2/k 6iYwRqp2ZsDt0Lk8axHJzvv/4pg1iqS+diVZKk6xEDzL86dN02MFMXhChCRkXXT7HBtB R6Ag== 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=5tRonMk7uvKJ9ue4p1e3aU3iZ3FZzpu4+uTRzSG0Cw8=; b=bDz1MqP5sLJnGP5FTgjCkVerpr6UKzIHViDNHpYoHocR5Z2f96CdPtUjgNjfkGUXyi 1JVTy/caxGNcYsRVEK5ssT5UOBtOezZ1UNkB7nizCbt+AzfsUAmlJwRBxrtEPZFm+VeU VEslQ2AljhTNmy+EzLOVK/dYwGO359LH4uQJ+hfI7hXy3FgiR7g3SOdze3TmCHs+10rt QfFNbswenVCUMRTnMcsMKMuSKMWBIR2z7ShvUV+w+WPYUghYXDwIBQMODrU/n/AtkLol /7h92GB5lMNKIY8PlUv18bSwIVWij6wgJxl7tp/dP6BIhwtLfXwx20Vq8ZxBptRNszaI EjUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d8WNXXwN; 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 o6-v6sor1664096pgp.99.2018.07.05.06.20.46 for (Google Transport Security); Thu, 05 Jul 2018 06:20:46 -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=d8WNXXwN; 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=5tRonMk7uvKJ9ue4p1e3aU3iZ3FZzpu4+uTRzSG0Cw8=; b=d8WNXXwNbcSs7bipZ0iUwosJCOxgPdpRJVXrQtCvOnjlGrnlncQfm4GKtXJiGITgy9 NucgkNwM0fvE92G1whjf012aRvvs3KH4TMb0ewKzNRpErRssXfbiWhQ/rZIym/Gs6jvc QWfrmqdXvUt40rqJIi+lriNz/+UJiAAZfHc6R5qAsb+Gv79EkwiaR50WcPQOXZT8YUzd u/dRLn5N6aE8s0Ot1ToySB1t8wfODMeetQOymvrP0LQlWeq3JZrqSf7NiMo2Xx5YKQwr dLnfzZBwCy7mHtv/VgKHxua2vkNAQqS47vaoBqtbevlEf7lYGRLqJNBj70XtA1sP8MD5 +PsA== X-Google-Smtp-Source: AAOMgpe3pzorI3XiyE24gT5FbraSmWaY34XmoPcA0biy61kuylLVndIDkyIz6cdMzSS9JFwy5FL7SA== X-Received: by 2002:a65:5141:: with SMTP id g1-v6mr5582700pgq.418.1530796846598; Thu, 05 Jul 2018 06:20:46 -0700 (PDT) Received: from dest.didichuxing.com ([168.63.150.120]) by smtp.gmail.com with ESMTPSA id b1-v6sm1150111pfa.181.2018.07.05.06.20.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 06:20:45 -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 v12 2/2] Add the missing information for the oom report Date: Thu, 5 Jul 2018 21:20:29 +0800 Message-Id: <1530796829-4539-2-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530796829-4539-1-git-send-email-ufo19890607@gmail.com> References: <1530796829-4539-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. Signed-off-by: yuzhoujian Acked-by: Michal Hocko --- include/linux/memcontrol.h | 14 +++++++++++--- mm/memcontrol.c | 36 ++++++++++++++++++++++-------------- mm/oom_kill.c | 10 ++++++---- 3 files changed, 39 insertions(+), 21 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 c38f224b0d9e..9e80f6c2eb2e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -430,13 +430,15 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) dump_stack(); /* one line summary of the oom killer context. */ - pr_info("oom-kill:constraint=%s,nodemask=%*pbl,task=%s,pid=%5d,uid=%5d", + pr_info("oom-kill:constraint=%s,nodemask=%*pbl", oom_constraint_text[oc->constraint], - nodemask_pr_args(oc->nodemask), - p->comm, p->pid, from_kuid(&init_user_ns, task_uid(p))); + nodemask_pr_args(oc->nodemask)); + mem_cgroup_print_oom_context(oc->memcg, p); cpuset_print_current_mems_allowed(); + 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())