Skip to content

Commit

Permalink
memcg: zap memcg_can_account_kmem
Browse files Browse the repository at this point in the history
memcg_can_account_kmem() returns true iff

    !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg) &&
                                   memcg_kmem_is_active(memcg);

To begin with the !mem_cgroup_is_root(memcg) check is useless, because one
can't enable kmem accounting for the root cgroup (mem_cgroup_write()
returns EINVAL on an attempt to set the limit on the root cgroup).

Furthermore, the !mem_cgroup_disabled() check also seems to be redundant.
The point is memcg_can_account_kmem() is called from three places:
mem_cgroup_salbinfo_read(), __memcg_kmem_get_cache(), and
__memcg_kmem_newpage_charge().  The latter two functions are only invoked
if memcg_kmem_enabled() returns true, which implies that the memory cgroup
subsystem is enabled.  And mem_cgroup_slabinfo_read() shows the output of
memory.kmem.slabinfo, which won't exist if the memory cgroup is completely
disabled.

So let's substitute all the calls to memcg_can_account_kmem() with plain
memcg_kmem_is_active(), and kill the former.

Signed-off-by: Vladimir Davydov <[email protected]>
Acked-by: Johannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Vladimir Davydov authored and torvalds committed Oct 10, 2014
1 parent b70a2a2 commit cf2b8fb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2762,12 +2762,6 @@ static DEFINE_MUTEX(memcg_slab_mutex);

static DEFINE_MUTEX(activate_kmem_mutex);

static inline bool memcg_can_account_kmem(struct mem_cgroup *memcg)
{
return !mem_cgroup_disabled() && !mem_cgroup_is_root(memcg) &&
memcg_kmem_is_active(memcg);
}

/*
* This is a bit cumbersome, but it is rarely used and avoids a backpointer
* in the memcg_cache_params struct.
Expand All @@ -2787,7 +2781,7 @@ static int mem_cgroup_slabinfo_read(struct seq_file *m, void *v)
struct mem_cgroup *memcg = mem_cgroup_from_css(seq_css(m));
struct memcg_cache_params *params;

if (!memcg_can_account_kmem(memcg))
if (!memcg_kmem_is_active(memcg))
return -EIO;

print_slabinfo_header(m);
Expand Down Expand Up @@ -3164,7 +3158,7 @@ struct kmem_cache *__memcg_kmem_get_cache(struct kmem_cache *cachep,
rcu_read_lock();
memcg = mem_cgroup_from_task(rcu_dereference(current->mm->owner));

if (!memcg_can_account_kmem(memcg))
if (!memcg_kmem_is_active(memcg))
goto out;

memcg_cachep = cache_from_memcg_idx(cachep, memcg_cache_id(memcg));
Expand Down Expand Up @@ -3249,7 +3243,7 @@ __memcg_kmem_newpage_charge(gfp_t gfp, struct mem_cgroup **_memcg, int order)

memcg = get_mem_cgroup_from_mm(current->mm);

if (!memcg_can_account_kmem(memcg)) {
if (!memcg_kmem_is_active(memcg)) {
css_put(&memcg->css);
return true;
}
Expand Down

0 comments on commit cf2b8fb

Please sign in to comment.