From patchwork Fri Dec 3 16:24:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Schatzberg X-Patchwork-Id: 12655501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 904A2C433F5 for ; Fri, 3 Dec 2021 16:25:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 075686B0074; Fri, 3 Dec 2021 11:24:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0241D6B0075; Fri, 3 Dec 2021 11:24:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE0276B0078; Fri, 3 Dec 2021 11:24:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id D01986B0074 for ; Fri, 3 Dec 2021 11:24:56 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9939E181A47E9 for ; Fri, 3 Dec 2021 16:24:46 +0000 (UTC) X-FDA: 78877006572.21.26A0D2E Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 41B3EE00199E for ; Fri, 3 Dec 2021 16:24:46 +0000 (UTC) Received: by mail-qt1-f178.google.com with SMTP id p19so3770456qtw.12 for ; Fri, 03 Dec 2021 08:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mMA0FwRsbKa8XEHQlou/tMRVIbGFsiozFUia1lQqx44=; b=JotK5rB5Id9ulOqmD/Pexs4DElrQW0yz1r8/r8rqXgtNglR0/3hIzYN7yHHRL330Xd cQQxNRjJQEzk6th5Kqrtx7HInxeu+M0Mum8gIkXD34G9KDJ62e50rBYkGxswmx5dgUee /kVFvzGHuZP62d6aBDM/G8FJQkngESqd5CVz7RA8lhGB/u3dV5ywDc9u6KzQiwDVczLP 1bc75km9MsBJWzTVM8s+n5v2z5lbi8eNdvECP9abcgvmikohlmnXoDoEmiZc82bvDlJ5 JXh434sWhWSjpEZctJHdknmRXFKTm6Z0cX01THb6hRtuFwNZAwPAb+PcbD4mMnnFpam8 uNJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mMA0FwRsbKa8XEHQlou/tMRVIbGFsiozFUia1lQqx44=; b=xScYybdHDRgRv8SurqVJ3gTwyeiMt94NXZ6XemTGVstckQ3w5xFPd6D3Xua4u1Y8Od vNaNQAyesSGLHZ06O7a+TDtBEvxP8OgT6ZqMUzjaKM37pMVnpTzug0+VNg5ADtS5U56n l+LmFImm+KBHljD2Wnun0duNrEe8y/ahr/bqY/IKm2CIyyFpIhTzGiZ6OngXcCHe/r3g l32qsDPKWpCk/WQMok1iLNJUObN3TuI2otWY1JeW2HykHRQIWXNCaMQ557ORxCJD4n79 x1Yol6QND4mWXmykx8yXoeadMCCwvO8zvewWBtisV3ms3Md/1t6rG9skIcLSuumrbt+O XISg== X-Gm-Message-State: AOAM533b9stlneSdh/nqrtC7Bxa+kyBcuAReoQRhQ4qGztcOv9G+LaFJ w3ttGe/rGS62StfIQ0dtSjg= X-Google-Smtp-Source: ABdhPJx9hBtUy3zW+sJpdntlHvakHD04U0OiGAx1hflDTQiL3DarIPQF0IWxK8s8/cqFeF67zmvt6A== X-Received: by 2002:a05:622a:307:: with SMTP id q7mr21839822qtw.330.1638548685441; Fri, 03 Dec 2021 08:24:45 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:285c]) by smtp.gmail.com with ESMTPSA id g14sm2435522qko.55.2021.12.03.08.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 08:24:44 -0800 (PST) From: Dan Schatzberg To: Johannes Weiner , Roman Gushchin Cc: Tejun Heo , Zefan Li , Jonathan Corbet , Michal Hocko , Vladimir Davydov , Andrew Morton , Shakeel Butt , "Matthew Wilcox (Oracle)" , Muchun Song , Alex Shi , Wei Yang , cgroups@vger.kernel.org (open list:CONTROL GROUP (CGROUP)), linux-doc@vger.kernel.org (open list:DOCUMENTATION), linux-kernel@vger.kernel.org (open list), linux-mm@kvack.org (open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)) Subject: [PATCH] mm: add group_oom_kill memory event Date: Fri, 3 Dec 2021 08:24:23 -0800 Message-Id: <20211203162426.3375036-1-schatzberg.dan@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 41B3EE00199E X-Stat-Signature: xo3gubhgpw9edynhx5ab7grf5rtbrz4u Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JotK5rB5; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of schatzberg.dan@gmail.com designates 209.85.160.178 as permitted sender) smtp.mailfrom=schatzberg.dan@gmail.com X-HE-Tag: 1638548686-710350 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: Our container agent wants to know when a container exits if it was OOM killed or not to report to the user. We use memory.oom.group = 1 to ensure that OOM kills within the container's cgroup kill everything. Existing memory.events are insufficient for knowing if this triggered: 1) Our current approach reads memory.events oom_kill and reports the container was killed if the value is non-zero. This is erroneous in some cases where containers create their children cgroups with memory.oom.group=1 as such OOM kills will get counted against the container cgroup's oom_kill counter despite not actually OOM killing the entire container. 2) Reading memory.events.local will fail to identify OOM kills in leaf cgroups (that don't set memory.oom.group) within the container cgroup. This patch adds a new oom_group_kill event when memory.oom.group triggers to allow userspace to cleanly identify when an entire cgroup is oom killed. Signed-off-by: Dan Schatzberg Reviewed-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by: Chris Down Acked-by: Michal Hocko --- Documentation/admin-guide/cgroup-v2.rst | 4 ++++ include/linux/memcontrol.h | 1 + mm/memcontrol.c | 5 +++++ mm/oom_kill.c | 1 + 4 files changed, 11 insertions(+) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 2aeb7ae8b393..eec830ce2068 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1268,6 +1268,10 @@ PAGE_SIZE multiple when read back. The number of processes belonging to this cgroup killed by any kind of OOM killer. + oom_group_kill + The number of times all tasks in the cgroup were killed + due to memory.oom.group. + memory.events.local Similar to memory.events but the fields in the file are local to the cgroup i.e. not hierarchical. The file modified event diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 0c5c403f4be6..951f24f42147 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -42,6 +42,7 @@ enum memcg_memory_event { MEMCG_MAX, MEMCG_OOM, MEMCG_OOM_KILL, + MEMCG_OOM_GROUP_KILL, MEMCG_SWAP_HIGH, MEMCG_SWAP_MAX, MEMCG_SWAP_FAIL, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6863a834ed42..5ab3b9ce90de 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4390,6 +4390,9 @@ static int mem_cgroup_oom_control_read(struct seq_file *sf, void *v) seq_printf(sf, "under_oom %d\n", (bool)memcg->under_oom); seq_printf(sf, "oom_kill %lu\n", atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL])); + seq_printf(sf, "oom_group_kill %lu\n", + atomic_long_read( + &memcg->memory_events[MEMCG_OOM_GROUP_KILL])); return 0; } @@ -6307,6 +6310,8 @@ static void __memory_events_show(struct seq_file *m, atomic_long_t *events) seq_printf(m, "oom %lu\n", atomic_long_read(&events[MEMCG_OOM])); seq_printf(m, "oom_kill %lu\n", atomic_long_read(&events[MEMCG_OOM_KILL])); + seq_printf(m, "oom_group_kill %lu\n", + atomic_long_read(&events[MEMCG_OOM_GROUP_KILL])); } static int memory_events_show(struct seq_file *m, void *v) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 1ddabefcfb5a..e52ce0b1465d 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -994,6 +994,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message) * If necessary, kill all tasks in the selected memory cgroup. */ if (oom_group) { + memcg_memory_event(oom_group, MEMCG_OOM_GROUP_KILL); mem_cgroup_print_oom_group(oom_group); mem_cgroup_scan_tasks(oom_group, oom_kill_memcg_member, (void *)message);