From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9503AC433E2 for ; Wed, 16 Sep 2020 04:15:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0362221E5 for ; Wed, 16 Sep 2020 04:15:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="2G6cIT8y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0362221E5 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 3DBF36B0003; Wed, 16 Sep 2020 00:15:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38C4D6B0037; Wed, 16 Sep 2020 00:15:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A2048E0001; Wed, 16 Sep 2020 00:15:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0210.hostedemail.com [216.40.44.210]) by kanga.kvack.org (Postfix) with ESMTP id 149C26B0003 for ; Wed, 16 Sep 2020 00:15:29 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CF33C8249980 for ; Wed, 16 Sep 2020 04:15:28 +0000 (UTC) X-FDA: 77267610336.06.use14_1f17c6e27116 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 95DE7100A8528 for ; Wed, 16 Sep 2020 04:15:27 +0000 (UTC) X-HE-Tag: use14_1f17c6e27116 X-Filterd-Recvd-Size: 10390 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Sep 2020 04:15:26 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id m15so2473069pls.8 for ; Tue, 15 Sep 2020 21:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LCRAOABNyfnd7lzn4QMxDV96zQMAtn58NYDWlvquY3g=; b=2G6cIT8yZsbFxrYcihmm01Gj0GSrMKff8Czby6u+EPsC5Y13yzYr4IjiO33Hbh6W/S 3XcK0ykjiUDsKYjgLk5yq6aEZlY8UOw/EMR+GXEHF5B4qga8TW5wh71rA8wRUI+O1GpF JRF8qYyUOP2vwBL0t5/skhaS8XNKzuppA5BzeZPbp+3zARCR1zbOWN7Jt4HgGiOYEoBS qyqW/6uNQxmXZke8BhbUXEvptwlrBP5RMTLKs2xagCaon+uPVYO0G1YiJ2lliVZpRdQt EoLdWPztPztdRe7hxe6Qy/FfIlXNwnh1ij5YFpXRg9gnDnrr+tYWs2UU4DIu88wynRFK qWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LCRAOABNyfnd7lzn4QMxDV96zQMAtn58NYDWlvquY3g=; b=tqK8D+Kinv2L9CIn8sABfd23NHiU2ficFq0heL4Pt98sgeS4LvU6wgFU4KDiRbti0h stZHvBU8lybQb0eUNDJ6jLdxrF1wjS3Hl0TARBbM31LuYEIb5ju2WamOjXDbVDv7OWHI Z1NvWZ+HgEMMpmkunIxNCgWLjphfhLQojFdk4ODkMmEv9xgMt3Y/ZqI+CK7F3QUYd6vW CPRUkficRLwLjNcMW8luvGTcqxBhQMMrr19W3sHRzjLjM+YMFRnIsjokQE/8xDzIlENc O7dvLIaLoydqOZeBAUIj1zSkAoNrxWUS0V5aVzMe7AlRLugSDQ5tGHxqviFnNX1X08b7 ZVQg== X-Gm-Message-State: AOAM531IXdQrxIbbA5BZE8XnpGVooVttt02BePAl0fTRipVY+2+qx8B/ pl73yIezpPs3QkL5yaU7/6oxzchcc9EkG6yiN+XZiw== X-Google-Smtp-Source: ABdhPJy2sy8PVXcyCJOvShHPTPgr0MnoBvJ8hNXFb+iNCh2bapM/ywuberhz6eOfN37SIu/IZPymzXp6hkAMbtGvh/Q= X-Received: by 2002:a17:90a:b78b:: with SMTP id m11mr2289570pjr.13.1600229725682; Tue, 15 Sep 2020 21:15:25 -0700 (PDT) MIME-Version: 1.0 References: <20200915171801.39761-1-songmuchun@bytedance.com> <20200915214845.GB189808@cmpxchg.org> In-Reply-To: <20200915214845.GB189808@cmpxchg.org> From: Muchun Song Date: Wed, 16 Sep 2020 12:14:49 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v5] mm: memcontrol: Add the missing numa_stat interface for cgroup v2 To: Johannes Weiner Cc: Tejun Heo , Zefan Li , Jonathan Corbet , Michal Hocko , Vladimir Davydov , Andrew Morton , Shakeel Butt , Roman Gushchin , Randy Dunlap , Cgroups , linux-doc@vger.kernel.org, LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 95DE7100A8528 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: On Wed, Sep 16, 2020 at 5:50 AM Johannes Weiner wrote: > > On Wed, Sep 16, 2020 at 01:18:01AM +0800, Muchun Song wrote: > > 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 > > Suggested-by: Shakeel Butt > > Reviewed-by: Shakeel Butt > > Yup, that would be useful information to have. Just a few comments on > the patch below: > > > @@ -1368,6 +1368,78 @@ PAGE_SIZE multiple when read back. > > collapsing an existing range of pages. This counter is not > > present when CONFIG_TRANSPARENT_HUGEPAGE is not set. > > > > + memory.numa_stat > > + A read-only flat-keyed file which exists on non-root cgroups. > > It's a nested key file, not flat. This is just copied from memory.stat documentation.Is the memory.stat also a nested key file? > > > + This breaks down the cgroup's memory footprint into different > > + types of memory, type-specific details, and other information > > + per node on the state of the memory management system. > > + > > + 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 case is evaluating > > + application performance by combining this information with the > > + application's CPU allocation. > > + > > + All memory amounts are in bytes. > > + > > + The output format of memory.numa_stat is:: > > + > > + type N0= N1= ... > > + > > + The entries are ordered to be human readable, and new entries > > + can show up in the middle. Don't rely on items remaining in a > > + fixed position; use the keys to look up specific values! > > + > > + anon > > + Amount of memory per node used in anonymous mappings such > > + as brk(), sbrk(), and mmap(MAP_ANONYMOUS). > > + > > + file > > + Amount of memory per node used to cache filesystem data, > > + including tmpfs and shared memory. > > + > > + kernel_stack > > + Amount of memory per node allocated to kernel stacks. > > + > > + shmem > > + Amount of cached filesystem data per node that is swap-backed, > > + such as tmpfs, shm segments, shared anonymous mmap()s. > > + > > + file_mapped > > + Amount of cached filesystem data per node mapped with mmap(). > > + > > + file_dirty > > + Amount of cached filesystem data per node that was modified but > > + not yet written back to disk. > > + > > + file_writeback > > + Amount of cached filesystem data per node that was modified and > > + is currently being written back to disk. > > + > > + anon_thp > > + Amount of memory per node used in anonymous mappings backed by > > + transparent hugepages. > > + > > + inactive_anon, active_anon, inactive_file, active_file, unevictable > > + Amount of memory, swap-backed and filesystem-backed, > > + per node on the internal memory management lists used > > + by the page reclaim algorithm. > > + > > + As these represent internal list state (e.g. shmem pages are on > > + anon memory management lists), inactive_foo + active_foo may not > > + be equal to the value for the foo counter, since the foo counter > > + is type-based, not list-based. > > + > > + slab_reclaimable > > + Amount of memory per node used for storing in-kernel data > > + structures which might be reclaimed, such as dentries and > > + inodes. > > + > > + slab_unreclaimable > > + Amount of memory per node used for storing in-kernel data > > + structures which cannot be reclaimed on memory pressure. > > + > > memory.swap.current > > A read-only single value file which exists on non-root > > cgroups. > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 75cd1a1e66c8..ff919ef3b57b 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -6425,6 +6425,86 @@ static int memory_stat_show(struct seq_file *m, void *v) > > return 0; > > } > > > > +#ifdef CONFIG_NUMA > > +struct numa_stat { > > + const char *name; > > + unsigned int ratio; > > + enum node_stat_item idx; > > +}; > > + > > +static struct numa_stat numa_stats[] = { > > + { "anon", PAGE_SIZE, NR_ANON_MAPPED }, > > + { "file", PAGE_SIZE, NR_FILE_PAGES }, > > + { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, > > + { "shmem", PAGE_SIZE, NR_SHMEM }, > > + { "file_mapped", PAGE_SIZE, NR_FILE_MAPPED }, > > + { "file_dirty", PAGE_SIZE, NR_FILE_DIRTY }, > > + { "file_writeback", PAGE_SIZE, NR_WRITEBACK }, > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > + /* > > + * The ratio will be initialized in numa_stats_init(). Because > > + * on some architectures, the macro of HPAGE_PMD_SIZE is not > > + * constant(e.g. powerpc). > > + */ > > + { "anon_thp", 0, NR_ANON_THPS }, > > +#endif > > + { "inactive_anon", PAGE_SIZE, NR_INACTIVE_ANON }, > > + { "active_anon", PAGE_SIZE, NR_ACTIVE_ANON }, > > + { "inactive_file", PAGE_SIZE, NR_INACTIVE_FILE }, > > + { "active_file", PAGE_SIZE, NR_ACTIVE_FILE }, > > + { "unevictable", PAGE_SIZE, NR_UNEVICTABLE }, > > + { "slab_reclaimable", 1, NR_SLAB_RECLAIMABLE_B }, > > + { "slab_unreclaimable", 1, NR_SLAB_UNRECLAIMABLE_B }, > > +}; > > This is a bit duplicative with memory_stat_format(), and the > collections will easily go out of sync as we add/change stat items. > > Can you please convert memory_stat_format() to use the same shared table? > > You may have to add another flag for the MEMCG_* items for which we > don't have per-node counters. > > The same applies to the documentation. Please don't duplicate the list > of items, but have memory.numa_stat refer to the list for memory.stat. > You can add (not in memory.numa_stat) or something to percpu and sock. Thanks for your suggestions. > > > +static unsigned long memcg_node_page_state(struct mem_cgroup *memcg, > > + unsigned int nid, > > + enum node_stat_item idx) > > +{ > > + VM_BUG_ON(nid >= nr_node_ids); > > + return lruvec_page_state(mem_cgroup_lruvec(memcg, NODE_DATA(nid)), idx); > > +} > > Please drop this wrapper and use lruvec_page_state directly below. > > Otherwise, this looks reasonable to me. OK. Will do that. -- Yours, Muchun