|
@@ -343,9 +343,6 @@ struct mem_cgroup {
|
|
struct cg_proto tcp_mem;
|
|
struct cg_proto tcp_mem;
|
|
#endif
|
|
#endif
|
|
#if defined(CONFIG_MEMCG_KMEM)
|
|
#if defined(CONFIG_MEMCG_KMEM)
|
|
- /* analogous to slab_common's slab_caches list, but per-memcg;
|
|
|
|
- * protected by memcg_slab_mutex */
|
|
|
|
- struct list_head memcg_slab_caches;
|
|
|
|
/* Index in the kmem_cache->memcg_params->memcg_caches array */
|
|
/* Index in the kmem_cache->memcg_params->memcg_caches array */
|
|
int kmemcg_id;
|
|
int kmemcg_id;
|
|
#endif
|
|
#endif
|
|
@@ -2476,25 +2473,6 @@ static void commit_charge(struct page *page, struct mem_cgroup *memcg,
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_MEMCG_KMEM
|
|
#ifdef CONFIG_MEMCG_KMEM
|
|
-/*
|
|
|
|
- * The memcg_slab_mutex is held whenever a per memcg kmem cache is created or
|
|
|
|
- * destroyed. It protects memcg_caches arrays and memcg_slab_caches lists.
|
|
|
|
- */
|
|
|
|
-static DEFINE_MUTEX(memcg_slab_mutex);
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- * This is a bit cumbersome, but it is rarely used and avoids a backpointer
|
|
|
|
- * in the memcg_cache_params struct.
|
|
|
|
- */
|
|
|
|
-static struct kmem_cache *memcg_params_to_cache(struct memcg_cache_params *p)
|
|
|
|
-{
|
|
|
|
- struct kmem_cache *cachep;
|
|
|
|
-
|
|
|
|
- VM_BUG_ON(p->is_root_cache);
|
|
|
|
- cachep = p->root_cache;
|
|
|
|
- return cache_from_memcg_idx(cachep, memcg_cache_id(p->memcg));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
|
|
int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
|
|
unsigned long nr_pages)
|
|
unsigned long nr_pages)
|
|
{
|
|
{
|
|
@@ -2578,10 +2556,7 @@ static int memcg_alloc_cache_id(void)
|
|
else if (size > MEMCG_CACHES_MAX_SIZE)
|
|
else if (size > MEMCG_CACHES_MAX_SIZE)
|
|
size = MEMCG_CACHES_MAX_SIZE;
|
|
size = MEMCG_CACHES_MAX_SIZE;
|
|
|
|
|
|
- mutex_lock(&memcg_slab_mutex);
|
|
|
|
err = memcg_update_all_caches(size);
|
|
err = memcg_update_all_caches(size);
|
|
- mutex_unlock(&memcg_slab_mutex);
|
|
|
|
-
|
|
|
|
if (err) {
|
|
if (err) {
|
|
ida_simple_remove(&kmem_limited_groups, id);
|
|
ida_simple_remove(&kmem_limited_groups, id);
|
|
return err;
|
|
return err;
|
|
@@ -2604,120 +2579,20 @@ void memcg_update_array_size(int num)
|
|
memcg_limited_groups_array_size = num;
|
|
memcg_limited_groups_array_size = num;
|
|
}
|
|
}
|
|
|
|
|
|
-static void memcg_register_cache(struct mem_cgroup *memcg,
|
|
|
|
- struct kmem_cache *root_cache)
|
|
|
|
-{
|
|
|
|
- struct kmem_cache *cachep;
|
|
|
|
- int id;
|
|
|
|
-
|
|
|
|
- lockdep_assert_held(&memcg_slab_mutex);
|
|
|
|
-
|
|
|
|
- id = memcg_cache_id(memcg);
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Since per-memcg caches are created asynchronously on first
|
|
|
|
- * allocation (see memcg_kmem_get_cache()), several threads can try to
|
|
|
|
- * create the same cache, but only one of them may succeed.
|
|
|
|
- */
|
|
|
|
- if (cache_from_memcg_idx(root_cache, id))
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- cachep = memcg_create_kmem_cache(memcg, root_cache);
|
|
|
|
- /*
|
|
|
|
- * If we could not create a memcg cache, do not complain, because
|
|
|
|
- * that's not critical at all as we can always proceed with the root
|
|
|
|
- * cache.
|
|
|
|
- */
|
|
|
|
- if (!cachep)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- list_add(&cachep->memcg_params->list, &memcg->memcg_slab_caches);
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- * Since readers won't lock (see cache_from_memcg_idx()), we need a
|
|
|
|
- * barrier here to ensure nobody will see the kmem_cache partially
|
|
|
|
- * initialized.
|
|
|
|
- */
|
|
|
|
- smp_wmb();
|
|
|
|
-
|
|
|
|
- BUG_ON(root_cache->memcg_params->memcg_caches[id]);
|
|
|
|
- root_cache->memcg_params->memcg_caches[id] = cachep;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void memcg_unregister_cache(struct kmem_cache *cachep)
|
|
|
|
-{
|
|
|
|
- struct kmem_cache *root_cache;
|
|
|
|
- struct mem_cgroup *memcg;
|
|
|
|
- int id;
|
|
|
|
-
|
|
|
|
- lockdep_assert_held(&memcg_slab_mutex);
|
|
|
|
-
|
|
|
|
- BUG_ON(is_root_cache(cachep));
|
|
|
|
-
|
|
|
|
- root_cache = cachep->memcg_params->root_cache;
|
|
|
|
- memcg = cachep->memcg_params->memcg;
|
|
|
|
- id = memcg_cache_id(memcg);
|
|
|
|
-
|
|
|
|
- BUG_ON(root_cache->memcg_params->memcg_caches[id] != cachep);
|
|
|
|
- root_cache->memcg_params->memcg_caches[id] = NULL;
|
|
|
|
-
|
|
|
|
- list_del(&cachep->memcg_params->list);
|
|
|
|
-
|
|
|
|
- kmem_cache_destroy(cachep);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int __memcg_cleanup_cache_params(struct kmem_cache *s)
|
|
|
|
-{
|
|
|
|
- struct kmem_cache *c;
|
|
|
|
- int i, failed = 0;
|
|
|
|
-
|
|
|
|
- mutex_lock(&memcg_slab_mutex);
|
|
|
|
- for_each_memcg_cache_index(i) {
|
|
|
|
- c = cache_from_memcg_idx(s, i);
|
|
|
|
- if (!c)
|
|
|
|
- continue;
|
|
|
|
-
|
|
|
|
- memcg_unregister_cache(c);
|
|
|
|
-
|
|
|
|
- if (cache_from_memcg_idx(s, i))
|
|
|
|
- failed++;
|
|
|
|
- }
|
|
|
|
- mutex_unlock(&memcg_slab_mutex);
|
|
|
|
- return failed;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void memcg_unregister_all_caches(struct mem_cgroup *memcg)
|
|
|
|
-{
|
|
|
|
- struct kmem_cache *cachep;
|
|
|
|
- struct memcg_cache_params *params, *tmp;
|
|
|
|
-
|
|
|
|
- if (!memcg_kmem_is_active(memcg))
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- mutex_lock(&memcg_slab_mutex);
|
|
|
|
- list_for_each_entry_safe(params, tmp, &memcg->memcg_slab_caches, list) {
|
|
|
|
- cachep = memcg_params_to_cache(params);
|
|
|
|
- memcg_unregister_cache(cachep);
|
|
|
|
- }
|
|
|
|
- mutex_unlock(&memcg_slab_mutex);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-struct memcg_register_cache_work {
|
|
|
|
|
|
+struct memcg_kmem_cache_create_work {
|
|
struct mem_cgroup *memcg;
|
|
struct mem_cgroup *memcg;
|
|
struct kmem_cache *cachep;
|
|
struct kmem_cache *cachep;
|
|
struct work_struct work;
|
|
struct work_struct work;
|
|
};
|
|
};
|
|
|
|
|
|
-static void memcg_register_cache_func(struct work_struct *w)
|
|
|
|
|
|
+static void memcg_kmem_cache_create_func(struct work_struct *w)
|
|
{
|
|
{
|
|
- struct memcg_register_cache_work *cw =
|
|
|
|
- container_of(w, struct memcg_register_cache_work, work);
|
|
|
|
|
|
+ struct memcg_kmem_cache_create_work *cw =
|
|
|
|
+ container_of(w, struct memcg_kmem_cache_create_work, work);
|
|
struct mem_cgroup *memcg = cw->memcg;
|
|
struct mem_cgroup *memcg = cw->memcg;
|
|
struct kmem_cache *cachep = cw->cachep;
|
|
struct kmem_cache *cachep = cw->cachep;
|
|
|
|
|
|
- mutex_lock(&memcg_slab_mutex);
|
|
|
|
- memcg_register_cache(memcg, cachep);
|
|
|
|
- mutex_unlock(&memcg_slab_mutex);
|
|
|
|
|
|
+ memcg_create_kmem_cache(memcg, cachep);
|
|
|
|
|
|
css_put(&memcg->css);
|
|
css_put(&memcg->css);
|
|
kfree(cw);
|
|
kfree(cw);
|
|
@@ -2726,10 +2601,10 @@ static void memcg_register_cache_func(struct work_struct *w)
|
|
/*
|
|
/*
|
|
* Enqueue the creation of a per-memcg kmem_cache.
|
|
* Enqueue the creation of a per-memcg kmem_cache.
|
|
*/
|
|
*/
|
|
-static void __memcg_schedule_register_cache(struct mem_cgroup *memcg,
|
|
|
|
- struct kmem_cache *cachep)
|
|
|
|
|
|
+static void __memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg,
|
|
|
|
+ struct kmem_cache *cachep)
|
|
{
|
|
{
|
|
- struct memcg_register_cache_work *cw;
|
|
|
|
|
|
+ struct memcg_kmem_cache_create_work *cw;
|
|
|
|
|
|
cw = kmalloc(sizeof(*cw), GFP_NOWAIT);
|
|
cw = kmalloc(sizeof(*cw), GFP_NOWAIT);
|
|
if (!cw)
|
|
if (!cw)
|
|
@@ -2739,18 +2614,18 @@ static void __memcg_schedule_register_cache(struct mem_cgroup *memcg,
|
|
|
|
|
|
cw->memcg = memcg;
|
|
cw->memcg = memcg;
|
|
cw->cachep = cachep;
|
|
cw->cachep = cachep;
|
|
|
|
+ INIT_WORK(&cw->work, memcg_kmem_cache_create_func);
|
|
|
|
|
|
- INIT_WORK(&cw->work, memcg_register_cache_func);
|
|
|
|
schedule_work(&cw->work);
|
|
schedule_work(&cw->work);
|
|
}
|
|
}
|
|
|
|
|
|
-static void memcg_schedule_register_cache(struct mem_cgroup *memcg,
|
|
|
|
- struct kmem_cache *cachep)
|
|
|
|
|
|
+static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg,
|
|
|
|
+ struct kmem_cache *cachep)
|
|
{
|
|
{
|
|
/*
|
|
/*
|
|
* We need to stop accounting when we kmalloc, because if the
|
|
* We need to stop accounting when we kmalloc, because if the
|
|
* corresponding kmalloc cache is not yet created, the first allocation
|
|
* corresponding kmalloc cache is not yet created, the first allocation
|
|
- * in __memcg_schedule_register_cache will recurse.
|
|
|
|
|
|
+ * in __memcg_schedule_kmem_cache_create will recurse.
|
|
*
|
|
*
|
|
* However, it is better to enclose the whole function. Depending on
|
|
* However, it is better to enclose the whole function. Depending on
|
|
* the debugging options enabled, INIT_WORK(), for instance, can
|
|
* the debugging options enabled, INIT_WORK(), for instance, can
|
|
@@ -2759,7 +2634,7 @@ static void memcg_schedule_register_cache(struct mem_cgroup *memcg,
|
|
* the safest choice is to do it like this, wrapping the whole function.
|
|
* the safest choice is to do it like this, wrapping the whole function.
|
|
*/
|
|
*/
|
|
current->memcg_kmem_skip_account = 1;
|
|
current->memcg_kmem_skip_account = 1;
|
|
- __memcg_schedule_register_cache(memcg, cachep);
|
|
|
|
|
|
+ __memcg_schedule_kmem_cache_create(memcg, cachep);
|
|
current->memcg_kmem_skip_account = 0;
|
|
current->memcg_kmem_skip_account = 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2807,7 +2682,7 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep)
|
|
* could happen with the slab_mutex held. So it's better to
|
|
* could happen with the slab_mutex held. So it's better to
|
|
* defer everything.
|
|
* defer everything.
|
|
*/
|
|
*/
|
|
- memcg_schedule_register_cache(memcg, cachep);
|
|
|
|
|
|
+ memcg_schedule_kmem_cache_create(memcg, cachep);
|
|
out:
|
|
out:
|
|
css_put(&memcg->css);
|
|
css_put(&memcg->css);
|
|
return cachep;
|
|
return cachep;
|
|
@@ -4136,7 +4011,7 @@ static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
|
|
|
|
|
|
static void memcg_destroy_kmem(struct mem_cgroup *memcg)
|
|
static void memcg_destroy_kmem(struct mem_cgroup *memcg)
|
|
{
|
|
{
|
|
- memcg_unregister_all_caches(memcg);
|
|
|
|
|
|
+ memcg_destroy_kmem_caches(memcg);
|
|
mem_cgroup_sockets_destroy(memcg);
|
|
mem_cgroup_sockets_destroy(memcg);
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
@@ -4664,7 +4539,6 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
|
|
spin_lock_init(&memcg->event_list_lock);
|
|
spin_lock_init(&memcg->event_list_lock);
|
|
#ifdef CONFIG_MEMCG_KMEM
|
|
#ifdef CONFIG_MEMCG_KMEM
|
|
memcg->kmemcg_id = -1;
|
|
memcg->kmemcg_id = -1;
|
|
- INIT_LIST_HEAD(&memcg->memcg_slab_caches);
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
return &memcg->css;
|
|
return &memcg->css;
|