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=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 67872C43461 for ; Mon, 14 Sep 2020 16:07:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8D0A20EDD for ; Mon, 14 Sep 2020 16:07:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pPpu3G31" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8D0A20EDD Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 921208E0003; Mon, 14 Sep 2020 12:07:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D4366B0071; Mon, 14 Sep 2020 12:07:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 799AB8E0003; Mon, 14 Sep 2020 12:07:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id 614316B0070 for ; Mon, 14 Sep 2020 12:07:45 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 19C21180AD838 for ; Mon, 14 Sep 2020 16:07:45 +0000 (UTC) X-FDA: 77262147690.07.deer19_19062e627109 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 5C3211803F9A4 for ; Mon, 14 Sep 2020 16:07:42 +0000 (UTC) X-HE-Tag: deer19_19062e627109 X-Filterd-Recvd-Size: 6868 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Sep 2020 16:07:41 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id r24so170449ljm.3 for ; Mon, 14 Sep 2020 09:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=K/o4tAbgmhnFT0w3pjwutrP2CtxBURpGRMbYhc3bTBE=; b=pPpu3G310vswA/nzxXfPePwsCLMfpRmAnUA0uCGCsS5PHm/yNqAAZL2/DWNTt+l3lM PvlI6UlO5TrzkcEInN5arkbz9MYp5S/M8PMd7n++rLAP9m+3RZZ/Am/tFaUXp52FBSLC g9fkBMmm8TJVzOiKLzLjysDoYMvdFdpXgllEVnYccmou3TECsBCo4Q2XgnBx3b4PGwt4 BMgJKPRRG756/BLx5t0gSUmFPXy7A4lKFKoEMbj5iWrtu7xM2kDexDml++76NxnnYD9H 94UfzpBjkzJ7QZEtd34w21csMPfqIeV1HofiC94xe6y3JiZRWGK2Vp6V0Ze6AjD7WFwN V5mA== 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=K/o4tAbgmhnFT0w3pjwutrP2CtxBURpGRMbYhc3bTBE=; b=QVNRTbkS/JiRkAYLxuS/jZ4iMICaEXHQHqzsd+wHvnYdeX9O9vJrKF/OmojOmusz3C /92bkTEjna68JDGa9TmUU+51QZ7qvzy4lO4so4p7Lt2yE84PbnK8iws0ghu34gHryKQA ql5WHn96beTn4+6jHziJe1p5gWmrBFRN6KwhIu3I/oLQ0EsfIAhzN4bTw3v3iGpm4m4u 0QfhgowLcuzxfxyGSml4AE9aVtshuMnRfNe1JbIVpq/ZEFWc62jjnhgdCr3Jv3aPqOAD HB91u9dutyFraE2g2muIyL2V3abOqQOI624YWFWmZUWtcJ6zIEeK+EHID1Zqdaj6pfxS GLtw== X-Gm-Message-State: AOAM5315Lg9CAz2OnmmNjwXViHdcBwcPngInZmqIXw6gL/wommiL9toN FhJ3hx0MjXUCMcowp+9ZzQmV27grs/2oVlEt4XotJg== X-Google-Smtp-Source: ABdhPJz+2ugwt3MV2M7c335KpsfycuWNA1d6x4/tCRTixfpAEWF4+SuPRbjwGuDcrW0MaFTlnu3YbseYJIzRlcDu9uA= X-Received: by 2002:a2e:92d6:: with SMTP id k22mr5766745ljh.332.1600099659795; Mon, 14 Sep 2020 09:07:39 -0700 (PDT) MIME-Version: 1.0 References: <20200913070010.44053-1-songmuchun@bytedance.com> In-Reply-To: <20200913070010.44053-1-songmuchun@bytedance.com> From: Shakeel Butt Date: Mon, 14 Sep 2020 09:07:28 -0700 Message-ID: Subject: Re: [PATCH v3] mm: memcontrol: Add the missing numa_stat interface for cgroup v2 To: Muchun Song 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" X-Rspamd-Queue-Id: 5C3211803F9A4 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 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. > + > + 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