From: Muchun Song <songmuchun@bytedance.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Cgroups <cgroups@vger.kernel.org>,
Linux Memory Management List <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>, Roman Gushchin <guro@fb.com>
Subject: Re: [External] Re: [PATCH v2] mm/memcontrol: make the slab calculation consistent
Date: Sat, 5 Dec 2020 00:19:30 +0800 [thread overview]
Message-ID: <CAMZfGtUkQUoy39qyHLPTdBY_38U23yThmFaHx2yfqz5ocfMViw@mail.gmail.com> (raw)
In-Reply-To: <20201204154613.GA176901@cmpxchg.org>
On Fri, Dec 4, 2020 at 11:48 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> On Thu, Dec 03, 2020 at 11:11:11AM +0800, Muchun Song 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. Simplify the code here.
> >
> > Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> > Acked-by: Roman Gushchin <guro@fb.com>
>
> I agree that ignoring the ratio right now is not very pretty, but
>
> size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) +
> memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B);
> seq_buf_printf(&s, "slab %llu\n", size);
>
> is way easier to understand and more robust than using idx and idx + 1
> and then requiring a series of BUG_ONs to ensure these two items are
> actually adjacent and in the right order.
>
> There is a redundant call to memcg_page_state(), granted, but that
> function is extremely cheap compared with e.g. seq_buf_printf().
>
> > mm/memcontrol.c | 26 +++++++++++++++++++++-----
> > 1 file changed, 21 insertions(+), 5 deletions(-)
>
> IMO this really just complicates the code with little discernible
> upside. It's going to be a NAK from me, unfortunately.
>
>
> In retrospect, I think that memory_stats[] table was a mistake. It
> would probably be easier to implement this using a wrapper for
> memcg_page_state() that has a big switch() for unit
> conversion. Something like this:
>
> /* Translate stat items to the correct unit for memory.stat output */
> static unsigned long memcg_page_state_output(memcg, item)
> {
> unsigned long value = memcg_page_state(memcg, item);
> int unit = PAGE_SIZE;
>
> switch (item) {
> 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 MEMCG_PERCPU_B:
> unit = 1;
> break;
> case NR_SHMEM_THPS:
> case NR_FILE_THPS:
> case NR_ANON_THPS:
> unit = HPAGE_PMD_SIZE;
> break;
> case NR_KERNEL_STACK_KB:
> unit = 1024;
> break;
> }
>
> return value * unit;
> }
>
> This would fix the ratio inconsistency, get rid of the awkward mix of
> static and runtime initialization of the table, is probably about the
> same amount of code, but simpler and more obvious overall.
Good idea. I can do that :)
Thanks.
--
Yours,
Muchun
next prev parent reply other threads:[~2020-12-04 16:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 3:11 [PATCH v2] mm/memcontrol: make the slab calculation consistent Muchun Song
2020-12-04 15:46 ` Johannes Weiner
2020-12-04 16:19 ` Muchun Song [this message]
2020-12-04 22:08 ` Roman Gushchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMZfGtUkQUoy39qyHLPTdBY_38U23yThmFaHx2yfqz5ocfMViw@mail.gmail.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=guro@fb.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vdavydov.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).