Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp7134758imm; Sun, 20 May 2018 19:42:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq+rz4ibn+gPhBC/0UOtYio+xyRAtqj14YlTu95kGjhiBhE7BVP18OfmacMqYlrP1EeDYTW X-Received: by 2002:a17:902:3a5:: with SMTP id d34-v6mr18984687pld.103.1526870527772; Sun, 20 May 2018 19:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526870527; cv=none; d=google.com; s=arc-20160816; b=z0iPMhSN5SAnFlElefLPINMqvI/O+QzA1+u4JO/aRFWa+E0S4W3tRLYwcK9QG77+nr 2xycWFnfDQMpFqJTyh8VB+8VqY1eRp7sqRGps/5E1hJXY0UpZRoi1ywP8E1a/LWXGNgk p22wMh8jWU3DLpK7MHDof5diXg93PYb1F2vl3RlX2pe151wjampmrQaf0OUtzRG8VkVp 8XLRStceFFa7D02d0njsfnZn4IpOfZYr+VMq9dM++qnYkFlyJY6lDTs7dzMHaJy3GKYc furX2ybZs1ry0espzwobkMD+umDe8LNDq9421syfMHmp1hOFbyjlJ3Br38oT7lh2rQhv JgHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ysBFv8joIWdKc1XALHbQhRZpWiUFhWWhmMhAImmYsxU=; b=O1fjcokqQNjx7sG7SoA4j+OJ+LfFafSSuGdG/hsRSkgZvMSYQm+5xiSe5Lj20oIFd+ 58O7OyTnr//WEI4syA2Y0wRrPKq/wdq+rmd7iKTJk7UXHlFpoyIm7ePsbE/LoUlfN+Un c9q81vhbAVchBLVp7Lwc9tCdsK5hTp9OQc636vYEdWK84PbyiQ1LxX88SvDfG202KVnh 7dNp3hprxGZVnB04noOr1GEbcrS8md0rvS96aX5FesdFZUav7XuZmU+Pt58RyfbmSpbt 4Akiu0ImpOS7grVeiO617nwC3dc0Ze6yQdp1m962lXr+xsdE0CQIZ2LSBKVzvUObZFlv WzXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T9hvtQpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f95-v6si13338763plb.401.2018.05.20.19.41.53; Sun, 20 May 2018 19:42:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T9hvtQpp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752655AbeEUCkC (ORCPT + 99 others); Sun, 20 May 2018 22:40:02 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43163 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751094AbeEUCkA (ORCPT ); Sun, 20 May 2018 22:40:00 -0400 Received: by mail-pl0-f65.google.com with SMTP id c41-v6so7871023plj.10 for ; Sun, 20 May 2018 19:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ysBFv8joIWdKc1XALHbQhRZpWiUFhWWhmMhAImmYsxU=; b=T9hvtQppMWhaehlVU2h1EeuGaW6VHPAbJUv+R/mUgFoDP4AAzlkNMPyoQ2nFihLU/J Kb0+Dv1BYQ+bUSAipSYEIjZEjIG6v1EoppkZV5nKxWM3h7pC40CkNZDX73gM5Jf3iVhj e42XT2pd/9wlqlJEHAIxxfyp+ogLV1v0zRfLLdL1uEVNGsRjQ3CyDSR2OEnesfvUBxcl 355MBv1seUVhtUsUc/qLjtYpe61s9qEGF6dgktG02VHXFxIj78mXcT8CTiohKh/7GfTr ptC4JBcVnNAo3G5uju6pLY5MmMrs3s/LQGIKCJ2zn2Br40yvK1Qov2baLnhB6bajaEXC ce3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ysBFv8joIWdKc1XALHbQhRZpWiUFhWWhmMhAImmYsxU=; b=Dn2Ys4YU7isUJ/bdFyZwEcDFPXmoAKeJ2jTIgWZ/OguM2t6+WesEwPkZhW5qWjImnE BrTPqZ2RHy9DL0DssRiq6l/x/QleMQVXThydWIgYYc/OzcxzJwIHUx8RhG7L19NTOtgY +enhl0kveHOipD54QlmSvgcmhdSToh/gsMd4Zewbgixi8mH8zHL4di3jEW8iSx9x33Dl d4xjwMOb7Kx9q58IA5N7zyRZdnjRMW+47GZb6dfMrC8QtTNOlPYKeM0tZihhiQpd/tPW MuolgCaF8dv963K1cQU2rQT94hZ3o0aES5FfNgH4rbECZgAVzdq5cuyTMI6pSraQ2Ctx jqNg== X-Gm-Message-State: ALKqPwfX4d12nyi096jNxNuqY0CXlMUXaZf6SASfxU0pXuq11XQH5lMd +tw1HA8Cz7nzMyaMZTED10o= X-Received: by 2002:a17:902:5597:: with SMTP id g23-v6mr18615713pli.347.1526870399656; Sun, 20 May 2018 19:39:59 -0700 (PDT) Received: from node5.localdomain ([52.229.160.192]) by smtp.gmail.com with ESMTPSA id s4-v6sm16781183pgp.35.2018.05.20.19.39.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 19:39:58 -0700 (PDT) From: ufo19890607 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 Subject: [PATCH v4] Print the memcg's name when system-wide OOM happened Date: Mon, 21 May 2018 03:39:46 +0100 Message-Id: <1526870386-2439-1-git-send-email-ufo19890607@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: yuzhoujian The dump_header does not print the memcg's name when the system oom happened. So users cannot locate the certain container which contains the task that has been killed by the oom killer. System oom report will print the memcg's name after this patch, so users can get the memcg's path from the oom report and check the certain container more quickly. Changes since v3: - rename the helper's name to mem_cgroup_print_oom_memcg_name. - add the rcu lock held to the helper. - remove the print info of memcg's name in mem_cgroup_print_oom_info. Changes since v2: - add the mem_cgroup_print_memcg_name helper to print the memcg's name which contains the task that will be killed by the oom-killer. Changes since v1: - replace adding mem_cgroup_print_oom_info with printing the memcg's name only. Signed-off-by: yuzhoujian --- include/linux/memcontrol.h | 9 +++++++++ mm/memcontrol.c | 27 +++++++++++++++++++-------- mm/oom_kill.c | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d99b71bc2c66..5fc58beae368 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -464,6 +464,9 @@ void mem_cgroup_handle_over_high(void); unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg); +void mem_cgroup_print_oom_memcg_name(struct mem_cgroup *memcg, + struct task_struct *p); + void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p); @@ -858,6 +861,12 @@ static inline unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg) return 0; } +static inline void +mem_cgroup_print_oom_memcg_name(struct mem_cgroup *memcg, + struct task_struct *p) +{ +} + static inline void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2bd3df3d101a..138a11edfacb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1118,19 +1118,15 @@ 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. + * mem_cgroup_print_oom_memcg_name: Print the memcg's name which contains the + * task that will be killed by the oom-killer. * @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_memcg_name(struct mem_cgroup *memcg, struct task_struct *p) { - struct mem_cgroup *iter; - unsigned int i; - rcu_read_lock(); if (p) { @@ -1145,7 +1141,22 @@ void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, struct task_struct *p) pr_cont("\n"); rcu_read_unlock(); +} + +/** + * mem_cgroup_print_oom_info: 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) +{ + struct mem_cgroup *iter; + unsigned int i; + mem_cgroup_print_oom_memcg_name(memcg, p); pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memory)), K((u64)memcg->memory.limit), memcg->memory.failcnt); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8ba6cb88cf58..3e0b725fb877 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -433,6 +433,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) if (is_memcg_oom(oc)) mem_cgroup_print_oom_info(oc->memcg, p); else { + mem_cgroup_print_oom_memcg_name(oc->memcg, p); show_mem(SHOW_MEM_FILTER_NODES, oc->nodemask); if (is_dump_unreclaim_slabs()) dump_unreclaimable_slab(); -- 2.14.1