mirror of https://gitee.com/openkylin/linux.git
memcg: get rid of kmem_cache_dup()
kmem_cache_dup() is only called from memcg_create_kmem_cache(). The latter, in fact, does nothing besides this, so let's fold kmem_cache_dup() into memcg_create_kmem_cache(). This patch also makes the memcg_cache_mutex private to memcg_create_kmem_cache(), because it is not used anywhere else. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Glauber Costa <glommer@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Balbir Singh <bsingharora@gmail.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
2edefe1155
commit
842e287369
|
@ -3427,27 +3427,16 @@ void mem_cgroup_destroy_cache(struct kmem_cache *cachep)
|
||||||
schedule_work(&cachep->memcg_params->destroy);
|
schedule_work(&cachep->memcg_params->destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
|
||||||
* This lock protects updaters, not readers. We want readers to be as fast as
|
struct kmem_cache *s)
|
||||||
* they can, and they will either see NULL or a valid cache value. Our model
|
|
||||||
* allow them to see NULL, in which case the root memcg will be selected.
|
|
||||||
*
|
|
||||||
* We need this lock because multiple allocations to the same cache from a non
|
|
||||||
* will span more than one worker. Only one of them can create the cache.
|
|
||||||
*/
|
|
||||||
static DEFINE_MUTEX(memcg_cache_mutex);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Called with memcg_cache_mutex held
|
|
||||||
*/
|
|
||||||
static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg,
|
|
||||||
struct kmem_cache *s)
|
|
||||||
{
|
{
|
||||||
struct kmem_cache *new;
|
struct kmem_cache *new;
|
||||||
static char *tmp_name = NULL;
|
static char *tmp_name = NULL;
|
||||||
|
static DEFINE_MUTEX(mutex); /* protects tmp_name */
|
||||||
|
|
||||||
lockdep_assert_held(&memcg_cache_mutex);
|
BUG_ON(!memcg_can_account_kmem(memcg));
|
||||||
|
|
||||||
|
mutex_lock(&mutex);
|
||||||
/*
|
/*
|
||||||
* kmem_cache_create_memcg duplicates the given name and
|
* kmem_cache_create_memcg duplicates the given name and
|
||||||
* cgroup_name for this name requires RCU context.
|
* cgroup_name for this name requires RCU context.
|
||||||
|
@ -3470,25 +3459,13 @@ static struct kmem_cache *kmem_cache_dup(struct mem_cgroup *memcg,
|
||||||
|
|
||||||
if (new)
|
if (new)
|
||||||
new->allocflags |= __GFP_KMEMCG;
|
new->allocflags |= __GFP_KMEMCG;
|
||||||
|
else
|
||||||
|
new = s;
|
||||||
|
|
||||||
|
mutex_unlock(&mutex);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
|
|
||||||
struct kmem_cache *cachep)
|
|
||||||
{
|
|
||||||
struct kmem_cache *new_cachep;
|
|
||||||
|
|
||||||
BUG_ON(!memcg_can_account_kmem(memcg));
|
|
||||||
|
|
||||||
mutex_lock(&memcg_cache_mutex);
|
|
||||||
new_cachep = kmem_cache_dup(memcg, cachep);
|
|
||||||
if (new_cachep == NULL)
|
|
||||||
new_cachep = cachep;
|
|
||||||
mutex_unlock(&memcg_cache_mutex);
|
|
||||||
return new_cachep;
|
|
||||||
}
|
|
||||||
|
|
||||||
void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
|
void kmem_cache_destroy_memcg_children(struct kmem_cache *s)
|
||||||
{
|
{
|
||||||
struct kmem_cache *c;
|
struct kmem_cache *c;
|
||||||
|
|
Loading…
Reference in New Issue