aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memcontrol.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r--mm/memcontrol.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e16694d5e118..3eafe6cf6ca4 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -341,6 +341,14 @@ struct mem_cgroup {
341#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET) 341#if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_INET)
342 struct tcp_memcontrol tcp_mem; 342 struct tcp_memcontrol tcp_mem;
343#endif 343#endif
344#if defined(CONFIG_MEMCG_KMEM)
345 /* analogous to slab_common's slab_caches list. per-memcg */
346 struct list_head memcg_slab_caches;
347 /* Not a spinlock, we can take a lot of time walking the list */
348 struct mutex slab_caches_mutex;
349 /* Index in the kmem_cache->memcg_params->memcg_caches array */
350 int kmemcg_id;
351#endif
344}; 352};
345 353
346/* internal only representation about the status of kmem accounting. */ 354/* internal only representation about the status of kmem accounting. */
@@ -2785,6 +2793,47 @@ static void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
2785 mem_cgroup_put(memcg); 2793 mem_cgroup_put(memcg);
2786} 2794}
2787 2795
2796void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep)
2797{
2798 if (!memcg)
2799 return;
2800
2801 mutex_lock(&memcg->slab_caches_mutex);
2802 list_add(&cachep->memcg_params->list, &memcg->memcg_slab_caches);
2803 mutex_unlock(&memcg->slab_caches_mutex);
2804}
2805
2806/*
2807 * helper for acessing a memcg's index. It will be used as an index in the
2808 * child cache array in kmem_cache, and also to derive its name. This function
2809 * will return -1 when this is not a kmem-limited memcg.
2810 */
2811int memcg_cache_id(struct mem_cgroup *memcg)
2812{
2813 return memcg ? memcg->kmemcg_id : -1;
2814}
2815
2816int memcg_register_cache(struct mem_cgroup *memcg, struct kmem_cache *s)
2817{
2818 size_t size = sizeof(struct memcg_cache_params);
2819
2820 if (!memcg_kmem_enabled())
2821 return 0;
2822
2823 s->memcg_params = kzalloc(size, GFP_KERNEL);
2824 if (!s->memcg_params)
2825 return -ENOMEM;
2826
2827 if (memcg)
2828 s->memcg_params->memcg = memcg;
2829 return 0;
2830}
2831
2832void memcg_release_cache(struct kmem_cache *s)
2833{
2834 kfree(s->memcg_params);
2835}
2836
2788/* 2837/*
2789 * We need to verify if the allocation against current->mm->owner's memcg is 2838 * We need to verify if the allocation against current->mm->owner's memcg is
2790 * possible for the given order. But the page is not allocated yet, so we'll 2839 * possible for the given order. But the page is not allocated yet, so we'll
@@ -5026,7 +5075,9 @@ static int mem_cgroup_oom_control_write(struct cgroup *cgrp,
5026#ifdef CONFIG_MEMCG_KMEM 5075#ifdef CONFIG_MEMCG_KMEM
5027static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss) 5076static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
5028{ 5077{
5078 memcg->kmemcg_id = -1;
5029 memcg_propagate_kmem(memcg); 5079 memcg_propagate_kmem(memcg);
5080
5030 return mem_cgroup_sockets_init(memcg, ss); 5081 return mem_cgroup_sockets_init(memcg, ss);
5031}; 5082};
5032 5083