mm: memcg/slab: allocate obj_cgroups for non-root slab pages
Allocate and release memory to store obj_cgroup pointers for each non-root slab page. Reuse page->mem_cgroup pointer to store a pointer to the allocated space. This commit temporarily increases the memory footprint of the kernel memory accounting. To store obj_cgroup pointers we'll need a place for an objcg_pointer for each allocated object. However, the following patches in the series will enable sharing of slab pages between memory cgroups, which will dramatically increase the total slab utilization. And the final memory footprint will be significantly smaller than before. To distinguish between obj_cgroups and memcg pointers in case when it's not obvious which one is used (as in page_cgroup_ino()), let's always set the lowest bit in the obj_cgroup case. The original obj_cgroups pointer is marked to be ignored by kmemleak, which otherwise would report a memory leak for each allocated vector. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Shakeel Butt <shakeelb@google.com> Cc: Christoph Lameter <cl@linux.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Tejun Heo <tj@kernel.org> Link: http://lkml.kernel.org/r/20200623174037.3951353-8-guro@fb.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
bf4f059954
commit
286e04b8ed
@@ -569,10 +569,21 @@ ino_t page_cgroup_ino(struct page *page)
|
||||
unsigned long ino = 0;
|
||||
|
||||
rcu_read_lock();
|
||||
if (PageSlab(page) && !PageTail(page))
|
||||
if (PageSlab(page) && !PageTail(page)) {
|
||||
memcg = memcg_from_slab_page(page);
|
||||
else
|
||||
memcg = READ_ONCE(page->mem_cgroup);
|
||||
} else {
|
||||
memcg = page->mem_cgroup;
|
||||
|
||||
/*
|
||||
* The lowest bit set means that memcg isn't a valid
|
||||
* memcg pointer, but a obj_cgroups pointer.
|
||||
* In this case the page is shared and doesn't belong
|
||||
* to any specific memory cgroup.
|
||||
*/
|
||||
if ((unsigned long) memcg & 0x1UL)
|
||||
memcg = NULL;
|
||||
}
|
||||
|
||||
while (memcg && !(memcg->css.flags & CSS_ONLINE))
|
||||
memcg = parent_mem_cgroup(memcg);
|
||||
if (memcg)
|
||||
|
Reference in New Issue
Block a user