public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: Shakeel Butt <shakeelb@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linux MM <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	"Rik van Riel" <riel@surriel.com>,
	Christoph Lameter <cl@linux.com>,
	"Vladimir Davydov" <vdavydov.dev@gmail.com>,
	Cgroups <cgroups@vger.kernel.org>
Subject: Re: [PATCH v2 4/6] mm: unify SLAB and SLUB page accounting
Date: Wed, 24 Apr 2019 19:17:12 +0000	[thread overview]
Message-ID: <20190424191706.GA26707@tower.DHCP.thefacebook.com> (raw)
In-Reply-To: <CALvZod6A43nQgkYj38K4h_ZYLSmYp0xJwO7n44kGJx2Ut7-EVg@mail.gmail.com>

On Wed, Apr 24, 2019 at 10:23:45AM -0700, Shakeel Butt wrote:
> Hi Roman,
> 
> On Tue, Apr 23, 2019 at 9:30 PM Roman Gushchin <guro@fb.com> wrote:
> >
> > Currently the page accounting code is duplicated in SLAB and SLUB
> > internals. Let's move it into new (un)charge_slab_page helpers
> > in the slab_common.c file. These helpers will be responsible
> > for statistics (global and memcg-aware) and memcg charging.
> > So they are replacing direct memcg_(un)charge_slab() calls.
> >
> > Signed-off-by: Roman Gushchin <guro@fb.com>
> > ---
> >  mm/slab.c | 19 +++----------------
> >  mm/slab.h | 22 ++++++++++++++++++++++
> >  mm/slub.c | 14 ++------------
> >  3 files changed, 27 insertions(+), 28 deletions(-)
> >
> > diff --git a/mm/slab.c b/mm/slab.c
> > index 14466a73d057..53e6b2687102 100644
> > --- a/mm/slab.c
> > +++ b/mm/slab.c
> > @@ -1389,7 +1389,6 @@ static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
> >                                                                 int nodeid)
> >  {
> >         struct page *page;
> > -       int nr_pages;
> >
> >         flags |= cachep->allocflags;
> >
> > @@ -1399,17 +1398,11 @@ static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
> >                 return NULL;
> >         }
> >
> > -       if (memcg_charge_slab(page, flags, cachep->gfporder, cachep)) {
> > +       if (charge_slab_page(page, flags, cachep->gfporder, cachep)) {
> >                 __free_pages(page, cachep->gfporder);
> >                 return NULL;
> >         }
> >
> > -       nr_pages = (1 << cachep->gfporder);
> > -       if (cachep->flags & SLAB_RECLAIM_ACCOUNT)
> > -               mod_lruvec_page_state(page, NR_SLAB_RECLAIMABLE, nr_pages);
> > -       else
> > -               mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE, nr_pages);
> > -
> >         __SetPageSlab(page);
> >         /* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */
> >         if (sk_memalloc_socks() && page_is_pfmemalloc(page))
> > @@ -1424,12 +1417,6 @@ static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
> >  static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
> >  {
> >         int order = cachep->gfporder;
> > -       unsigned long nr_freed = (1 << order);
> > -
> > -       if (cachep->flags & SLAB_RECLAIM_ACCOUNT)
> > -               mod_lruvec_page_state(page, NR_SLAB_RECLAIMABLE, -nr_freed);
> > -       else
> > -               mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE, -nr_freed);
> >
> >         BUG_ON(!PageSlab(page));
> >         __ClearPageSlabPfmemalloc(page);
> > @@ -1438,8 +1425,8 @@ static void kmem_freepages(struct kmem_cache *cachep, struct page *page)
> >         page->mapping = NULL;
> >
> >         if (current->reclaim_state)
> > -               current->reclaim_state->reclaimed_slab += nr_freed;
> > -       memcg_uncharge_slab(page, order, cachep);
> > +               current->reclaim_state->reclaimed_slab += 1 << order;
> > +       uncharge_slab_page(page, order, cachep);
> >         __free_pages(page, order);
> >  }
> >
> > diff --git a/mm/slab.h b/mm/slab.h
> > index 4a261c97c138..0f5c5444acf1 100644
> > --- a/mm/slab.h
> > +++ b/mm/slab.h
> > @@ -205,6 +205,12 @@ ssize_t slabinfo_write(struct file *file, const char __user *buffer,
> >  void __kmem_cache_free_bulk(struct kmem_cache *, size_t, void **);
> >  int __kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
> >
> > +static inline int cache_vmstat_idx(struct kmem_cache *s)
> > +{
> > +       return (s->flags & SLAB_RECLAIM_ACCOUNT) ?
> > +               NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE;
> > +}
> > +
> >  #ifdef CONFIG_MEMCG_KMEM
> >
> >  /* List of all root caches. */
> > @@ -352,6 +358,22 @@ static inline void memcg_link_cache(struct kmem_cache *s,
> >
> >  #endif /* CONFIG_MEMCG_KMEM */
> >
> > +static __always_inline int charge_slab_page(struct page *page,
> > +                                           gfp_t gfp, int order,
> > +                                           struct kmem_cache *s)
> > +{
> > +       memcg_charge_slab(page, gfp, order, s);
> 
> This does not seem right. Why the return of memcg_charge_slab is ignored?

Hi Shakeel!

Right, it's a bug. It's actually fixed later in the patchset
(in "mm: rework non-root kmem_cache lifecycle management"),
so the final result looks correct to me. Anyway, I'll fix it.

How does everything else look to you?

Thank you!

  reply	other threads:[~2019-04-24 19:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 21:31 [PATCH v2 0/6] mm: reparent slab memory on cgroup removal Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 1/6] mm: postpone kmem_cache memcg pointer initialization to memcg_link_cache() Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 2/6] mm: generalize postponed non-root kmem_cache deactivation Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 3/6] mm: introduce __memcg_kmem_uncharge_memcg() Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 4/6] mm: unify SLAB and SLUB page accounting Roman Gushchin
2019-04-24 17:23   ` Shakeel Butt
2019-04-24 19:17     ` Roman Gushchin [this message]
2019-04-24 19:40       ` Shakeel Butt
2019-04-24 19:51         ` Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 5/6] mm: rework non-root kmem_cache lifecycle management Roman Gushchin
2019-04-23 21:31 ` [PATCH v2 6/6] mm: reparent slab memory on cgroup removal 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=20190424191706.GA26707@tower.DHCP.thefacebook.com \
    --to=guro@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=cl@linux.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=riel@surriel.com \
    --cc=shakeelb@google.com \
    --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