From patchwork Fri Apr 28 13:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13226461 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 DC02CC77B7C for ; Fri, 28 Apr 2023 13:24:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 605276B007D; Fri, 28 Apr 2023 09:24:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 58EF96B007E; Fri, 28 Apr 2023 09:24:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B9F56B0080; Fri, 28 Apr 2023 09:24:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 276656B007D for ; Fri, 28 Apr 2023 09:24:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F27CE120148 for ; Fri, 28 Apr 2023 13:24:17 +0000 (UTC) X-FDA: 80730868554.11.B08B8A0 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf25.hostedemail.com (Postfix) with ESMTP id F361EA0017 for ; Fri, 28 Apr 2023 13:24:14 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=jcuVTOAp; spf=pass (imf25.hostedemail.com: domain of 3_chLZAoKCOYgWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3_chLZAoKCOYgWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682688255; a=rsa-sha256; cv=none; b=BvZIhQeiC09MvOouZNgmjOqAAx4EoioLkOYd1ouoTOhJTYMo8UCtdvNeV09YbmQcVfZV6/ yMZh4Cq4/0MmpezvEM+8UE76bPVMHGAzaA15+xxQxBJY2GkrwEecsVZY+E7BegfInuQ0jB YC37O55j9CeVgN7q+CNkgCkf2dvPDHM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=jcuVTOAp; spf=pass (imf25.hostedemail.com: domain of 3_chLZAoKCOYgWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3_chLZAoKCOYgWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682688255; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gCrHQjiS2fwiby7dz0V9ThMkUe63uEws1Bin2T2dpU8=; b=l0F2DelgH1nHxBIMGerOxJRtM9qBuNsObnqdMJ/g7+qb9heKrpY8ndnWHBfE6TRx4LxhRX JSSuVyFtY+KKP31UdpoNYQSESIk30fhXVprSrVuJo1RboEKOAbkDFueMsyKoupbeZ5m2Qv Wfjrc+SEeerneLGr23X0VbzQWGbuFsI= Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5212ed3b16eso5914868a12.0 for ; Fri, 28 Apr 2023 06:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682688254; x=1685280254; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gCrHQjiS2fwiby7dz0V9ThMkUe63uEws1Bin2T2dpU8=; b=jcuVTOAp1c8K+ch7YCMLi+8POwhTwb1WrUalORmat2684E/X82MLP/H/sTNZiGTSzw ILJbHonyleAOPNozrhCp7XJpKzpTbzSV2WanXyhxQyxv5lSFZW8pMKziOeeK25UM/lM3 JtO2LiFUAPtV+zJkr/lmiV+hDnMAOdwrsD7W9rNnMigwvNIYtIDxnNjAK3lyudpZp5yI 5vpaP0vtG6m4sW2kgSy3vvkx/O8FeePG6gnTT8455Z1wkWEJFKZg0VnC7g7BQBECbTSk 07ULhu3kIczPuOMcJkwFO/y0wcnsFUVJfVg87WLuR8H+9rMQZ0u8212WdRLWh+a/t1bT beJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682688254; x=1685280254; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gCrHQjiS2fwiby7dz0V9ThMkUe63uEws1Bin2T2dpU8=; b=Cwwn+XXDrG01QE5vmHAsmsdKHyCxm2t7yLzJnCzeL6AOpbAk/ZhDjWZWS1HQCvy8D3 gB1TMdOh/TwnZfMHFiFAKpEUeUBXEGPGkrUg3ROpWxn04+c4HxLi6B5+s38pXdBxcPTQ pveDkPKO7X1yHa+0hF6evEKdyjKxv7UBSg6mDSC9Rgya2tcNwp4c0JPxNFSFW8Itgj0X quxX0DZfS3ecjcS64abA7LEnTHT5u+/sh2hxC+4JWG2Q2yA2wMHvIa35EdZ6a9f0hrc6 T8RG487nplDowtyEcsLI8HdGQpx1dWW/WEi23ZHyvTbrDQCE8fBjvwVN+qHk3N7FVWKt 2aQA== X-Gm-Message-State: AC+VfDydxHU/suosUt86Z6miJqu0Z/qR2Aee7d2nDJd44Xqo1NQC1yo/ dr5quCSYzH+3JbV5t6VYuCg3gYGqACy/4GQY X-Google-Smtp-Source: ACHHUZ6Q1iaeTMc7znbuRU46RBkgJ3r/GzmuoUGlNK1hEg/1kqgAXN7zKR88/FXgEDBYkLlt9aTGSyL2pZdAjcsz X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:b289:b0:19f:1d62:4393 with SMTP id u9-20020a170902b28900b0019f1d624393mr1511380plr.7.1682688253988; Fri, 28 Apr 2023 06:24:13 -0700 (PDT) Date: Fri, 28 Apr 2023 13:24:06 +0000 In-Reply-To: <20230428132406.2540811-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230428132406.2540811-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230428132406.2540811-3-yosryahmed@google.com> Subject: [PATCH v2 2/2] memcg: dump memory.stat during cgroup OOM for v1 From: Yosry Ahmed To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Andrew Morton Cc: Muchun Song , Sergey Senozhatsky , Steven Rostedt , Petr Mladek , Chris Li , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Queue-Id: F361EA0017 X-Rspamd-Server: rspam01 X-Stat-Signature: 89td7w8q3xbw3mdnnr3ti4w11zb5y5dt X-HE-Tag: 1682688254-310316 X-HE-Meta: U2FsdGVkX1++RsCKuc4JBy13LJv08JEKt62PFFeCqX06CRBkEAdxvrjdd/5AqDwugh9EwP7qMlUnNN2sJco7mZ0oq2RINsrCZv75VmMAh6Jyag6zn6QPU5QG4nJk1YPqs6yK7d7+LQgH3X/B9wXRlahhrjjEvj2vfl/DvtdZ1uvqq/vQkKsYG5c8+UiPOvwn/09ZLwge/+JBV/As4vI2l8xvkjjLUs9zzH+MIQRtVulUI7SQRjv5/yO5m+jz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yXq944179E3IuJERanOA5AcJdW7UieTucB/+aP5i/pHzlJMdzvm53E6g83kSM9QtNgw/AeUuewOhuJ/J8GZIekyMGDbAsqUDKWJpEXJPI1WsVPMJDGwmPRITKeVdoQOoDJO1MLRfnW26k00SzrV7Zb5ikO/ibWvDUKyqtbEFHIbM0s8cyg/y/RT+Vgr75JimbL8PGQ/XNZUuVRZhKFyxHz/Se9NW+ZWdAnk+XJFmiCng8yNaLNANhxtUxKqK3zjJUu5dKg4FikYfhm+utRkyTHhadwn870vV90IwIqho4Qj7kre89U8= 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: Commit c8713d0b2312 ("mm: memcontrol: dump memory.stat during cgroup OOM") made sure we dump all the stats in memory.stat during a cgroup OOM, but it also introduced a slight behavioral change. The code used to print the non-hierarchical v1 cgroup stats for the entire cgroup subtree, now it only prints the v2 cgroup stats for the cgroup under OOM. For cgroup v1 users, this introduces a few problems: (a) The non-hierarchical stats of the memcg under OOM are no longer shown. (b) A couple of v1-only stats (e.g. pgpgin, pgpgout) are no longer shown. (c) We show the list of cgroup v2 stats, even in cgroup v1. This list of stats is not tracked with v1 in mind. While most of the stats seem to be working on v1, there may be some stats that are not fully or correctly tracked. Although OOM log is not set in stone, we should not change it for no reason. When upgrading the kernel version to a version including commit c8713d0b2312 ("mm: memcontrol: dump memory.stat during cgroup OOM"), these behavioral changes are noticed in cgroup v1. The fix is simple. Commit c8713d0b2312 ("mm: memcontrol: dump memory.stat during cgroup OOM") separated stats formatting from stats display for v2, to reuse the stats formatting in the OOM logs. Do the same for v1. Move the v2 specific formatting from memory_stat_format() to memcg_stat_format(), add memcg1_stat_format() for v1, and make memory_stat_format() select between them based on cgroup version. Since memory_stat_show() now works for both v1 & v2, drop memcg_stat_show(). Signed-off-by: Yosry Ahmed Acked-by: Michal Hocko Acked-by: Shakeel Butt --- mm/memcontrol.c | 60 ++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5922940f92c9..2b492f8d540c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1551,7 +1551,7 @@ static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, return memcg_page_state(memcg, item) * memcg_page_state_unit(item); } -static void memory_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) +static void memcg_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) { int i; @@ -1604,6 +1604,17 @@ static void memory_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) WARN_ON_ONCE(seq_buf_has_overflowed(s)); } +static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s); + +static void memory_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) +{ + if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) + memcg_stat_format(memcg, s); + else + memcg1_stat_format(memcg, s); + WARN_ON_ONCE(seq_buf_has_overflowed(s)); +} + #define K(x) ((x) << (PAGE_SHIFT-10)) /** * mem_cgroup_print_oom_context: Print OOM information relevant to @@ -4078,9 +4089,8 @@ static const unsigned int memcg1_events[] = { PGMAJFAULT, }; -static int memcg_stat_show(struct seq_file *m, void *v) +static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) { - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); unsigned long memory, memsw; struct mem_cgroup *mi; unsigned int i; @@ -4095,18 +4105,18 @@ static int memcg_stat_show(struct seq_file *m, void *v) if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account()) continue; nr = memcg_page_state_local(memcg, memcg1_stats[i]); - seq_printf(m, "%s %lu\n", memcg1_stat_names[i], + seq_buf_printf(s, "%s %lu\n", memcg1_stat_names[i], nr * memcg_page_state_unit(memcg1_stats[i])); } for (i = 0; i < ARRAY_SIZE(memcg1_events); i++) - seq_printf(m, "%s %lu\n", vm_event_name(memcg1_events[i]), - memcg_events_local(memcg, memcg1_events[i])); + seq_buf_printf(s, "%s %lu\n", vm_event_name(memcg1_events[i]), + memcg_events_local(memcg, memcg1_events[i])); for (i = 0; i < NR_LRU_LISTS; i++) - seq_printf(m, "%s %lu\n", lru_list_name(i), - memcg_page_state_local(memcg, NR_LRU_BASE + i) * - PAGE_SIZE); + seq_buf_printf(s, "%s %lu\n", lru_list_name(i), + memcg_page_state_local(memcg, NR_LRU_BASE + i) * + PAGE_SIZE); /* Hierarchical information */ memory = memsw = PAGE_COUNTER_MAX; @@ -4114,11 +4124,11 @@ static int memcg_stat_show(struct seq_file *m, void *v) memory = min(memory, READ_ONCE(mi->memory.max)); memsw = min(memsw, READ_ONCE(mi->memsw.max)); } - seq_printf(m, "hierarchical_memory_limit %llu\n", - (u64)memory * PAGE_SIZE); + seq_buf_printf(s, "hierarchical_memory_limit %llu\n", + (u64)memory * PAGE_SIZE); if (do_memsw_account()) - seq_printf(m, "hierarchical_memsw_limit %llu\n", - (u64)memsw * PAGE_SIZE); + seq_buf_printf(s, "hierarchical_memsw_limit %llu\n", + (u64)memsw * PAGE_SIZE); for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) { unsigned long nr; @@ -4126,19 +4136,19 @@ static int memcg_stat_show(struct seq_file *m, void *v) if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account()) continue; nr = memcg_page_state(memcg, memcg1_stats[i]); - seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], + seq_buf_printf(s, "total_%s %llu\n", memcg1_stat_names[i], (u64)nr * memcg_page_state_unit(memcg1_stats[i])); } for (i = 0; i < ARRAY_SIZE(memcg1_events); i++) - seq_printf(m, "total_%s %llu\n", - vm_event_name(memcg1_events[i]), - (u64)memcg_events(memcg, memcg1_events[i])); + seq_buf_printf(s, "total_%s %llu\n", + vm_event_name(memcg1_events[i]), + (u64)memcg_events(memcg, memcg1_events[i])); for (i = 0; i < NR_LRU_LISTS; i++) - seq_printf(m, "total_%s %llu\n", lru_list_name(i), - (u64)memcg_page_state(memcg, NR_LRU_BASE + i) * - PAGE_SIZE); + seq_buf_printf(s, "total_%s %llu\n", lru_list_name(i), + (u64)memcg_page_state(memcg, NR_LRU_BASE + i) * + PAGE_SIZE); #ifdef CONFIG_DEBUG_VM { @@ -4153,12 +4163,10 @@ static int memcg_stat_show(struct seq_file *m, void *v) anon_cost += mz->lruvec.anon_cost; file_cost += mz->lruvec.file_cost; } - seq_printf(m, "anon_cost %lu\n", anon_cost); - seq_printf(m, "file_cost %lu\n", file_cost); + seq_buf_printf(s, "anon_cost %lu\n", anon_cost); + seq_buf_printf(s, "file_cost %lu\n", file_cost); } #endif - - return 0; } static u64 mem_cgroup_swappiness_read(struct cgroup_subsys_state *css, @@ -4998,6 +5006,8 @@ static int mem_cgroup_slab_show(struct seq_file *m, void *p) } #endif +static int memory_stat_show(struct seq_file *m, void *v); + static struct cftype mem_cgroup_legacy_files[] = { { .name = "usage_in_bytes", @@ -5030,7 +5040,7 @@ static struct cftype mem_cgroup_legacy_files[] = { }, { .name = "stat", - .seq_show = memcg_stat_show, + .seq_show = memory_stat_show, }, { .name = "force_empty",