Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2314728pxk; Mon, 14 Sep 2020 10:00:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvgervj+3EyeaC4GvJ/4L6TWTt0gYDmCax1taSsziOArOuQgPmy3/fqQ3Dv1ktnCoij7dl X-Received: by 2002:a17:906:480a:: with SMTP id w10mr15401293ejq.372.1600102811292; Mon, 14 Sep 2020 10:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600102811; cv=none; d=google.com; s=arc-20160816; b=RN4Y7liPdheLMuKh5z5FgRXHcEaI5UGLItQ9VH62rzgHfwe3OoKzm3gl1VAkuEO1+M 8CkM0cJsFw4NEUH7Tvn0SgdtAIeQQth9wv78ULF5pXYHO1u7VA2fGtrw7uidtiDjknon E8gJjq0EYUL0/iHTT6ditSP9ZbG46c5sjprXR26EKAIvxlaMIDjF2CqQ+LuX3k1cMg8m O4l8fTtJqQ8Mc96PkdwMHaYAep45p6F7TkPy2D4KrTcJinFqH+nDVZ4/CUZ80DHduEbs 4q8gxTzIsyYovxjy2h+htpz5CtX3gRnop8Iegrf57+Q7Jk+slOBpO0cvxx1r6BBmnSco pc8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nn8uGO9a9X0XwaIfMVFd2VgaWgHbpK8dvPYHd7Sq/nA=; b=IDbCNBEwfVby7/4h+o7zHCU4M0iFIAJHSjqQIhtTrwvLZkLkioemqNT9lKzEZNoKBP pxE+4hpgbl6biEaPv26o9gZVUKm1R6zzaZSQ+bJS8M+pAkp26rVPNJylBlwZPRCkGCVt XVDVWnEPlC6LTWBgaGaZAePOQG1qr9XJ1O7iMFNVBWKBKRzjXuGinBoPPzIoG+dm2XeE HiSopztcjTdsctmrrk8uUBZF6Dbh1fRnGO2ZcfoIZt5U4Y1c4sTnqKCPAQXhSlNCG19Q ckdUFP+AmliycMd6yWKUgl18onLGVZkodcZ5h9L9BSGorinMyuKmD7A+yaq830fXAtrG NLYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=RB+2IbSg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si7859731edv.47.2020.09.14.09.59.49; Mon, 14 Sep 2020 10:00:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=RB+2IbSg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726057AbgINQ5A (ORCPT + 99 others); Mon, 14 Sep 2020 12:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbgINQz1 (ORCPT ); Mon, 14 Sep 2020 12:55:27 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EB23C061788 for ; Mon, 14 Sep 2020 09:55:27 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id f18so16806pfa.10 for ; Mon, 14 Sep 2020 09:55:27 -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=nn8uGO9a9X0XwaIfMVFd2VgaWgHbpK8dvPYHd7Sq/nA=; b=RB+2IbSgUvQBoAdsF0OTSCz20nt98NJ5VHwnf9jRx7zYNTMQeX4LZz03zL76irCDsG 0mdg45wZp2YAKNVNcAwTPfapLTrblMQfnEi5juhLmTb8jSzbarIx3WRVlOGm1lwO0q4M JQXKYTnJSK2DV38j5skJQDiuqxCdrQ3kOy8gMmaXArc3C/XUvXxCidE0P/u3zhA62+yi xxn5pXMlfzPSghT6dqYreCTRbu1o6GiEEvmXJk4bl7fHVfWaL8keJwVa0PHKeirScjuK prJC8gaEvEx5yF4bvJyP9nUjr2ef9WkOsxRj3i4EAEkOXmG5T4VYP6A9imu3h5LqM1Nm 5WRg== 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=nn8uGO9a9X0XwaIfMVFd2VgaWgHbpK8dvPYHd7Sq/nA=; b=s8UPQ55VFkbaS0Xt+1lBOXtjDR1ryluozc6i2iI9D2/WwDI/pDE5jByB7/6TBAxup5 ihzBO4O60IJ9/v7YG7AzIp/sAfbsJhx8t5HLD/0Ey3dLshyOABteuGJVpi9HnDs45VKU 18nlFUALp/LHcGu2+tZxoJIOQ2pAYTX2qH4Pt+k6/NhRl6tAgoyA9qy3VjOxNTPy1C2j Nu4L7PcIUBkwC57RpBjhz8SIvJXouqMZJaNbC2LZrbDZsxSYntqRyd+Dqeu1OF5DBCzB UjcmsajyrLKFQYCiMJNInWA7Kw8e2YuXYUy8nv1vWVz3sHWjHOW/Eo+ULIJSnmZLXdRs hOiQ== X-Gm-Message-State: AOAM531iuiDeNGUAIaSnM/fPYga180DA2skxSFZ1905ExhrCN1Wo4BmI BjE7Bk6J5Y6h2Y7CdvR837DmtnbS7j7MEuoMf4gI7g== X-Received: by 2002:a62:8f4c:: with SMTP id n73mr13928326pfd.65.1600102526730; Mon, 14 Sep 2020 09:55:26 -0700 (PDT) MIME-Version: 1.0 References: <20200913070010.44053-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 15 Sep 2020 00:54:50 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3] mm: memcontrol: Add the missing numa_stat interface for cgroup v2 To: Shakeel Butt Cc: Tejun Heo , Li Zefan , Johannes Weiner , Jonathan Corbet , Michal Hocko , Vladimir Davydov , Andrew Morton , Roman Gushchin , Cgroups , linux-doc@vger.kernel.org, LKML , Linux MM , kernel test robot Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2020 at 12:07 AM Shakeel Butt wrote: > > On Sun, Sep 13, 2020 at 12:01 AM 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 > > Reported-by: kernel test robot > > --- > [snip] > > + > > +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 }, > > +}; > > + > > +static int __init numa_stats_init(void) > > +{ > > + int i; > > + > > + for (i = 0; i < ARRAY_SIZE(numa_stats); i++) { > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > + if (numa_stats[i].idx == NR_ANON_THPS) > > + numa_stats[i].ratio = HPAGE_PMD_SIZE; > > +#endif > > + } > > The for loop seems excessive but I don't really have a good alternative. Yeah, I also have no good alternative. The numa_stats is only initialized once. So there may be no problem :). > > > + > > + return 0; > > +} > > +pure_initcall(numa_stats_init); > > + > > +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); > > +} > > + > > +static const char *memory_numa_stat_format(struct mem_cgroup *memcg) > > +{ > > + int i; > > + struct seq_buf s; > > + > > + /* Reserve a byte for the trailing null */ > > + seq_buf_init(&s, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE - 1); > > + if (!s.buffer) > > + return NULL; > > + > > + for (i = 0; i < ARRAY_SIZE(numa_stats); i++) { > > + int nid; > > + > > + seq_buf_printf(&s, "%s", numa_stats[i].name); > > + for_each_node_state(nid, N_MEMORY) { > > + u64 size; > > + > > + size = memcg_node_page_state(memcg, nid, > > + numa_stats[i].idx); > > + size *= numa_stats[i].ratio; > > + seq_buf_printf(&s, " N%d=%llu", nid, size); > > + } > > + seq_buf_putc(&s, '\n'); > > + } > > + > > + /* The above should easily fit into one page */ > > + if (WARN_ON_ONCE(seq_buf_putc(&s, '\0'))) > > + s.buffer[PAGE_SIZE - 1] = '\0'; > > I think you should follow Michal's recommendation at > http://lkml.kernel.org/r/20200914115724.GO16999@dhcp22.suse.cz Here is different, because the seq_buf_putc(&s, '\n') will not add \0 unless we use seq_buf_puts(&s, "\n"). -- Yours, Muchun