From patchwork Thu Sep 10 08:42:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11767111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15597618 for ; Thu, 10 Sep 2020 08:43:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF20520872 for ; Thu, 10 Sep 2020 08:43:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="fW03118K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF20520872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B43686B0002; Thu, 10 Sep 2020 04:43:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF2586B005A; Thu, 10 Sep 2020 04:43:17 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B9D8900002; Thu, 10 Sep 2020 04:43:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 836E36B0002 for ; Thu, 10 Sep 2020 04:43:17 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3CA27181AEF1D for ; Thu, 10 Sep 2020 08:43:17 +0000 (UTC) X-FDA: 77246512434.04.route80_6302447270e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 14288800E099 for ; Thu, 10 Sep 2020 08:43:17 +0000 (UTC) X-Spam-Summary: 1,0,0,d875ce88d5ea64fd,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2892:3138:3139:3140:3141:3142:3353:3865:3866:3867:3870:3871:4250:4321:4605:5007:6261:6653:10004:11026:11233:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13255:13894:14181:14394:14721:21080:21444:21451:21627:21990:30045:30054:30075,0,RBL:209.85.210.194:@bytedance.com:.lbl8.mailshell.net-66.201.201.201 62.14.0.100;04yrts9p16g59mz6hazjz5siw3f9tocws6h791czef6pjmx55w5mk6n9ghb86tg.urs3x81qebffnhpf7pqjpq7k9m1ze1ynwg8b8swgjio81u1ywo6suyw7k9ooj85.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: route80_6302447270e4 X-Filterd-Recvd-Size: 5543 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 08:43:16 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id w7so4237731pfi.4 for ; Thu, 10 Sep 2020 01:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DydHZR1p/a4YgWod1jge5YOze1r87n8O9ViW1sroOHE=; b=fW03118K7OqoKHn0n/T5KvrtUYFGItUGF5N6guUzhftq5pe6S/cCuNZOc7HvKn8Eey IDNdM9hwsCF4NZkTkAwKmCSYy5a2dFlOA9lp46ncqkgd1q3DoUJBFxmUZUZt6kufBXDw pYTgoq8v1ApLaGpSc4X6a84Kaosdt95njNvvWGVCbOHsa7bfTKEnm+5pbShj746vZxEM b+3wSM92YFInqZYqb9WhPEDbL8IxDn5xD9kvQ3mFFAd9hJY0Ini76LCw7FtbXR+ymhl4 VUof+fRcGtKEQQO3SOy6ZDwd0/xU/N2QLdSZhnFwnfuFkKPNnJZKNuYqkAsm/aEf/aXB rmLg== 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:mime-version :content-transfer-encoding; bh=DydHZR1p/a4YgWod1jge5YOze1r87n8O9ViW1sroOHE=; b=oO9PTSYP0Zgns/gQ0P2+UCxQSBiD0T0Vv8diJPBKzm3rp7NqFGOs8HYt8cHIMeVVGI XgA+pe0J+FcxdcFt8fl0Ytjc8RhiZ2I5MwgMnbroXfu8AWiO1P3sgzTtp1SaFum92m12 8VjXf/oaGpwfBm1tnbHFEtMM+5zdp9rKNlMCGBx8spmF5MUn2fGvgkrvMvAyeTzfmI9i CFLLTuGnHqzeGscd4v8JNCsH/jl5GqgESxB57Cvd2Bd5/Ki/9pLD1PpfFVBfbCG4DTCs AAW17ooUYIY0JCAo/qspzjVYv+wrHfVlIcfOhXhiLIW+xu2lN5T1GATbtOdjE9jyAHXy KkDQ== X-Gm-Message-State: AOAM5334klhQ0p8vIHw0Zod6Nx0Sml4uwk4mCRBHgaNRTgnVSCYXfXV3 Cn6qiZ4jUPYz9Atsp0dp6OGB3w== X-Google-Smtp-Source: ABdhPJw1G2Xl2QigaSTG41KX4+ivGSijQkSvMrzle/xljTr3qEDQNI3MjDlu9qARs4whVg2vcMPJEw== X-Received: by 2002:a63:f53:: with SMTP id 19mr3741250pgp.26.1599727395106; Thu, 10 Sep 2020 01:43:15 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.221.71]) by smtp.gmail.com with ESMTPSA id n21sm4447567pgl.7.2020.09.10.01.43.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2020 01:43:14 -0700 (PDT) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm: memcontrol: Add the missing numa stat of anon and file for cgroup v2 Date: Thu, 10 Sep 2020 16:42:58 +0800 Message-Id: <20200910084258.22293-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Rspamd-Queue-Id: 14288800E099 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: In the cgroup v1, we have a numa_stat interface. This is useful for providing visibility into the numa locality information within an memcg since the pages are allowed to be allocated from any physical node. One of the use cases is evaluating application performance by combining this information with the application's CPU allocation. But the cgroup v2 does not. So this patch adds the missing information. Signed-off-by: Muchun Song --- mm/memcontrol.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 75cd1a1e66c8..c779673f29b2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1492,10 +1492,34 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) return false; } +#ifdef CONFIG_NUMA +static unsigned long memcg_node_page_state(struct mem_cgroup *memcg, + unsigned int nid, + enum node_stat_item idx) +{ + long x; + struct mem_cgroup_per_node *pn; + struct lruvec *lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); + + VM_BUG_ON(nid >= nr_node_ids); + + pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec); + x = atomic_long_read(&pn->lruvec_stat[idx]); +#ifdef CONFIG_SMP + if (x < 0) + x = 0; +#endif + return x; +} +#endif + static char *memory_stat_format(struct mem_cgroup *memcg) { struct seq_buf s; int i; +#ifdef CONFIG_NUMA + int nid; +#endif seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE); if (!s.buffer) @@ -1512,12 +1536,30 @@ static char *memory_stat_format(struct mem_cgroup *memcg) * Current memory state: */ - seq_buf_printf(&s, "anon %llu\n", + seq_buf_printf(&s, "anon %llu", (u64)memcg_page_state(memcg, NR_ANON_MAPPED) * PAGE_SIZE); - seq_buf_printf(&s, "file %llu\n", +#ifdef CONFIG_NUMA + for_each_node_state(nid, N_MEMORY) + seq_buf_printf(&s, " N%d=%llu", nid, + (u64)memcg_node_page_state(memcg, nid, + NR_ANON_MAPPED) * + PAGE_SIZE); +#endif + seq_buf_putc(&s, '\n'); + + seq_buf_printf(&s, "file %llu", (u64)memcg_page_state(memcg, NR_FILE_PAGES) * PAGE_SIZE); +#ifdef CONFIG_NUMA + for_each_node_state(nid, N_MEMORY) + seq_buf_printf(&s, " N%d=%llu", nid, + (u64)memcg_node_page_state(memcg, nid, + NR_FILE_PAGES) * + PAGE_SIZE); +#endif + seq_buf_putc(&s, '\n'); + seq_buf_printf(&s, "kernel_stack %llu\n", (u64)memcg_page_state(memcg, NR_KERNEL_STACK_KB) * 1024);