Commit 95fc3c50 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Linus Torvalds

memcg: do not abuse memcg_kmem_skip_account

task_struct->memcg_kmem_skip_account was initially introduced to avoid
recursion during kmem cache creation: memcg_kmem_get_cache, which is
called by kmem_cache_alloc to determine the per-memcg cache to account
allocation to, may issue lazy cache creation if the needed cache doesn't
exist, which means issuing yet another kmem_cache_alloc.  We can't just
pass a flag to the nested kmem_cache_alloc disabling kmem accounting,
because there are hidden allocations, e.g.  in INIT_WORK.  So we
introduced a flag on the task_struct, memcg_kmem_skip_account, making
memcg_kmem_get_cache return immediately.

By its nature, the flag may also be used to disable accounting for
allocations shared among different cgroups, and currently it is used this
way in memcg_activate_kmem.  Using it like this looks like abusing it to
me.  If we want to disable accounting for some allocations (which we will
definitely want one day), we should either add GFP_NO_MEMCG or GFP_MEMCG
flag in order to blacklist/whitelist some allocations.

For now, let's simply remove memcg_stop/resume_kmem_account from
memcg_activate_kmem.
Signed-off-by: default avatarVladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9d100c5e
...@@ -3538,12 +3538,6 @@ static int memcg_activate_kmem(struct mem_cgroup *memcg, ...@@ -3538,12 +3538,6 @@ static int memcg_activate_kmem(struct mem_cgroup *memcg,
if (memcg_kmem_is_active(memcg)) if (memcg_kmem_is_active(memcg))
return 0; return 0;
/*
* We are going to allocate memory for data shared by all memory
* cgroups so let's stop accounting here.
*/
memcg_stop_kmem_account();
/* /*
* For simplicity, we won't allow this to be disabled. It also can't * For simplicity, we won't allow this to be disabled. It also can't
* be changed if the cgroup has children already, or if tasks had * be changed if the cgroup has children already, or if tasks had
...@@ -3588,7 +3582,6 @@ static int memcg_activate_kmem(struct mem_cgroup *memcg, ...@@ -3588,7 +3582,6 @@ static int memcg_activate_kmem(struct mem_cgroup *memcg,
*/ */
memcg_kmem_set_active(memcg); memcg_kmem_set_active(memcg);
out: out:
memcg_resume_kmem_account();
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment