From patchwork Wed Apr 26 13:39:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13224619 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 C53CDC77B60 for ; Wed, 26 Apr 2023 13:39:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1385D6B00D6; Wed, 26 Apr 2023 09:39:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C0D36B00D8; Wed, 26 Apr 2023 09:39:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2DB16B00D9; Wed, 26 Apr 2023 09:39:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CDC226B00D6 for ; Wed, 26 Apr 2023 09:39:29 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A76D41C6768 for ; Wed, 26 Apr 2023 13:39:29 +0000 (UTC) X-FDA: 80723649258.03.F1DA96F Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf19.hostedemail.com (Postfix) with ESMTP id BEEA91A001D for ; Wed, 26 Apr 2023 13:39:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=VzLG+6h5; spf=pass (imf19.hostedemail.com: domain of 3jilJZAoKCC8jZdcjLSXPORZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3jilJZAoKCC8jZdcjLSXPORZZRWP.NZXWTYfi-XXVgLNV.ZcR@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=1682516367; 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=B3i7jLy77aXSdzt8MLnlwJrjLWa5VGev4cAQ6nx3Pzk=; b=pFY2nK6j5coFw5KAtBEwULhZIb21f+0hwzVUHIkSOo0YQ91dsTb2CyKhZWAjvZ6vyO7/Gd MDqrPqaR1krux3k7qGeku4MfkGpJ/aNTAtjSj/aTLFY+suZaT+4k7W6fWDvhV11OgzTNC7 s0S5151GCkWVbhU9G2I7Y9FaVnl0ttw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=VzLG+6h5; spf=pass (imf19.hostedemail.com: domain of 3jilJZAoKCC8jZdcjLSXPORZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3jilJZAoKCC8jZdcjLSXPORZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682516367; a=rsa-sha256; cv=none; b=wUA+M8q4x4Ye8ygCyJSejEAs/mV8zAJ8mXs1DrZDbrSqOE7jDPdzkmkUuTTfkZKw4o7OSM C8gqtzJPc0f/4fYPZGvl7w7jeQMHtTvz9QXQsv3zfvVER9kNl5chW/AYQlaEKavOVGLwKC C8ZfUKhk35clUFI76h2jiQ3vys+SHKA= Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-63b62529864so8325168b3a.2 for ; Wed, 26 Apr 2023 06:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682516366; x=1685108366; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=B3i7jLy77aXSdzt8MLnlwJrjLWa5VGev4cAQ6nx3Pzk=; b=VzLG+6h5CSkfvQZli1OGIiAHvWLeZ1UxaxLHwKBOnH2MCjUETX1QJE/sogMe69eqk7 vBbIbWZIN20q7FnUgXd+PGfMXTGUTczgWU8KKwjcZ8lBbyiyhGbKQYcc5cO7TX8Z3V4f 8DEtCJMSayke/qyFUeJHi41Q8w5O3Vw3jYELxMD9G2Yd43hlJ+5i9W56SzV8e4Y7qupz hvIeqP/bkO4QBcA+CZnvstw3SEisBauI073SKtvHsPG/3CBfKdbOME1DsBqBxapdAL07 yrZBPGmoTvf0k16+hlujpoOSCW6OIVEIvr6tqUDY4KOlfvJdizlM78YwN2B4KBUKjdh4 yo1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682516366; x=1685108366; 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=B3i7jLy77aXSdzt8MLnlwJrjLWa5VGev4cAQ6nx3Pzk=; b=UZlR8pQAeAb5VMqWuBD8T/inod0K95w6popDah/HrVZsdld06nZzBMuLoRXAAYnTYa ZFG7JNO/q2PH8a2nLnVLyQP4DZrC+1xHIszOpdFP7OPfTfAqyu+ruHA19eAutR81ccOd kR408CP/8XaYHusxsEm45mO7LAIV4dx2HYcHL/g9jE+R+epEkI/tAlyP6mS3X4a36Xwf UylVf56PwYjhlzT+gKxdhvHfRSHU2cPVEJj1+3zzFhJDWR0S5U7DwkDBKpfomQ3wmvc/ a06AGzDdFeMj2Je2/XBPILajX9WFcR58Ih4F2JniDs0SLM2lAxAjM/zbvtDGbbOpt04m 50/w== X-Gm-Message-State: AAQBX9eMhFw8LJjLWwn29uFM6WW9bSDfDfO301FUW85GkGV6jvYe3nnu osp7+t7NgzGA0AanjT1bHZrh8mma8kH+CnFY X-Google-Smtp-Source: AKy350bvBBlvhcymPuweaHrlA8kXbAA4KJRh9R4AzrPuP59p9sKX2jGZrLIZnT3j/yneuiDoaDCMGDaIkZEjKqJV X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:17a2:b0:63d:4598:ff1e with SMTP id s34-20020a056a0017a200b0063d4598ff1emr9147931pfg.3.1682516366660; Wed, 26 Apr 2023 06:39:26 -0700 (PDT) Date: Wed, 26 Apr 2023 13:39:19 +0000 In-Reply-To: <20230426133919.1342942-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230426133919.1342942-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230426133919.1342942-3-yosryahmed@google.com> Subject: [PATCH 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BEEA91A001D X-Stat-Signature: rcxcaz1mugp8wj58zbugfymrea4mw41s X-Rspam-User: X-HE-Tag: 1682516367-468318 X-HE-Meta: U2FsdGVkX19hRZLIelx0YziYn8psskoLwB5ixluMk9k4xS1UQbBc/Px/KMPY3SzbhGsfdEnThsMDsiZBcGjs3OHnyR/srHKkpZNoKO5mCGMfSwuLEJdbnNF6JNX2cQ8u37AIfoujAoS6AsFAJ7fBTI4v8plAm6dK4+/ldZG7Fu+te1aCLyVFDasl76kqOhb/kL91X0DyDia36qS8ffZN0rI+Z7h/myUNeeouqOe3JCfajUZ/l0itPAPR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DiDO8ingDwu8wzeC57jx/D3mZ2QvQu0PEU+Er2xx8i2QbbmzaDdy2ptlG1sdFsa9lt0thSat1HMVl3s4AN27VdzCksoB7x9X2VTgyh6F+Sa39q8r7wu9MPY6Mtk3/y+0pjJdMEnWQzd6cZxxf2i96AZLmPXSrJ5fTMx2NmXsIYxusLGhYHi5Npco1ra/AjxXf8Xtsj/l+KGIAH2grtZquJRa3ndhwrmduqS0sRM/kFQlnSmEjk9yxPYGyyPg9MWgudVCWPjNA07mxlsPLByD/uFatuhWTFWupUUsIpRCFRYSQ= 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, not it only prints the v2 cgroup stats for the cgroup under OOM. Although v2 stats are a superset of v1 stats, some of them have different naming. We also lost the non-hierarchical stats for the cgroup under OOM in 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 --- 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",