From patchwork Wed Nov 21 11:29:59 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: 10692457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 271AA13BB for ; Wed, 21 Nov 2018 11:30:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 155F42B6CF for ; Wed, 21 Nov 2018 11:30:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A1162B611; Wed, 21 Nov 2018 11:30:21 +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 6D39A2B6CF for ; Wed, 21 Nov 2018 11:30:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B3F66B260A; Wed, 21 Nov 2018 06:30:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 362996B260B; Wed, 21 Nov 2018 06:30:19 -0500 (EST) 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 253746B260C; Wed, 21 Nov 2018 06:30:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id D02036B260A for ; Wed, 21 Nov 2018 06:30:18 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id e68so7443865plb.3 for ; Wed, 21 Nov 2018 03:30:18 -0800 (PST) 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=ylCHwBAJTmPIaOdxe6D4qpf2xk7cxDYmrUoJdcdixoc=; b=D+Zy3a6fMcIYclwRdQADrsjsV0G/0wPfmvJ3G4cf04q6dW5M9vuBDwLT2v3DXQVrPr r4+1OlY4c5WA1LTt578fzS8x+x0ws1e+BKjo0D8NIpRjpcXa6LZgiyzKY2bklX2/zXzU yrTQYn21EXGmqwnw3vG2D0UQ+3FdT0ICj2mAbt4zCYHQcaD7ckOGr2eEQraf+46Q32nL +kgnzrpUfeseMxsW8QghjlYoF8NFWOKd6XLDXqlseIzEUenM0koHnVS7MS1nbVWm3E1W YMpyzPAgvnGJTP38eQGjriRLIsFnOHsEDzomUnFpR7gF/5o0GWREuGyomSY+cpiyYaCR tCjg== X-Gm-Message-State: AGRZ1gI/0lxDTQ/XruJK0hEcoFagP5mgbgHccC3tKFGCEfm/+cuzSaeI se2pibup46P3KtFV0m/OPUwzfdrwDltJWvZr109tHvcRaDbBsUdyu4d2JJmFLWQLYwYER6Zlw73 hIiK0pT45pobNd31S2Darzr/j1MZZp44D7+IzZGzsL7AnQjXOgbr3d5ZXMnEKu6QkjHfDIu2wXt znjfAMsYVGZ4Klt8PmiCHV6EXk7JYfstRjVni03q5GuU4+MjNr39LIra4Xal+I83ci3ELmoEp4c sOADdk3v0MsmiiR52pKVtvghzawfRr9rLhxD4vTD4W3i8GdbbV5NSt38Ssg55S7kfsx9yYMbH6G h/BTLUxA9E0noB3X5a6VmKJoX8ZhU1k7NXSt/ag86Axra2k8a2u0JL1Sln6UYEAGJwJQ7xCFTGz X X-Received: by 2002:a62:6181:: with SMTP id v123-v6mr6500994pfb.117.1542799818512; Wed, 21 Nov 2018 03:30:18 -0800 (PST) X-Received: by 2002:a62:6181:: with SMTP id v123-v6mr6500930pfb.117.1542799817672; Wed, 21 Nov 2018 03:30:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542799817; cv=none; d=google.com; s=arc-20160816; b=SH2troBtc5BO43kWNcxQ+3C6VR2zqD8hU09Xmlx/wleUMaIT27dMkOkqbVDYHAgPNw DV6Mghx2RquSIDFSU64dsvQmc1GuLwRcR4xESeZnX7JHDl4ifw3U8YOiWF7p3rAXlD/g zbHH+NETdyUTCO0ow/XBMXqcjyU7pFQIiWgUo6ZchEBI/7bYeUXDZd73jMrCT5iHZ+td O9EwYwRFldehjMWZfdG9zv/SOguHGDcO74Vxk78SzUowZx1pNAdW9F8kRfut0h1/6vks sPpwzPp0KO0foDlrGLRvr00LtNn1q0+JG33T+7lxzfjBh2euq0DznoW069Ms7Zgf4aw4 MXtg== 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; bh=ylCHwBAJTmPIaOdxe6D4qpf2xk7cxDYmrUoJdcdixoc=; b=yFSmtMNZVS88zlYFS7IytRZ/XpxCuVwujKeEKmNKNpZaOS/WoFYGg9WAg4a/1EzdbI qy5PwxDezFE9T2RelpToju4ah28wFDv1XOU31RFMy7mU7OkRqv74fa0ih0gqgDxpOL+q NbyrXfeO1G75Xb16cF3zfZG4/nrFrCt2j2cBl5Kr4ZUyOk6Q9R5RfCyD/pT6Ge96GsPc dXZ4w4dvSzFpwmda+6RTMkkK8XPvBhzUkEnv6lvIHd5kLMO9gzeqlve7G5WNHr0g5+6W s4pNJVAiovcwmK5NEdAX2hAD/c/15e2fHIy0rQ8HyEsnDP8Xi+K2PiO3ADr4WK74qJ6Y xHLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dE+70IAL; 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 p18sor53497064pgl.33.2018.11.21.03.30.17 for (Google Transport Security); Wed, 21 Nov 2018 03:30:17 -0800 (PST) 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=dE+70IAL; 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=ylCHwBAJTmPIaOdxe6D4qpf2xk7cxDYmrUoJdcdixoc=; b=dE+70IALVpR1aU8LFaUxI3u+s7wupMAQa3upaWdKnXgbxVyFfxyKO//GRnBuegoZ2Y RzbauJitgakVMQAezGHkgD+KFKpz1s+CJS2ltSbksoxKCx1wsYd8HAo22mXzK5329dcc BiJNqqCZ9X+jZYsetmrUjx1nJdsr5tzxoUlWPyYEljRnCGmuAxQ4fWyVUoG2yjIdQzLu BoMW2qY/deUCW2t4y6lqscI2ZDppauzhIAwiNz/DDlTfPXplzT6wnNzvg7L1/a2nZh7n UETEshCdL/CxujxniADeidHs34S5/Wg/0do6o98t/J92hGSAcgK0joD2dfjnHImykACG Znlg== X-Google-Smtp-Source: AFSGD/X350H88Q9Ed+EhlgoJgCIhKwnZEyF/GbEwylyRO1QpNSss3ZPhNMQ3CMjm2TM68Mw5R/gfqA== X-Received: by 2002:a63:ce50:: with SMTP id r16mr5569991pgi.217.1542799817296; Wed, 21 Nov 2018 03:30:17 -0800 (PST) Received: from dest.didichuxing.com ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id t13sm90753952pgr.42.2018.11.21.03.30.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 03:30:16 -0800 (PST) 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 v15 2/2] Add oom victim's memcg to the oom context information Date: Wed, 21 Nov 2018 19:29:59 +0800 Message-Id: <1542799799-36184-2-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1542799799-36184-1-git-send-email-ufo19890607@gmail.com> References: <1542799799-36184-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 Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Tetsuo Handa --- include/linux/memcontrol.h | 11 +++++++++-- mm/memcontrol.c | 33 ++++++++++++++++++++------------- mm/oom_kill.c | 3 ++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7ab2120..83ae11c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -526,9 +526,11 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec, unsigned long mem_cgroup_get_max(struct mem_cgroup *memcg); -void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, +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_enter_user_fault(void) { WARN_ON(current->in_user_fault); @@ -970,7 +972,12 @@ 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 6e1469b..b860dd4 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1293,32 +1293,39 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) #define K(x) ((x) << (PAGE_SHIFT-10)) /** - * mem_cgroup_print_oom_info: Print OOM information relevant to memory controller. + * mem_cgroup_print_oom_context: Print OOM information relevant to + * memory controller. * @memcg: The 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; - rcu_read_lock(); + if (memcg) { + pr_info(",oom_memcg="); + pr_cont_cgroup_path(memcg->css.cgroup); + } else + pr_info(",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 2c686d2..6fd1ead 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -435,6 +435,7 @@ static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim) oom_constraint_text[oc->constraint], nodemask_pr_args(oc->nodemask)); cpuset_print_current_mems_allowed(); + mem_cgroup_print_oom_context(oc->memcg, victim); pr_cont(",task=%s,pid=%d,uid=%d\n", victim->comm, victim->pid, from_kuid(&init_user_ns, task_uid(victim))); } @@ -449,7 +450,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) dump_stack(); 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())