On Thu, Aug 01, 2019 at 04:35:32PM -0700, Roman Gushchin wrote: > Memcg counters for shadow nodes are broken because the memcg pointer is > obtained in a wrong way. The following approach is used: > virt_to_page(xa_node)->mem_cgroup > > Since commit 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup > pointer for slab pages") page->mem_cgroup pointer isn't set for slab pages, > so memcg_from_slab_page() should be used instead. > > Also I doubt that it ever worked correctly: virt_to_head_page() should be > used instead of virt_to_page(). Otherwise objects residing on tail pages > are not accounted, because only the head page contains a valid mem_cgroup > pointer. That was a case since the introduction of these counters by the > commit 68d48e6a2df5 ("mm: workingset: add vmstat counter for shadow nodes"). You're right. slub uses order-2 compound pages for radix_tree_node, so we've been underreporting shadow nodes placed in the three tail pages. Nice catch. > Fixes: 4d96ba353075 ("mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages") > Signed-off-by: Roman Gushchin <guro@xxxxxx> > Cc: Johannes Weiner <hannes@xxxxxxxxxxx> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>