From: Shakeel Butt <shakeelb@google.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Jan Kara <jack@suse.com>, Greg Thelen <gthelen@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Cgroups <cgroups@vger.kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux MM <linux-mm@kvack.org>, Jan Kara <jack@suse.cz>,
Amir Goldstein <amir73il@gmail.com>,
Christoph Lameter <cl@linux.com>,
Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Mel Gorman <mgorman@suse.de>, Vlastimil Babka <vbabka@suse.cz>,
Alexander Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 1/3] mm: memcg: remote memcg charging for kmem allocations
Date: Tue, 19 Jun 2018 16:31:18 -0700 [thread overview]
Message-ID: <CALvZod7eq3WnMU8dzA+9CmbOuf-peaCyhLuMRW2n_VyOPqjZ7A@mail.gmail.com> (raw)
In-Reply-To: <20180619162429.GB27423@cmpxchg.org>
On Tue, Jun 19, 2018 at 9:22 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> On Mon, Jun 18, 2018 at 10:13:25PM -0700, Shakeel Butt wrote:
> > @@ -248,6 +248,30 @@ static inline void memalloc_noreclaim_restore(unsigned int flags)
> > current->flags = (current->flags & ~PF_MEMALLOC) | flags;
> > }
> >
> > +#ifdef CONFIG_MEMCG
> > +static inline struct mem_cgroup *memalloc_memcg_save(struct mem_cgroup *memcg)
> > +{
> > + struct mem_cgroup *old_memcg = current->target_memcg;
> > +
> > + current->target_memcg = memcg;
> > + return old_memcg;
> > +}
> > +
> > +static inline void memalloc_memcg_restore(struct mem_cgroup *memcg)
> > +{
> > + current->target_memcg = memcg;
> > +}
>
> The use_mm() and friends naming scheme would be better here:
> memalloc_use_memcg(), memalloc_unuse_memcg(), current->active_memcg
>
Ack. Though do you still think <linux/sched/mm.h> is the right place
for these functions?
> > @@ -375,6 +376,27 @@ static __always_inline void kfree_bulk(size_t size, void **p)
> > kmem_cache_free_bulk(NULL, size, p);
> > }
> >
> > +/*
> > + * Calling kmem_cache_alloc_memcg implicitly assumes that the caller wants
> > + * a __GFP_ACCOUNT allocation. However if memcg is NULL then
> > + * kmem_cache_alloc_memcg is same as kmem_cache_alloc.
> > + */
> > +static __always_inline void *kmem_cache_alloc_memcg(struct kmem_cache *cachep,
> > + gfp_t flags,
> > + struct mem_cgroup *memcg)
> > +{
> > + struct mem_cgroup *old_memcg;
> > + void *ptr;
> > +
> > + if (!memcg)
> > + return kmem_cache_alloc(cachep, flags);
> > +
> > + old_memcg = memalloc_memcg_save(memcg);
> > + ptr = kmem_cache_alloc(cachep, flags | __GFP_ACCOUNT);
> > + memalloc_memcg_restore(old_memcg);
> > + return ptr;
>
> I'm not a big fan of these functions as an interface because it
> implies that kmem_cache_alloc() et al wouldn't charge a memcg - but
> they do, just using current's memcg.
>
> It's also a lot of churn to duplicate all the various slab functions.
>
> Can you please inline the save/restore (or use/unuse) functions into
> the callsites? If you make them handle NULL as parameters, it merely
> adds two bracketing lines around the allocation call in the callsites,
> which I think would be better to understand - in particular with a
> comment on why we are charging *that* group instead of current's.
>
Ack.
> > +static __always_inline struct mem_cgroup *get_mem_cgroup(
> > + struct mem_cgroup *memcg, struct mm_struct *mm)
> > +{
> > + if (unlikely(memcg)) {
> > + rcu_read_lock();
> > + if (css_tryget_online(&memcg->css)) {
> > + rcu_read_unlock();
> > + return memcg;
> > + }
> > + rcu_read_unlock();
> > + }
> > + return get_mem_cgroup_from_mm(mm);
> > +}
> > +
> > /**
> > * mem_cgroup_iter - iterate over memory cgroup hierarchy
> > * @root: hierarchy root
> > @@ -2260,7 +2274,7 @@ struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep)
> > if (current->memcg_kmem_skip_account)
> > return cachep;
> >
> > - memcg = get_mem_cgroup_from_mm(current->mm);
> > + memcg = get_mem_cgroup(current->target_memcg, current->mm);
>
> get_mem_cgroup_from_current(), which uses current->active_memcg if set
> and current->mm->memcg otherwise, would be a nicer abstraction IMO.
Ack.
thanks,
Shakeel
next prev parent reply other threads:[~2018-06-19 23:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 5:13 [PATCH v6 0/3] Directed kmem charging Shakeel Butt
2018-06-19 5:13 ` [PATCH 1/3] mm: memcg: remote memcg charging for kmem allocations Shakeel Butt
2018-06-19 16:24 ` Johannes Weiner
2018-06-19 23:31 ` Shakeel Butt [this message]
2018-06-20 15:22 ` Johannes Weiner
2018-06-19 5:13 ` [PATCH 2/3] fs: fsnotify: account fsnotify metadata to kmemcg Shakeel Butt
2018-06-19 7:20 ` Amir Goldstein
2018-06-19 14:15 ` Shakeel Butt
2018-06-19 5:13 ` [PATCH 3/3] fs, mm: account buffer_head " Shakeel Butt
2018-06-19 16:27 ` Johannes Weiner
2018-06-19 17:40 ` Roman Gushchin
2018-06-19 19:51 ` Shakeel Butt
2018-06-19 19:55 ` Roman Gushchin
2018-06-22 23:33 ` Shakeel Butt
2018-06-23 0:05 ` [PATCH 1/2] mm: revert mem_cgroup_put() introduction Roman Gushchin
2018-06-23 0:06 ` [PATCH 2/2] mm: introduce mem_cgroup_put() helper Roman Gushchin
2018-06-23 0:10 ` Shakeel Butt
2018-06-23 0:47 ` [PATCH 1/2] mm: revert mem_cgroup_put() introduction kbuild test robot
2018-06-19 16:11 ` [PATCH v6 0/3] Directed kmem charging Johannes Weiner
2018-06-19 22:58 ` Shakeel Butt
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=CALvZod7eq3WnMU8dzA+9CmbOuf-peaCyhLuMRW2n_VyOPqjZ7A@mail.gmail.com \
--to=shakeelb@google.com \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=cl@linux.com \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=vbabka@suse.cz \
--cc=vdavydov.dev@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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).