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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 8E1EBC4361B for ; Tue, 8 Dec 2020 07:54:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5995C23A51 for ; Tue, 8 Dec 2020 07:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbgLHHyW (ORCPT ); Tue, 8 Dec 2020 02:54:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbgLHHyW (ORCPT ); Tue, 8 Dec 2020 02:54:22 -0500 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04BB7C0613D6 for ; Mon, 7 Dec 2020 23:53:42 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id y8so577967plp.8 for ; Mon, 07 Dec 2020 23:53:41 -0800 (PST) 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=6yOAVZjGe0LBykCQztVKp2D4Gmc2eJlF3ZDhvK2CW4w=; b=I6+h+plxzfDytT3JY5089iYAUGryc03SX1u46qY0mKqZS/nBI9KbegEu4vDHyaZvR8 1gN8VtP1D147cTFIn3dimmElmmW76jgsNjvyGHLhCTrWY/PbxZ2JNdKmCFX4ErbFkjK6 HjxKS1TkSg3AOZFe/5hrIX2hAd2b44RDj1bMTGPEEXKy3iMOS7DPGQyzMTKIGLaEinoL QMwcLKR5xgMkmSRwfs3nkZLQtNfN/Kn3deg57xuctwnL+SjgCSeNvHrAVcebgTrCUkC9 5VfC3mjMfe9zjGzylGzR1BMiECSMMYtrSnV24QfimsEQvbnmPOGGuiScUPM2EVmWBFSc mGsg== 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=6yOAVZjGe0LBykCQztVKp2D4Gmc2eJlF3ZDhvK2CW4w=; b=Bi0ah/cGBgNdah1mwT56v1v682sIsa6UcllgxkPp4pQU5Iub5vnCvAtspPUx1ka0Cz NlGYR/AkGy8fvATXS3mUhY60dwcBNjfd7SDObxfRO3Ippl9Sg0kypw26YS/a9HX12O1c g8JvW6x4afmbVy4nP3NlkHQqL08s6FgyMWufYyb7K8DD1uy4WgpCpHo5SwHVwuDzl3SA O1lYiZLGKmjhejWL2NK3XS4lpz9mHQ91yrj0Z8qtKIuXAQClTTLZEP0fRkcnw2o8g5Jo Cz4p49qEv9ubAE4etdvTyfmUBlX5yIWT6LePil6n8KBNNWFyHRGyQul2vE2n0vDvcfrp 5ABw== X-Gm-Message-State: AOAM530OzrkxyXfP84UQzLV7UCGb021IMkrxtDUoolIWO3uQv4J0seCy BF7H+/tK84SxOHm/PlzQoW1v2EqmA1Ykm2b2ZtZ5/A== X-Google-Smtp-Source: ABdhPJwCu+RkIOjZ4EZmnfUZRQMKj2S2yjYBnRNWVVVOr4SzPLOF3SVcLmbjbu4HCM5OrM7HcnuIy//60ukVPxOJPPs= X-Received: by 2002:a17:902:76c8:b029:d9:d6c3:357d with SMTP id j8-20020a17090276c8b02900d9d6c3357dmr20261768plt.34.1607414021513; Mon, 07 Dec 2020 23:53:41 -0800 (PST) MIME-Version: 1.0 References: <20201208041847.72122-1-songmuchun@bytedance.com> <20201208041847.72122-8-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 8 Dec 2020 15:53:05 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 7/7] mm: memcontrol: make the slab calculation consistent To: Pankaj Gupta Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexey Dobriyan , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Hugh Dickins , Shakeel Butt , Roman Gushchin , Sami Tolvanen , Feng Tang , Neil Brown , Joonsoo Kim , Randy Dunlap , LKML , linux-fsdevel , Linux MM , Cgroups Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 8, 2020 at 3:21 PM Pankaj Gupta wrote: > > > Although the ratio of the slab is one, we also should read the ratio > > from the related memory_stats instead of hard-coding. And the local > > variable of size is already the value of slab_unreclaimable. So we > > do not need to read again. > > > > We can drop the ratio in struct memory_stat. This can make the code > > clean and simple. And get rid of the awkward mix of static and runtime > > initialization of the memory_stats table. > > > > Signed-off-by: Muchun Song > > --- > > mm/memcontrol.c | 112 ++++++++++++++++++++++++++++++++++++-------------------- > > 1 file changed, 73 insertions(+), 39 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index a40797a27f87..841ea37cc123 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1511,49 +1511,78 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) > > > > struct memory_stat { > > const char *name; > > - unsigned int ratio; > > unsigned int idx; > > }; > > > > static const struct memory_stat memory_stats[] = { > > - { "anon", PAGE_SIZE, NR_ANON_MAPPED }, > > - { "file", PAGE_SIZE, NR_FILE_PAGES }, > > - { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, > > - { "pagetables", PAGE_SIZE, NR_PAGETABLE }, > > - { "percpu", 1, MEMCG_PERCPU_B }, > > - { "sock", PAGE_SIZE, MEMCG_SOCK }, > > - { "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 }, > > + { "anon", NR_ANON_MAPPED }, > > + { "file", NR_FILE_PAGES }, > > + { "kernel_stack", NR_KERNEL_STACK_KB }, > > + { "pagetables", NR_PAGETABLE }, > > + { "percpu", MEMCG_PERCPU_B }, > > + { "sock", MEMCG_SOCK }, > > + { "shmem", NR_SHMEM }, > > + { "file_mapped", NR_FILE_MAPPED }, > > + { "file_dirty", NR_FILE_DIRTY }, > > + { "file_writeback", NR_WRITEBACK }, > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > > - { "anon_thp", PAGE_SIZE, NR_ANON_THPS }, > > - { "file_thp", PAGE_SIZE, NR_FILE_THPS }, > > - { "shmem_thp", PAGE_SIZE, NR_SHMEM_THPS }, > > + { "anon_thp", NR_ANON_THPS }, > > + { "file_thp", NR_FILE_THPS }, > > + { "shmem_thp", NR_SHMEM_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 }, > > - > > - /* > > - * Note: The slab_reclaimable and slab_unreclaimable must be > > - * together and slab_reclaimable must be in front. > > - */ > > - { "slab_reclaimable", 1, NR_SLAB_RECLAIMABLE_B }, > > - { "slab_unreclaimable", 1, NR_SLAB_UNRECLAIMABLE_B }, > > + { "inactive_anon", NR_INACTIVE_ANON }, > > + { "active_anon", NR_ACTIVE_ANON }, > > + { "inactive_file", NR_INACTIVE_FILE }, > > + { "active_file", NR_ACTIVE_FILE }, > > + { "unevictable", NR_UNEVICTABLE }, > > + { "slab_reclaimable", NR_SLAB_RECLAIMABLE_B }, > > + { "slab_unreclaimable", NR_SLAB_UNRECLAIMABLE_B }, > > > > /* The memory events */ > > - { "workingset_refault_anon", 1, WORKINGSET_REFAULT_ANON }, > > - { "workingset_refault_file", 1, WORKINGSET_REFAULT_FILE }, > > - { "workingset_activate_anon", 1, WORKINGSET_ACTIVATE_ANON }, > > - { "workingset_activate_file", 1, WORKINGSET_ACTIVATE_FILE }, > > - { "workingset_restore_anon", 1, WORKINGSET_RESTORE_ANON }, > > - { "workingset_restore_file", 1, WORKINGSET_RESTORE_FILE }, > > - { "workingset_nodereclaim", 1, WORKINGSET_NODERECLAIM }, > > + { "workingset_refault_anon", WORKINGSET_REFAULT_ANON }, > > + { "workingset_refault_file", WORKINGSET_REFAULT_FILE }, > > + { "workingset_activate_anon", WORKINGSET_ACTIVATE_ANON }, > > + { "workingset_activate_file", WORKINGSET_ACTIVATE_FILE }, > > + { "workingset_restore_anon", WORKINGSET_RESTORE_ANON }, > > + { "workingset_restore_file", WORKINGSET_RESTORE_FILE }, > > + { "workingset_nodereclaim", WORKINGSET_NODERECLAIM }, > > }; > > > > +/* Translate stat items to the correct unit for memory.stat output */ > > +static int memcg_page_state_unit(int item) > > +{ > > + int unit; > > + > > + switch (item) { > > + case MEMCG_PERCPU_B: > > + case NR_SLAB_RECLAIMABLE_B: > > + case NR_SLAB_UNRECLAIMABLE_B: > > + case WORKINGSET_REFAULT_ANON: > > + case WORKINGSET_REFAULT_FILE: > > + case WORKINGSET_ACTIVATE_ANON: > > + case WORKINGSET_ACTIVATE_FILE: > > + case WORKINGSET_RESTORE_ANON: > > + case WORKINGSET_RESTORE_FILE: > > + case WORKINGSET_NODERECLAIM: > > + unit = 1; > > + break; > > + case NR_KERNEL_STACK_KB: > > + unit = SZ_1K; > > + break; > > + default: > > + unit = PAGE_SIZE; > > + break; > break not needed here, or maybe we can return for every case, > that will avoid "unit" variable. Yeah, thanks. > > > + } > > + > > + return unit; > > +} > > + > > +static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, > > + int item) > > +{ > > + return memcg_page_state(memcg, item) * memcg_page_state_unit(item); > > +} > > + > > static char *memory_stat_format(struct mem_cgroup *memcg) > > { > > struct seq_buf s; > > @@ -1577,13 +1606,12 @@ static char *memory_stat_format(struct mem_cgroup *memcg) > > for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { > > u64 size; > > > > - size = memcg_page_state(memcg, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = memcg_page_state_output(memcg, memory_stats[i].idx); > > seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size); > > > > if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) { > > - size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + > > - memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B); > > + size += > (memcg, > > + NR_SLAB_RECLAIMABLE_B); > > seq_buf_printf(&s, "slab %llu\n", size); > > } > > } > > @@ -6377,6 +6405,12 @@ static int memory_stat_show(struct seq_file *m, void *v) > > } > > > > #ifdef CONFIG_NUMA > > +static inline unsigned long lruvec_page_state_output(struct lruvec *lruvec, > > + int item) > > +{ > > + return lruvec_page_state(lruvec, item) * memcg_page_state_unit(item); > > +} > > + > > static int memory_numa_stat_show(struct seq_file *m, void *v) > > { > > int i; > > @@ -6394,8 +6428,8 @@ static int memory_numa_stat_show(struct seq_file *m, void *v) > > struct lruvec *lruvec; > > > > lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); > > - size = lruvec_page_state(lruvec, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = lruvec_page_state_output(lruvec, > > + memory_stats[i].idx); > > seq_printf(m, " N%d=%llu", nid, size); > > } > > seq_putc(m, '\n'); > > -- > > 2.11.0 > > > > -- Yours, Muchun 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=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 23CF7C4361B for ; Tue, 8 Dec 2020 07:53:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A62B923A5B for ; Tue, 8 Dec 2020 07:53:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A62B923A5B 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 3743A6B005C; Tue, 8 Dec 2020 02:53:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 323AD6B005D; Tue, 8 Dec 2020 02:53:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 213A06B0068; Tue, 8 Dec 2020 02:53:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id 0A3436B005C for ; Tue, 8 Dec 2020 02:53:44 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CB7E3362A for ; Tue, 8 Dec 2020 07:53:43 +0000 (UTC) X-FDA: 77569350726.17.war33_3600008273e5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id AE432180D0180 for ; Tue, 8 Dec 2020 07:53:43 +0000 (UTC) X-HE-Tag: war33_3600008273e5 X-Filterd-Recvd-Size: 12357 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 07:53:42 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id 4so6574481plk.5 for ; Mon, 07 Dec 2020 23:53:42 -0800 (PST) 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=6yOAVZjGe0LBykCQztVKp2D4Gmc2eJlF3ZDhvK2CW4w=; b=I6+h+plxzfDytT3JY5089iYAUGryc03SX1u46qY0mKqZS/nBI9KbegEu4vDHyaZvR8 1gN8VtP1D147cTFIn3dimmElmmW76jgsNjvyGHLhCTrWY/PbxZ2JNdKmCFX4ErbFkjK6 HjxKS1TkSg3AOZFe/5hrIX2hAd2b44RDj1bMTGPEEXKy3iMOS7DPGQyzMTKIGLaEinoL QMwcLKR5xgMkmSRwfs3nkZLQtNfN/Kn3deg57xuctwnL+SjgCSeNvHrAVcebgTrCUkC9 5VfC3mjMfe9zjGzylGzR1BMiECSMMYtrSnV24QfimsEQvbnmPOGGuiScUPM2EVmWBFSc mGsg== 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=6yOAVZjGe0LBykCQztVKp2D4Gmc2eJlF3ZDhvK2CW4w=; b=kaB8p8xjIk3aPMoWrxD2mN/d3uSyqA6K1wknwebGAhVFFDHIGT7C1fzUz9gqMmvRf/ drgbC+oSyW2mXAoBBr7VgiUiisziMHQXkp+EfhzyVmng0dkThs70nf831wBav3KIcFb5 nwlIychxYg888EkNVCFkNdNGj4+NFhRX83INaOkT1HnyPr+q1bek5mSY2TwddcFeQebI +PTkNvSQa+ACAJPJJxBfAMjA+SAThgb5wbD+CP8JukRDufViPHuQEDlYs7t2C2K47WvD AoDLNyd3t7/hKMdZd1UFApq3J7fZRbR0F5I15s8QJfbGpgRM+wuPWSkkOMatgJVebwys s07Q== X-Gm-Message-State: AOAM5327vKyrArPI3zvqbQ27jxUEpKX+TDMLhFrHKXaJO05ONQx7Qtwp kMZvslNBzzEPMHSZPY4eeJJ29FkKZarrlFT71jXMhw== X-Google-Smtp-Source: ABdhPJwCu+RkIOjZ4EZmnfUZRQMKj2S2yjYBnRNWVVVOr4SzPLOF3SVcLmbjbu4HCM5OrM7HcnuIy//60ukVPxOJPPs= X-Received: by 2002:a17:902:76c8:b029:d9:d6c3:357d with SMTP id j8-20020a17090276c8b02900d9d6c3357dmr20261768plt.34.1607414021513; Mon, 07 Dec 2020 23:53:41 -0800 (PST) MIME-Version: 1.0 References: <20201208041847.72122-1-songmuchun@bytedance.com> <20201208041847.72122-8-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Tue, 8 Dec 2020 15:53:05 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 7/7] mm: memcontrol: make the slab calculation consistent To: Pankaj Gupta Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexey Dobriyan , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Hugh Dickins , Shakeel Butt , Roman Gushchin , Sami Tolvanen , Feng Tang , Neil Brown , Joonsoo Kim , Randy Dunlap , LKML , linux-fsdevel , Linux MM , Cgroups Content-Type: text/plain; charset="UTF-8" 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 Tue, Dec 8, 2020 at 3:21 PM Pankaj Gupta wrote: > > > Although the ratio of the slab is one, we also should read the ratio > > from the related memory_stats instead of hard-coding. And the local > > variable of size is already the value of slab_unreclaimable. So we > > do not need to read again. > > > > We can drop the ratio in struct memory_stat. This can make the code > > clean and simple. And get rid of the awkward mix of static and runtime > > initialization of the memory_stats table. > > > > Signed-off-by: Muchun Song > > --- > > mm/memcontrol.c | 112 ++++++++++++++++++++++++++++++++++++-------------------- > > 1 file changed, 73 insertions(+), 39 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index a40797a27f87..841ea37cc123 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1511,49 +1511,78 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) > > > > struct memory_stat { > > const char *name; > > - unsigned int ratio; > > unsigned int idx; > > }; > > > > static const struct memory_stat memory_stats[] = { > > - { "anon", PAGE_SIZE, NR_ANON_MAPPED }, > > - { "file", PAGE_SIZE, NR_FILE_PAGES }, > > - { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, > > - { "pagetables", PAGE_SIZE, NR_PAGETABLE }, > > - { "percpu", 1, MEMCG_PERCPU_B }, > > - { "sock", PAGE_SIZE, MEMCG_SOCK }, > > - { "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 }, > > + { "anon", NR_ANON_MAPPED }, > > + { "file", NR_FILE_PAGES }, > > + { "kernel_stack", NR_KERNEL_STACK_KB }, > > + { "pagetables", NR_PAGETABLE }, > > + { "percpu", MEMCG_PERCPU_B }, > > + { "sock", MEMCG_SOCK }, > > + { "shmem", NR_SHMEM }, > > + { "file_mapped", NR_FILE_MAPPED }, > > + { "file_dirty", NR_FILE_DIRTY }, > > + { "file_writeback", NR_WRITEBACK }, > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > > - { "anon_thp", PAGE_SIZE, NR_ANON_THPS }, > > - { "file_thp", PAGE_SIZE, NR_FILE_THPS }, > > - { "shmem_thp", PAGE_SIZE, NR_SHMEM_THPS }, > > + { "anon_thp", NR_ANON_THPS }, > > + { "file_thp", NR_FILE_THPS }, > > + { "shmem_thp", NR_SHMEM_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 }, > > - > > - /* > > - * Note: The slab_reclaimable and slab_unreclaimable must be > > - * together and slab_reclaimable must be in front. > > - */ > > - { "slab_reclaimable", 1, NR_SLAB_RECLAIMABLE_B }, > > - { "slab_unreclaimable", 1, NR_SLAB_UNRECLAIMABLE_B }, > > + { "inactive_anon", NR_INACTIVE_ANON }, > > + { "active_anon", NR_ACTIVE_ANON }, > > + { "inactive_file", NR_INACTIVE_FILE }, > > + { "active_file", NR_ACTIVE_FILE }, > > + { "unevictable", NR_UNEVICTABLE }, > > + { "slab_reclaimable", NR_SLAB_RECLAIMABLE_B }, > > + { "slab_unreclaimable", NR_SLAB_UNRECLAIMABLE_B }, > > > > /* The memory events */ > > - { "workingset_refault_anon", 1, WORKINGSET_REFAULT_ANON }, > > - { "workingset_refault_file", 1, WORKINGSET_REFAULT_FILE }, > > - { "workingset_activate_anon", 1, WORKINGSET_ACTIVATE_ANON }, > > - { "workingset_activate_file", 1, WORKINGSET_ACTIVATE_FILE }, > > - { "workingset_restore_anon", 1, WORKINGSET_RESTORE_ANON }, > > - { "workingset_restore_file", 1, WORKINGSET_RESTORE_FILE }, > > - { "workingset_nodereclaim", 1, WORKINGSET_NODERECLAIM }, > > + { "workingset_refault_anon", WORKINGSET_REFAULT_ANON }, > > + { "workingset_refault_file", WORKINGSET_REFAULT_FILE }, > > + { "workingset_activate_anon", WORKINGSET_ACTIVATE_ANON }, > > + { "workingset_activate_file", WORKINGSET_ACTIVATE_FILE }, > > + { "workingset_restore_anon", WORKINGSET_RESTORE_ANON }, > > + { "workingset_restore_file", WORKINGSET_RESTORE_FILE }, > > + { "workingset_nodereclaim", WORKINGSET_NODERECLAIM }, > > }; > > > > +/* Translate stat items to the correct unit for memory.stat output */ > > +static int memcg_page_state_unit(int item) > > +{ > > + int unit; > > + > > + switch (item) { > > + case MEMCG_PERCPU_B: > > + case NR_SLAB_RECLAIMABLE_B: > > + case NR_SLAB_UNRECLAIMABLE_B: > > + case WORKINGSET_REFAULT_ANON: > > + case WORKINGSET_REFAULT_FILE: > > + case WORKINGSET_ACTIVATE_ANON: > > + case WORKINGSET_ACTIVATE_FILE: > > + case WORKINGSET_RESTORE_ANON: > > + case WORKINGSET_RESTORE_FILE: > > + case WORKINGSET_NODERECLAIM: > > + unit = 1; > > + break; > > + case NR_KERNEL_STACK_KB: > > + unit = SZ_1K; > > + break; > > + default: > > + unit = PAGE_SIZE; > > + break; > break not needed here, or maybe we can return for every case, > that will avoid "unit" variable. Yeah, thanks. > > > + } > > + > > + return unit; > > +} > > + > > +static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, > > + int item) > > +{ > > + return memcg_page_state(memcg, item) * memcg_page_state_unit(item); > > +} > > + > > static char *memory_stat_format(struct mem_cgroup *memcg) > > { > > struct seq_buf s; > > @@ -1577,13 +1606,12 @@ static char *memory_stat_format(struct mem_cgroup *memcg) > > for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { > > u64 size; > > > > - size = memcg_page_state(memcg, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = memcg_page_state_output(memcg, memory_stats[i].idx); > > seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size); > > > > if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) { > > - size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + > > - memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B); > > + size += > (memcg, > > + NR_SLAB_RECLAIMABLE_B); > > seq_buf_printf(&s, "slab %llu\n", size); > > } > > } > > @@ -6377,6 +6405,12 @@ static int memory_stat_show(struct seq_file *m, void *v) > > } > > > > #ifdef CONFIG_NUMA > > +static inline unsigned long lruvec_page_state_output(struct lruvec *lruvec, > > + int item) > > +{ > > + return lruvec_page_state(lruvec, item) * memcg_page_state_unit(item); > > +} > > + > > static int memory_numa_stat_show(struct seq_file *m, void *v) > > { > > int i; > > @@ -6394,8 +6428,8 @@ static int memory_numa_stat_show(struct seq_file *m, void *v) > > struct lruvec *lruvec; > > > > lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); > > - size = lruvec_page_state(lruvec, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = lruvec_page_state_output(lruvec, > > + memory_stats[i].idx); > > seq_printf(m, " N%d=%llu", nid, size); > > } > > seq_putc(m, '\n'); > > -- > > 2.11.0 > > > > -- Yours, Muchun From mboxrd@z Thu Jan 1 00:00:00 1970 From: Muchun Song Subject: Re: [External] Re: [PATCH v3 7/7] mm: memcontrol: make the slab calculation consistent Date: Tue, 8 Dec 2020 15:53:05 +0800 Message-ID: References: <20201208041847.72122-1-songmuchun@bytedance.com> <20201208041847.72122-8-songmuchun@bytedance.com> Mime-Version: 1.0 Return-path: 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=6yOAVZjGe0LBykCQztVKp2D4Gmc2eJlF3ZDhvK2CW4w=; b=I6+h+plxzfDytT3JY5089iYAUGryc03SX1u46qY0mKqZS/nBI9KbegEu4vDHyaZvR8 1gN8VtP1D147cTFIn3dimmElmmW76jgsNjvyGHLhCTrWY/PbxZ2JNdKmCFX4ErbFkjK6 HjxKS1TkSg3AOZFe/5hrIX2hAd2b44RDj1bMTGPEEXKy3iMOS7DPGQyzMTKIGLaEinoL QMwcLKR5xgMkmSRwfs3nkZLQtNfN/Kn3deg57xuctwnL+SjgCSeNvHrAVcebgTrCUkC9 5VfC3mjMfe9zjGzylGzR1BMiECSMMYtrSnV24QfimsEQvbnmPOGGuiScUPM2EVmWBFSc mGsg== In-Reply-To: List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Pankaj Gupta Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Alexey Dobriyan , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Hugh Dickins , Shakeel Butt , Roman Gushchin , Sami Tolvanen , Feng Tang , Neil Brown , Joonsoo Kim , Randy Dunlap , LKML , linux-fsdevel , Linux MM , Cgroups On Tue, Dec 8, 2020 at 3:21 PM Pankaj Gupta wrote: > > > Although the ratio of the slab is one, we also should read the ratio > > from the related memory_stats instead of hard-coding. And the local > > variable of size is already the value of slab_unreclaimable. So we > > do not need to read again. > > > > We can drop the ratio in struct memory_stat. This can make the code > > clean and simple. And get rid of the awkward mix of static and runtime > > initialization of the memory_stats table. > > > > Signed-off-by: Muchun Song > > --- > > mm/memcontrol.c | 112 ++++++++++++++++++++++++++++++++++++-------------------- > > 1 file changed, 73 insertions(+), 39 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index a40797a27f87..841ea37cc123 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -1511,49 +1511,78 @@ static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg) > > > > struct memory_stat { > > const char *name; > > - unsigned int ratio; > > unsigned int idx; > > }; > > > > static const struct memory_stat memory_stats[] = { > > - { "anon", PAGE_SIZE, NR_ANON_MAPPED }, > > - { "file", PAGE_SIZE, NR_FILE_PAGES }, > > - { "kernel_stack", 1024, NR_KERNEL_STACK_KB }, > > - { "pagetables", PAGE_SIZE, NR_PAGETABLE }, > > - { "percpu", 1, MEMCG_PERCPU_B }, > > - { "sock", PAGE_SIZE, MEMCG_SOCK }, > > - { "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 }, > > + { "anon", NR_ANON_MAPPED }, > > + { "file", NR_FILE_PAGES }, > > + { "kernel_stack", NR_KERNEL_STACK_KB }, > > + { "pagetables", NR_PAGETABLE }, > > + { "percpu", MEMCG_PERCPU_B }, > > + { "sock", MEMCG_SOCK }, > > + { "shmem", NR_SHMEM }, > > + { "file_mapped", NR_FILE_MAPPED }, > > + { "file_dirty", NR_FILE_DIRTY }, > > + { "file_writeback", NR_WRITEBACK }, > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > > - { "anon_thp", PAGE_SIZE, NR_ANON_THPS }, > > - { "file_thp", PAGE_SIZE, NR_FILE_THPS }, > > - { "shmem_thp", PAGE_SIZE, NR_SHMEM_THPS }, > > + { "anon_thp", NR_ANON_THPS }, > > + { "file_thp", NR_FILE_THPS }, > > + { "shmem_thp", NR_SHMEM_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 }, > > - > > - /* > > - * Note: The slab_reclaimable and slab_unreclaimable must be > > - * together and slab_reclaimable must be in front. > > - */ > > - { "slab_reclaimable", 1, NR_SLAB_RECLAIMABLE_B }, > > - { "slab_unreclaimable", 1, NR_SLAB_UNRECLAIMABLE_B }, > > + { "inactive_anon", NR_INACTIVE_ANON }, > > + { "active_anon", NR_ACTIVE_ANON }, > > + { "inactive_file", NR_INACTIVE_FILE }, > > + { "active_file", NR_ACTIVE_FILE }, > > + { "unevictable", NR_UNEVICTABLE }, > > + { "slab_reclaimable", NR_SLAB_RECLAIMABLE_B }, > > + { "slab_unreclaimable", NR_SLAB_UNRECLAIMABLE_B }, > > > > /* The memory events */ > > - { "workingset_refault_anon", 1, WORKINGSET_REFAULT_ANON }, > > - { "workingset_refault_file", 1, WORKINGSET_REFAULT_FILE }, > > - { "workingset_activate_anon", 1, WORKINGSET_ACTIVATE_ANON }, > > - { "workingset_activate_file", 1, WORKINGSET_ACTIVATE_FILE }, > > - { "workingset_restore_anon", 1, WORKINGSET_RESTORE_ANON }, > > - { "workingset_restore_file", 1, WORKINGSET_RESTORE_FILE }, > > - { "workingset_nodereclaim", 1, WORKINGSET_NODERECLAIM }, > > + { "workingset_refault_anon", WORKINGSET_REFAULT_ANON }, > > + { "workingset_refault_file", WORKINGSET_REFAULT_FILE }, > > + { "workingset_activate_anon", WORKINGSET_ACTIVATE_ANON }, > > + { "workingset_activate_file", WORKINGSET_ACTIVATE_FILE }, > > + { "workingset_restore_anon", WORKINGSET_RESTORE_ANON }, > > + { "workingset_restore_file", WORKINGSET_RESTORE_FILE }, > > + { "workingset_nodereclaim", WORKINGSET_NODERECLAIM }, > > }; > > > > +/* Translate stat items to the correct unit for memory.stat output */ > > +static int memcg_page_state_unit(int item) > > +{ > > + int unit; > > + > > + switch (item) { > > + case MEMCG_PERCPU_B: > > + case NR_SLAB_RECLAIMABLE_B: > > + case NR_SLAB_UNRECLAIMABLE_B: > > + case WORKINGSET_REFAULT_ANON: > > + case WORKINGSET_REFAULT_FILE: > > + case WORKINGSET_ACTIVATE_ANON: > > + case WORKINGSET_ACTIVATE_FILE: > > + case WORKINGSET_RESTORE_ANON: > > + case WORKINGSET_RESTORE_FILE: > > + case WORKINGSET_NODERECLAIM: > > + unit = 1; > > + break; > > + case NR_KERNEL_STACK_KB: > > + unit = SZ_1K; > > + break; > > + default: > > + unit = PAGE_SIZE; > > + break; > break not needed here, or maybe we can return for every case, > that will avoid "unit" variable. Yeah, thanks. > > > + } > > + > > + return unit; > > +} > > + > > +static inline unsigned long memcg_page_state_output(struct mem_cgroup *memcg, > > + int item) > > +{ > > + return memcg_page_state(memcg, item) * memcg_page_state_unit(item); > > +} > > + > > static char *memory_stat_format(struct mem_cgroup *memcg) > > { > > struct seq_buf s; > > @@ -1577,13 +1606,12 @@ static char *memory_stat_format(struct mem_cgroup *memcg) > > for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { > > u64 size; > > > > - size = memcg_page_state(memcg, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = memcg_page_state_output(memcg, memory_stats[i].idx); > > seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size); > > > > if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) { > > - size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + > > - memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B); > > + size += > (memcg, > > + NR_SLAB_RECLAIMABLE_B); > > seq_buf_printf(&s, "slab %llu\n", size); > > } > > } > > @@ -6377,6 +6405,12 @@ static int memory_stat_show(struct seq_file *m, void *v) > > } > > > > #ifdef CONFIG_NUMA > > +static inline unsigned long lruvec_page_state_output(struct lruvec *lruvec, > > + int item) > > +{ > > + return lruvec_page_state(lruvec, item) * memcg_page_state_unit(item); > > +} > > + > > static int memory_numa_stat_show(struct seq_file *m, void *v) > > { > > int i; > > @@ -6394,8 +6428,8 @@ static int memory_numa_stat_show(struct seq_file *m, void *v) > > struct lruvec *lruvec; > > > > lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(nid)); > > - size = lruvec_page_state(lruvec, memory_stats[i].idx); > > - size *= memory_stats[i].ratio; > > + size = lruvec_page_state_output(lruvec, > > + memory_stats[i].idx); > > seq_printf(m, " N%d=%llu", nid, size); > > } > > seq_putc(m, '\n'); > > -- > > 2.11.0 > > > > -- Yours, Muchun