@@ -199,7 +199,10 @@ struct page {
atomic_t _refcount;
#ifdef CONFIG_MEMCG
- struct mem_cgroup *mem_cgroup;
+ union {
+ struct mem_cgroup *mem_cgroup;
+ struct mem_cgroup_ptr **mem_cgroup_vec;
+ };
#endif
/*
@@ -1369,7 +1369,8 @@ static struct page *kmem_getpages(struct kmem_cache *cachep, gfp_t flags,
return NULL;
}
- if (charge_slab_page(page, flags, cachep->gfporder, cachep)) {
+ if (charge_slab_page(page, flags, cachep->gfporder, cachep,
+ cachep->num)) {
__free_pages(page, cachep->gfporder);
return NULL;
}
@@ -406,6 +406,23 @@ static __always_inline void memcg_uncharge_slab(struct page *page, int order,
percpu_ref_put_many(&s->memcg_params.refcnt, 1 << order);
}
+static inline int memcg_alloc_page_memcg_vec(struct page *page, gfp_t gfp,
+ unsigned int objects)
+{
+ page->mem_cgroup_vec = kmalloc(sizeof(struct mem_cgroup_ptr *) *
+ objects, gfp | __GFP_ZERO);
+ if (!page->mem_cgroup_vec)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static inline void memcg_free_page_memcg_vec(struct page *page)
+{
+ kfree(page->mem_cgroup_vec);
+ page->mem_cgroup_vec = NULL;
+}
+
extern void slab_init_memcg_params(struct kmem_cache *);
extern void memcg_link_cache(struct kmem_cache *s, struct mem_cgroup *memcg);
@@ -455,6 +472,16 @@ static inline void memcg_uncharge_slab(struct page *page, int order,
{
}
+static inline int memcg_alloc_page_memcg_vec(struct page *page, gfp_t gfp,
+ unsigned int objects)
+{
+ return 0;
+}
+
+static inline void memcg_free_page_memcg_vec(struct page *page)
+{
+}
+
static inline void slab_init_memcg_params(struct kmem_cache *s)
{
}
@@ -479,14 +506,21 @@ static inline struct kmem_cache *virt_to_cache(const void *obj)
static __always_inline int charge_slab_page(struct page *page,
gfp_t gfp, int order,
- struct kmem_cache *s)
+ struct kmem_cache *s,
+ unsigned int objects)
{
+ int ret;
+
if (is_root_cache(s)) {
mod_node_page_state(page_pgdat(page), cache_vmstat_idx(s),
PAGE_SIZE << order);
return 0;
}
+ ret = memcg_alloc_page_memcg_vec(page, gfp, objects);
+ if (ret)
+ return ret;
+
return memcg_charge_slab(page, gfp, order, s);
}
@@ -499,6 +533,7 @@ static __always_inline void uncharge_slab_page(struct page *page, int order,
return;
}
+ memcg_free_page_memcg_vec(page);
memcg_uncharge_slab(page, order, s);
}
@@ -1517,7 +1517,7 @@ static inline struct page *alloc_slab_page(struct kmem_cache *s,
else
page = __alloc_pages_node(node, flags, order);
- if (page && charge_slab_page(page, flags, order, s)) {
+ if (page && charge_slab_page(page, flags, order, s, oo_objects(oo))) {
__free_pages(page, order);
page = NULL;
}
Allocate and release memory for storing the memcg ownership data. For each slab page allocate space sufficient for number_of_objects pointers to struct mem_cgroup_vec. The mem_cgroup field of the struct page isn't used for slab pages, so let's use the space for storing the pointer for the allocated space. This commit makes sure that the space is ready for use, but nobody is actually using it yet. Following commits in the series will fix it. Signed-off-by: Roman Gushchin <guro@fb.com> --- include/linux/mm_types.h | 5 ++++- mm/slab.c | 3 ++- mm/slab.h | 37 ++++++++++++++++++++++++++++++++++++- mm/slub.c | 2 +- 4 files changed, 43 insertions(+), 4 deletions(-)