From patchwork Fri Jun 3 07:04:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12868704 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 284CDC433EF for ; Fri, 3 Jun 2022 07:06:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91F8A6B0071; Fri, 3 Jun 2022 03:06:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C9EC6B0073; Fri, 3 Jun 2022 03:06:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78F936B0074; Fri, 3 Jun 2022 03:06:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 68B806B0071 for ; Fri, 3 Jun 2022 03:06:06 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 36A5421074 for ; Fri, 3 Jun 2022 07:06:06 +0000 (UTC) X-FDA: 79536040332.26.634E8B8 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf28.hostedemail.com (Postfix) with ESMTP id EB43BC0078 for ; Fri, 3 Jun 2022 07:05:23 +0000 (UTC) Received: by mail-pl1-f178.google.com with SMTP id s14so6256756plk.8 for ; Fri, 03 Jun 2022 00:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e82fukpYye7S2pSV2P+x4ME/8iEwBLqlJ1dF4LHKRB0=; b=ry5NcCTXMOqj1FGTaEXhK+FobbrIVEyQmzz/PgWWOHG+peC2R1eWm4saAAl0ArXz56 7kqucbKX48iDB/rFpfZPlkZduVuAXQ1QWhrpK9qfw+6f/xvm6RV4FRaxl9jK5uxD1lAw DbEqejaeKCPP5MKuCY1wBpCRa95O/EO4aTBT1SDvFNgyqB3BFZBd+0EA1OXZ7N+6Z0Af sjz4XWY++3WN2hEqhBehtW0dKbDwTnPN1t8R1sFb/cKTEEuoU+ls60QysmRkU80dkG1T AX8y6mdwYugEGK5GBYhv/yaT5R8CIqnxRr3AynW1g97mVZnDkSxaQfil2YumvXykmYQU uxhw== 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=e82fukpYye7S2pSV2P+x4ME/8iEwBLqlJ1dF4LHKRB0=; b=3WP6i60d/gPvfMLcdshFLnL0ARue/iR8iPT5Ssiu2QhXiHnkbvav0e7hQ03Kx8MEE6 udaFKR4EFC5KWtcvt4dwSAnVwR3EhXhaeDx2vQtvTdyDafHx90iYEyIKT0XTOMUN7tiE m3Q0jp0efOBefTkXTi7l/18OGFdjbZ5CVMbQJeVyES4SDWP72JNBm3ac3B/hcggxtrsI gkEeaxi8UGiA+ZjJZdJ8rLsR/FGbbwjMVkNAiQBCOoJ0gEqSYC6ozJw658XKW1YBqPzG M295vZiR4eaevEnCx9mdwC8RkBqJGXdaME4X5llz9W4V1X9PA9drFfew+rIwugED3W3b PovQ== X-Gm-Message-State: AOAM532HsrCRiOWtSnYSnKeay21j3UoxBkPGQWOX9ZdmC+WhB2w65GXe LhtOBstmFcQci8HkpuKnHRoeyg== X-Google-Smtp-Source: ABdhPJzgJuki2NLhaHmK8hlAK3grRo/oCn5wI6acSYyw+d//NXha49HtiC09VSEmU6CA03CNN6HfMw== X-Received: by 2002:a17:90b:4acd:b0:1e3:4dab:a14c with SMTP id mh13-20020a17090b4acd00b001e34daba14cmr9409659pjb.5.1654239962996; Fri, 03 Jun 2022 00:06:02 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.224]) by smtp.gmail.com with ESMTPSA id ij4-20020a170902ab4400b0016632179ec8sm3822472plb.219.2022.06.03.00.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 00:06:02 -0700 (PDT) From: Qi Zheng To: mhocko@kernel.org, hannes@cmpxchg.org, roman.gushchin@linux.dev, shakeelb@google.com, songmuchun@bytedance.com, akpm@linux-foundation.org, corbet@lwn.net Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Qi Zheng Subject: [PATCH] mm: memcontrol: separate {pgscan,pgsteal}_{kswapd,direct} items in memory.stat of cgroup v2 Date: Fri, 3 Jun 2022 15:04:23 +0800 Message-Id: <20220603070423.10025-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Stat-Signature: r6wpuo4pxumof3681ro4rt7yoaufcjff X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ry5NcCTX; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EB43BC0078 X-HE-Tag: 1654239923-224980 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: There are already statistics of {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct of memcg event here, but now the sum of the two is displayed in memory.stat of cgroup v2. In order to obtain more accurate information during monitoring and debugging, and to align with the display in /proc/vmstat, it better to display {pgscan,pgsteal}_kswapd and {pgscan,pgsteal}_direct separately. Moreover, after this modification, all memcg events can be printed with a combination of vm_event_name() and memcg_events(). This allows us to create an array to traverse and print, which reduces redundant seq_buf_printf() codes. Signed-off-by: Qi Zheng Acked-by: Johannes Weiner Acked-by: Roman Gushchin Acked-by: Muchun Song --- Documentation/admin-guide/cgroup-v2.rst | 14 ++++-- mm/memcontrol.c | 61 +++++++++++-------------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 176298f2f4de..0b9ca7e7df34 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1442,11 +1442,17 @@ PAGE_SIZE multiple when read back. pgrefill (npn) Amount of scanned pages (in an active LRU list) - pgscan (npn) - Amount of scanned pages (in an inactive LRU list) + pgscan_kswapd (npn) + Amount of scanned pages by kswapd (in an inactive LRU list) - pgsteal (npn) - Amount of reclaimed pages + pgscan_direct (npn) + Amount of scanned pages directly (in an inactive LRU list) + + pgsteal_kswapd (npn) + Amount of reclaimed pages by kswapd + + pgsteal_direct (npn) + Amount of reclaimed pages directly pgactivate (npn) Amount of pages moved to the active LRU list diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 0d3fe0a0c75a..4093062c5c9b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1460,6 +1460,28 @@ static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, return memcg_page_state(memcg, item) * memcg_page_state_unit(item); } +static const unsigned int memcg_vm_event_stat[] = { + PGFAULT, + PGMAJFAULT, + PGREFILL, + PGSCAN_KSWAPD, + PGSCAN_DIRECT, + PGSTEAL_KSWAPD, + PGSTEAL_DIRECT, + PGACTIVATE, + PGDEACTIVATE, + PGLAZYFREE, + PGLAZYFREED, +#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) + ZSWPIN, + ZSWPOUT, +#endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + THP_FAULT_ALLOC, + THP_COLLAPSE_ALLOC, +#endif +}; + static char *memory_stat_format(struct mem_cgroup *memcg) { struct seq_buf s; @@ -1495,41 +1517,10 @@ static char *memory_stat_format(struct mem_cgroup *memcg) } /* Accumulated memory events */ - - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGFAULT), - memcg_events(memcg, PGFAULT)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGMAJFAULT), - memcg_events(memcg, PGMAJFAULT)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGREFILL), - memcg_events(memcg, PGREFILL)); - seq_buf_printf(&s, "pgscan %lu\n", - memcg_events(memcg, PGSCAN_KSWAPD) + - memcg_events(memcg, PGSCAN_DIRECT)); - seq_buf_printf(&s, "pgsteal %lu\n", - memcg_events(memcg, PGSTEAL_KSWAPD) + - memcg_events(memcg, PGSTEAL_DIRECT)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGACTIVATE), - memcg_events(memcg, PGACTIVATE)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGDEACTIVATE), - memcg_events(memcg, PGDEACTIVATE)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREE), - memcg_events(memcg, PGLAZYFREE)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGLAZYFREED), - memcg_events(memcg, PGLAZYFREED)); - -#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) - seq_buf_printf(&s, "%s %lu\n", vm_event_name(ZSWPIN), - memcg_events(memcg, ZSWPIN)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(ZSWPOUT), - memcg_events(memcg, ZSWPOUT)); -#endif - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_FAULT_ALLOC), - memcg_events(memcg, THP_FAULT_ALLOC)); - seq_buf_printf(&s, "%s %lu\n", vm_event_name(THP_COLLAPSE_ALLOC), - memcg_events(memcg, THP_COLLAPSE_ALLOC)); -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + for (i = 0; i < ARRAY_SIZE(memcg_vm_event_stat); i++) + seq_buf_printf(&s, "%s %lu\n", + vm_event_name(memcg_vm_event_stat[i]), + memcg_events(memcg, memcg_vm_event_stat[i])); /* The above should easily fit into one page */ WARN_ON_ONCE(seq_buf_has_overflowed(&s));