]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mm: memcontrol: fix swap counter leak on swapout from offline cgroup
authorVladimir Davydov <vdavydov@virtuozzo.com>
Thu, 11 Aug 2016 22:33:00 +0000 (15:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 16 Aug 2016 07:34:59 +0000 (09:34 +0200)
commit0571b96f5fe82580bc84c19b826cc63cd37df0dd
tree0dcf6f5c6158022c6c885d51af03bc0dd25ad6dd
parent80f35a804be48ac0fe1f3b3ae73bb60a7320d3c3
mm: memcontrol: fix swap counter leak on swapout from offline cgroup

commit 1f47b61fb4077936465dcde872a4e5cc4fe708da upstream.

An offline memory cgroup might have anonymous memory or shmem left
charged to it and no swap.  Since only swap entries pin the id of an
offline cgroup, such a cgroup will have no id and so an attempt to
swapout its anon/shmem will not store memory cgroup info in the swap
cgroup map.  As a result, memcg->swap or memcg->memsw will never get
uncharged from it and any of its ascendants.

Fix this by always charging swapout to the first ancestor cgroup that
hasn't released its id yet.

[hannes@cmpxchg.org: add comment to mem_cgroup_swapout]
[vdavydov@virtuozzo.com: use WARN_ON_ONCE() in mem_cgroup_id_get_online()]
Link: http://lkml.kernel.org/r/20160803123445.GJ13263@esperanza
Fixes: 73f576c04b941 ("mm: memcontrol: fix cgroup creation failure after many small jobs")
Link: http://lkml.kernel.org/r/5336daa5c9a32e776067773d9da655d2dc126491.1470219853.git.vdavydov@virtuozzo.com
Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/memcontrol.c