Skip to content

Commit 94b6da5

Browse files
hkamezawatorvalds
authored andcommitted
memcg: fix page_cgroup allocation
page_cgroup_init() is called from mem_cgroup_init(). But at this point, we cannot call alloc_bootmem(). (and this caused panic at boot.) This patch moves page_cgroup_init() to init/main.c. Time table is following: == parse_args(). # we can trust mem_cgroup_subsys.disabled bit after this. .... cgroup_init_early() # "early" init of cgroup. .... setup_arch() # memmap is allocated. ... page_cgroup_init(); mem_init(); # we cannot call alloc_bootmem after this. .... cgroup_init() # mem_cgroup is initialized. == Before page_cgroup_init(), mem_map must be initialized. So, I added page_cgroup_init() to init/main.c directly. (*) maybe this is not very clean but - cgroup_init_early() is too early - in cgroup_init(), we have to use vmalloc instead of alloc_bootmem(). use of vmalloc area in x86-32 is important and we should avoid very large vmalloc() in x86-32. So, we want to use alloc_bootmem() and added page_cgroup_init() directly to init/main.c [akpm@linux-foundation.org: remove unneeded/bad mem_cgroup_subsys declaration] [akpm@linux-foundation.org: fix build] Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Tested-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent be07c4e commit 94b6da5

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎include/linux/page_cgroup.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,10 @@ static inline struct page_cgroup *lookup_page_cgroup(struct page *page)
9999
{
100100
return NULL;
101101
}
102+
103+
static inline void page_cgroup_init(void)
104+
{
105+
}
106+
102107
#endif
103108
#endif

‎init/main.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <linux/key.h>
5353
#include <linux/unwind.h>
5454
#include <linux/buffer_head.h>
55+
#include <linux/page_cgroup.h>
5556
#include <linux/debug_locks.h>
5657
#include <linux/debugobjects.h>
5758
#include <linux/lockdep.h>
@@ -647,6 +648,7 @@ asmlinkage void __init start_kernel(void)
647648
vmalloc_init();
648649
vfs_caches_init_early();
649650
cpuset_init_early();
651+
page_cgroup_init();
650652
mem_init();
651653
enable_debug_pagealloc();
652654
cpu_hotplug_init();

‎mm/memcontrol.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,6 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
10881088
int node;
10891089

10901090
if (unlikely((cont->parent) == NULL)) {
1091-
page_cgroup_init();
10921091
mem = &init_mem_cgroup;
10931092
} else {
10941093
mem = mem_cgroup_alloc();

‎mm/page_cgroup.c‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include <linux/bit_spinlock.h>
55
#include <linux/page_cgroup.h>
66
#include <linux/hash.h>
7+
#include <linux/slab.h>
78
#include <linux/memory.h>
89
#include <linux/vmalloc.h>
10+
#include <linux/cgroup.h>
911

1012
static void __meminit
1113
__init_page_cgroup(struct page_cgroup *pc, unsigned long pfn)
@@ -67,6 +69,9 @@ void __init page_cgroup_init(void)
6769

6870
int nid, fail;
6971

72+
if (mem_cgroup_subsys.disabled)
73+
return;
74+
7075
for_each_online_node(nid) {
7176
fail = alloc_node_page_cgroup(nid);
7277
if (fail)
@@ -107,9 +112,14 @@ int __meminit init_section_page_cgroup(unsigned long pfn)
107112
nid = page_to_nid(pfn_to_page(pfn));
108113

109114
table_size = sizeof(struct page_cgroup) * PAGES_PER_SECTION;
110-
base = kmalloc_node(table_size, GFP_KERNEL, nid);
111-
if (!base)
112-
base = vmalloc_node(table_size, nid);
115+
if (slab_is_available()) {
116+
base = kmalloc_node(table_size, GFP_KERNEL, nid);
117+
if (!base)
118+
base = vmalloc_node(table_size, nid);
119+
} else {
120+
base = __alloc_bootmem_node_nopanic(NODE_DATA(nid), table_size,
121+
PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
122+
}
113123

114124
if (!base) {
115125
printk(KERN_ERR "page cgroup allocation failure\n");
@@ -136,11 +146,16 @@ void __free_page_cgroup(unsigned long pfn)
136146
if (!ms || !ms->page_cgroup)
137147
return;
138148
base = ms->page_cgroup + pfn;
139-
ms->page_cgroup = NULL;
140-
if (is_vmalloc_addr(base))
149+
if (is_vmalloc_addr(base)) {
141150
vfree(base);
142-
else
143-
kfree(base);
151+
ms->page_cgroup = NULL;
152+
} else {
153+
struct page *page = virt_to_page(base);
154+
if (!PageReserved(page)) { /* Is bootmem ? */
155+
kfree(base);
156+
ms->page_cgroup = NULL;
157+
}
158+
}
144159
}
145160

146161
int online_page_cgroup(unsigned long start_pfn,
@@ -214,6 +229,9 @@ void __init page_cgroup_init(void)
214229
unsigned long pfn;
215230
int fail = 0;
216231

232+
if (mem_cgroup_subsys.disabled)
233+
return;
234+
217235
for (pfn = 0; !fail && pfn < max_pfn; pfn += PAGES_PER_SECTION) {
218236
if (!pfn_present(pfn))
219237
continue;

0 commit comments

Comments
 (0)