Message ID | 20190508202458.550808-8-guro@fb.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm: reparent slab memory on cgroup removal | expand |
From: Roman Gushchin <guro@fb.com> Date: Wed, May 8, 2019 at 1:40 PM To: Andrew Morton, Shakeel Butt Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>, <kernel-team@fb.com>, Johannes Weiner, Michal Hocko, Rik van Riel, Christoph Lameter, Vladimir Davydov, <cgroups@vger.kernel.org>, Roman Gushchin > Switching to an indirect scheme of getting mem_cgroup pointer for > !root slab pages broke /proc/kpagecgroup interface for them. > > Let's fix it by learning page_cgroup_ino() how to get memcg > pointer for slab pages. > > Reported-by: Shakeel Butt <shakeelb@google.com> > Signed-off-by: Roman Gushchin <guro@fb.com> > --- > mm/memcontrol.c | 5 ++++- > mm/slab.h | 21 +++++++++++++++++++++ > mm/slab_common.c | 1 + > 3 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 6e4d9ed16069..8114838759f6 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -494,7 +494,10 @@ ino_t page_cgroup_ino(struct page *page) > unsigned long ino = 0; > > rcu_read_lock(); > - memcg = READ_ONCE(page->mem_cgroup); > + if (PageSlab(page)) > + memcg = memcg_from_slab_page(page); > + else > + memcg = READ_ONCE(page->mem_cgroup); > while (memcg && !(memcg->css.flags & CSS_ONLINE)) > memcg = parent_mem_cgroup(memcg); > if (memcg) > diff --git a/mm/slab.h b/mm/slab.h > index acdc1810639d..cb684fbe2cc2 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -256,6 +256,22 @@ static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s) > return s->memcg_params.root_cache; > } > Can you please document the preconditions of this function? It seems like it must be PageSlab() then why need to check PageTail and do compound_head(). > +static inline struct mem_cgroup *memcg_from_slab_page(struct page *page) > +{ > + struct kmem_cache *s; > + > + WARN_ON_ONCE(!rcu_read_lock_held()); > + > + if (PageTail(page)) > + page = compound_head(page); > + > + s = READ_ONCE(page->slab_cache); > + if (s && !is_root_cache(s)) > + return rcu_dereference(s->memcg_params.memcg); > + > + return NULL; > +} > + > static __always_inline int memcg_charge_slab(struct page *page, > gfp_t gfp, int order, > struct kmem_cache *s) > @@ -338,6 +354,11 @@ static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s) > return s; > } > > +static inline struct mem_cgroup *memcg_from_slab_page(struct page *page) > +{ > + return NULL; > +} > + > static inline int memcg_charge_slab(struct page *page, gfp_t gfp, int order, > struct kmem_cache *s) > { > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 36673a43ed31..0cfdad0a0aac 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -253,6 +253,7 @@ static void memcg_unlink_cache(struct kmem_cache *s) > list_del(&s->memcg_params.kmem_caches_node); > mem_cgroup_put(rcu_dereference_protected(s->memcg_params.memcg, > lockdep_is_held(&slab_mutex))); > + rcu_assign_pointer(s->memcg_params.memcg, NULL); > } > } > #else > -- > 2.20.1 >
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6e4d9ed16069..8114838759f6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -494,7 +494,10 @@ ino_t page_cgroup_ino(struct page *page) unsigned long ino = 0; rcu_read_lock(); - memcg = READ_ONCE(page->mem_cgroup); + if (PageSlab(page)) + memcg = memcg_from_slab_page(page); + else + memcg = READ_ONCE(page->mem_cgroup); while (memcg && !(memcg->css.flags & CSS_ONLINE)) memcg = parent_mem_cgroup(memcg); if (memcg) diff --git a/mm/slab.h b/mm/slab.h index acdc1810639d..cb684fbe2cc2 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -256,6 +256,22 @@ static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s) return s->memcg_params.root_cache; } +static inline struct mem_cgroup *memcg_from_slab_page(struct page *page) +{ + struct kmem_cache *s; + + WARN_ON_ONCE(!rcu_read_lock_held()); + + if (PageTail(page)) + page = compound_head(page); + + s = READ_ONCE(page->slab_cache); + if (s && !is_root_cache(s)) + return rcu_dereference(s->memcg_params.memcg); + + return NULL; +} + static __always_inline int memcg_charge_slab(struct page *page, gfp_t gfp, int order, struct kmem_cache *s) @@ -338,6 +354,11 @@ static inline struct kmem_cache *memcg_root_cache(struct kmem_cache *s) return s; } +static inline struct mem_cgroup *memcg_from_slab_page(struct page *page) +{ + return NULL; +} + static inline int memcg_charge_slab(struct page *page, gfp_t gfp, int order, struct kmem_cache *s) { diff --git a/mm/slab_common.c b/mm/slab_common.c index 36673a43ed31..0cfdad0a0aac 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -253,6 +253,7 @@ static void memcg_unlink_cache(struct kmem_cache *s) list_del(&s->memcg_params.kmem_caches_node); mem_cgroup_put(rcu_dereference_protected(s->memcg_params.memcg, lockdep_is_held(&slab_mutex))); + rcu_assign_pointer(s->memcg_params.memcg, NULL); } } #else
Switching to an indirect scheme of getting mem_cgroup pointer for !root slab pages broke /proc/kpagecgroup interface for them. Let's fix it by learning page_cgroup_ino() how to get memcg pointer for slab pages. Reported-by: Shakeel Butt <shakeelb@google.com> Signed-off-by: Roman Gushchin <guro@fb.com> --- mm/memcontrol.c | 5 ++++- mm/slab.h | 21 +++++++++++++++++++++ mm/slab_common.c | 1 + 3 files changed, 26 insertions(+), 1 deletion(-)