Skip to content

Commit 00c54c0

Browse files
hnaztorvalds
authored andcommitted
mm: page_cgroup: check page_cgroup arrays in lookup_page_cgroup() only when necessary
lookup_page_cgroup() is usually used only against pages that are used in userspace. The exception is the CONFIG_DEBUG_VM-only memcg check from the page allocator: it can run on pages without page_cgroup descriptors allocated when the pages are fed into the page allocator for the first time during boot or memory hotplug. Include the array check only when CONFIG_DEBUG_VM is set and save the unnecessary check in production kernels. Signed-off-by: Johannes Weiner <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Balbir Singh <[email protected]> Cc: David Rientjes <[email protected]> Cc: Hugh Dickins <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent cfa4494 commit 00c54c0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

mm/page_cgroup.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ struct page_cgroup *lookup_page_cgroup(struct page *page)
2828
struct page_cgroup *base;
2929

3030
base = NODE_DATA(page_to_nid(page))->node_page_cgroup;
31+
#ifdef CONFIG_DEBUG_VM
32+
/*
33+
* The sanity checks the page allocator does upon freeing a
34+
* page can reach here before the page_cgroup arrays are
35+
* allocated when feeding a range of pages to the allocator
36+
* for the first time during bootup or memory hotplug.
37+
*/
3138
if (unlikely(!base))
3239
return NULL;
33-
40+
#endif
3441
offset = pfn - NODE_DATA(page_to_nid(page))->node_start_pfn;
3542
return base + offset;
3643
}
@@ -85,9 +92,16 @@ struct page_cgroup *lookup_page_cgroup(struct page *page)
8592
{
8693
unsigned long pfn = page_to_pfn(page);
8794
struct mem_section *section = __pfn_to_section(pfn);
88-
95+
#ifdef CONFIG_DEBUG_VM
96+
/*
97+
* The sanity checks the page allocator does upon freeing a
98+
* page can reach here before the page_cgroup arrays are
99+
* allocated when feeding a range of pages to the allocator
100+
* for the first time during bootup or memory hotplug.
101+
*/
89102
if (!section->page_cgroup)
90103
return NULL;
104+
#endif
91105
return section->page_cgroup + pfn;
92106
}
93107

0 commit comments

Comments
 (0)