memcg, slab: merge memcg_{bind,release}_pages to memcg_{un}charge_slab
Currently we have two pairs of kmemcg-related functions that are called on slab alloc/free. The first is memcg_{bind,release}_pages that count the total number of pages allocated on a kmem cache. The second is memcg_{un}charge_slab that {un}charge slab pages to kmemcg resource counter. Let's just merge them to keep the code clean. Signed-off-by: Vladimir Davydov <vdavydov@parallels.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Glauber Costa <glommer@gmail.com> Cc: Pekka Enberg <penberg@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
1e32e77f95
commit
c67a8a685a
@@ -2954,7 +2954,7 @@ static int mem_cgroup_slabinfo_read(struct seq_file *m, void *v)
|
||||
}
|
||||
#endif
|
||||
|
||||
int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
|
||||
static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
|
||||
{
|
||||
struct res_counter *fail_res;
|
||||
int ret = 0;
|
||||
@@ -2992,7 +2992,7 @@ int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
|
||||
static void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
|
||||
{
|
||||
res_counter_uncharge(&memcg->res, size);
|
||||
if (do_swap_account)
|
||||
@@ -3390,6 +3390,24 @@ static void memcg_create_cache_enqueue(struct mem_cgroup *memcg,
|
||||
__memcg_create_cache_enqueue(memcg, cachep);
|
||||
memcg_resume_kmem_account();
|
||||
}
|
||||
|
||||
int __memcg_charge_slab(struct kmem_cache *cachep, gfp_t gfp, int order)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = memcg_charge_kmem(cachep->memcg_params->memcg, gfp,
|
||||
PAGE_SIZE << order);
|
||||
if (!res)
|
||||
atomic_add(1 << order, &cachep->memcg_params->nr_pages);
|
||||
return res;
|
||||
}
|
||||
|
||||
void __memcg_uncharge_slab(struct kmem_cache *cachep, int order)
|
||||
{
|
||||
memcg_uncharge_kmem(cachep->memcg_params->memcg, PAGE_SIZE << order);
|
||||
atomic_sub(1 << order, &cachep->memcg_params->nr_pages);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the kmem_cache we're supposed to use for a slab allocation.
|
||||
* We try to use the current memcg's version of the cache.
|
||||
|
Reference in New Issue
Block a user