Skip to content

Commit

Permalink
mm: memcontrol: fix get_active_memcg return value
Browse files Browse the repository at this point in the history
We use a global percpu int_active_memcg variable to store the remote memcg
when we are in the interrupt context.  But get_active_memcg always return
the current->active_memcg or root_mem_cgroup.  The remote memcg (set in
the interrupt context) is ignored.  This is not what we want.  So fix it.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 37d5985 ("mm: kmem: prepare remote memcg charging infra for interrupt contexts")
Signed-off-by: Muchun Song <[email protected]>
Reviewed-by: Shakeel Butt <[email protected]>
Reviewed-by: Roman Gushchin <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Muchun Song authored and torvalds committed Feb 24, 2021
1 parent cae3af6 commit 1685bde
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,9 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)

rcu_read_lock();
memcg = active_memcg();
if (memcg) {
/* current->active_memcg must hold a ref. */
if (WARN_ON_ONCE(!css_tryget(&memcg->css)))
memcg = root_mem_cgroup;
else
memcg = current->active_memcg;
}
/* remote memcg must hold a ref. */
if (memcg && WARN_ON_ONCE(!css_tryget(&memcg->css)))
memcg = root_mem_cgroup;
rcu_read_unlock();

return memcg;
Expand Down

0 comments on commit 1685bde

Please sign in to comment.