From patchwork Tue Jul 10 10:19: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: 10516797 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 D4CDD6032A for ; Tue, 10 Jul 2018 10:20:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C481028BB7 for ; Tue, 10 Jul 2018 10:20:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B862828D00; Tue, 10 Jul 2018 10:20:19 +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 0CAD828CF3 for ; Tue, 10 Jul 2018 10:20:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3D446B0273; Tue, 10 Jul 2018 06:20:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DED696B0274; Tue, 10 Jul 2018 06:20:06 -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 CB6876B0275; Tue, 10 Jul 2018 06:20:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 8A70B6B0273 for ; Tue, 10 Jul 2018 06:20:06 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id a12-v6so13611408pfn.12 for ; Tue, 10 Jul 2018 03:20:06 -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=x/MBL0tIfUBBDNjUvuXx8NnFcaBIN8co3DbDxNitGGc=; b=fmhko6mPkMA6Q9ZREVk3k6bF0ZjWt0+/ll/GZTUmJJc6UUaL7mgO+VTY38GQbeWIB6 EH2YmMwE7SVdx16/EobCvbDm25VlCzQYglkk52LssWWUEPjfWe5m1exHhHngA5z2Q1Xb dWUUg3AjRR4egvqmxgJoru5vZSRlXiBWH8pxSh4wUeLt8veLbAVxOGNbqdlfIkoLuhaw tfNSZ5ngHmvb5d4JmMDU1z87gTB4YADYhujW+l2yC9Fl5cIefl7kIjXhpowglOlAx3t0 mmghPpM11Y4hCpllx3ECqPtoFUOfMeHUWu8chxwRMbEjK/VgTpu7WzSt7F8+3lgrcVPz qNgw== X-Gm-Message-State: APt69E39YEmS1E7RouMohI1eG2hk3YHR6FAgSbqgzG4PwPUlO8/dy6wJ p08XGnUipdidCmWtxcdtMRbzZwwfx+pTJ1iGfNJXjt2Y190mZ/2ALEA5CByScs+mfECo5+Ai3Np TXUIQe/UkrITWhqzMNBZWBMxJyVF7D2jalxlpayX9tzJcg/J9aRamB70ki0O5hEFLjWORdHPXKf QyMQxyq2Fe3KJrcWYa44TYwofG6I7VcNX+GhKeZ1D+Gh1tac4nRW02VhvX4QVcpalh3Gl3HXLO8 YPQJhb6nzqH5+2wh33v34kUK68GMIARz3V8vHoiHYvfWG9/13BBRzW7KU8AHNinHfsLORmGyJRa +xoEBeCp1Nw2A+N1/yyKH2fQY6y4Gknr87dwqNnrYRN76Lx9O37gvcaZ1TBWfu3pwbP0IkBmjJm P X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr23984586plg.135.1531218006228; Tue, 10 Jul 2018 03:20:06 -0700 (PDT) X-Received: by 2002:a17:902:622:: with SMTP id 31-v6mr23984535plg.135.1531218005289; Tue, 10 Jul 2018 03:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531218005; cv=none; d=google.com; s=arc-20160816; b=KBzfNOmageb4hDivF5bERrCd2qf72OF5LRjqQuTnFMFRoSYPE6g/yTLeSDwRhDOoF1 380+ZkhaUG05/18FAjENRpl0x9hcJ43BxZrM7oqbXM8XAf7iOxY4/jxS/ZURXbQ8x4ob CBpE4a8Y/v1zlmfdsYOvZwe1IpzLn/4IBKtH7c+aRyaYyZC9FfIqegZWPMnzTupJ5G9c pdIDqM/IGuhIKoYkimFmwzh8qFysqpWR9TsCj4rqwSVwbfjGHNY4Yjx6wez9ronjn1DD FTWkz06230RmBWKODnASaFsQk9sTKKqTMUkf//BiRu0WsI26Iq/aG3SJ8SAluJD5NjTR AM4A== 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=x/MBL0tIfUBBDNjUvuXx8NnFcaBIN8co3DbDxNitGGc=; b=tMY6rnXq0d/EMO2sz1c/FHzgVL3js+MXM3IjW4QYuJ80Gzz6rGoZfIc/eQAUp67gbl 6mKvap19OQKUPsDyHzaJsPg2C6uOF3CAlglZflEYcqs+dC3lQFwEQIuClfsE1cdy9OMo dw6UgUFLBgcrvCKd48jADjd/kY/ZqXl82MwPJ7X6YuKe3J68ctVXQptINzFjrNh5U2h6 DAAAkc/JQXVI3+TwalhNaIAfyjBoLveU5nWEHsMzhvtnLRBml8CWK0C338fU5x9G1O7l jGhCEFiYcWtLgQsjT9/RMuy7dAWjFrT8YcP0qkfN1GVu2uBFi0jtZVDYQAo7rpba0VXX Fy0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j4pgWc5K; 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 u22-v6sor5353399pfh.19.2018.07.10.03.20.05 for (Google Transport Security); Tue, 10 Jul 2018 03:20:05 -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=j4pgWc5K; 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=x/MBL0tIfUBBDNjUvuXx8NnFcaBIN8co3DbDxNitGGc=; b=j4pgWc5KeEB12wrDfls/XZTYh5etoSpD17AoPwHqD9ppTvA+ZMDVARpeoItLImfH0f EK2Hj5PzIGmoxEFZ2was9F0ytvf7S7EOx+qVcixYXpWrLEJ41fNP39PoHAdwZzrmAv3A 0fHm5EcV3+MFq3fCenJJDs/lE22cFjpEqDR7Nr7jXZGfCxtPXX60b2IsMHWzti2HLoXG MeTcsQnXUIrn+krGWkdJiPlA8pz9TJoDrMQBkhrS7g560g0krwCuMKn1jilateKmLbLq 8eLlSfS4VC1o5AuNjajyLaeILHbi5heSmYDXgNvFEhd8/fp7qdKD8n6RrD+Od422MaJI BiEA== X-Google-Smtp-Source: AAOMgpeQHSD0Bwz08towpSVzC8NL8eW6L6u5VFKrRgT6z7htIeSsf5R0dEvofkA4a7a5n2+ZtQ2/Qw== X-Received: by 2002:a62:8917:: with SMTP id v23-v6mr25236473pfd.127.1531218005030; Tue, 10 Jul 2018 03:20:05 -0700 (PDT) Received: from dest.didichuxing.com ([168.63.150.120]) by smtp.gmail.com with ESMTPSA id k4-v6sm24213518pgo.49.2018.07.10.03.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jul 2018 03:20:04 -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: Tue, 10 Jul 2018 18:19:48 +0800 Message-Id: <1531217988-33940-2-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1531217988-33940-1-git-send-email-ufo19890607@gmail.com> References: <1531217988-33940-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=,global_oom,task_memcg=,task=,pid=,uid= - memcg oom context information: oom-kill:constraint=,nodemask=,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 531b2c86d4db..9e80f6c2eb2e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -433,11 +433,12 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) pr_info("oom-kill:constraint=%s,nodemask=%*pbl", oom_constraint_text[oc->constraint], 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())