LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH][BUGFIX] memcg: fix page_cgroup allocation
@ 2008-10-22  1:24 KAMEZAWA Hiroyuki
  2008-10-22  1:37 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: KAMEZAWA Hiroyuki @ 2008-10-22  1:24 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-mm, balbir, mingo, lizf, nishimura

Andrew, this is a fix to "x86 cannot boot if memcg is enabled" problem in Linus's git-tree,0
fix to "memcg: allocate all page_cgroup at boot" patch.

Thank you for all helps!
(*) I and Balbir tested this. other testers are welcome :)
-Kame
==

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

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>

 init/main.c      |    2 ++
 mm/memcontrol.c  |    1 -
 mm/page_cgroup.c |   35 ++++++++++++++++++++++++++++-------
 3 files changed, 30 insertions(+), 8 deletions(-)

Index: linux-2.6/init/main.c
===================================================================
--- linux-2.6.orig/init/main.c
+++ linux-2.6/init/main.c
@@ -62,6 +62,7 @@
 #include <linux/signal.h>
 #include <linux/idr.h>
 #include <linux/ftrace.h>
+#include <linux/page_cgroup.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -647,6 +648,7 @@ asmlinkage void __init start_kernel(void
 	vmalloc_init();
 	vfs_caches_init_early();
 	cpuset_init_early();
+	page_cgroup_init();
 	mem_init();
 	enable_debug_pagealloc();
 	cpu_hotplug_init();
Index: linux-2.6/mm/memcontrol.c
===================================================================
--- linux-2.6.orig/mm/memcontrol.c
+++ linux-2.6/mm/memcontrol.c
@@ -1088,7 +1088,6 @@ mem_cgroup_create(struct cgroup_subsys *
 	int node;
 
 	if (unlikely((cont->parent) == NULL)) {
-		page_cgroup_init();
 		mem = &init_mem_cgroup;
 	} else {
 		mem = mem_cgroup_alloc();
Index: linux-2.6/mm/page_cgroup.c
===================================================================
--- linux-2.6.orig/mm/page_cgroup.c
+++ linux-2.6/mm/page_cgroup.c
@@ -4,7 +4,12 @@
 #include <linux/bit_spinlock.h>
 #include <linux/page_cgroup.h>
 #include <linux/hash.h>
+#include <linux/slab.h>
 #include <linux/memory.h>
+#include <linux/cgroup.h>
+
+extern struct cgroup_subsys	mem_cgroup_subsys;
+
 
 static void __meminit
 __init_page_cgroup(struct page_cgroup *pc, unsigned long pfn)
@@ -66,6 +71,9 @@ void __init page_cgroup_init(void)
 
 	int nid, fail;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	for_each_online_node(nid)  {
 		fail = alloc_node_page_cgroup(nid);
 		if (fail)
@@ -106,9 +114,14 @@ int __meminit init_section_page_cgroup(u
 	nid = page_to_nid(pfn_to_page(pfn));
 
 	table_size = sizeof(struct page_cgroup) * PAGES_PER_SECTION;
-	base = kmalloc_node(table_size, GFP_KERNEL, nid);
-	if (!base)
-		base = vmalloc_node(table_size, nid);
+	if (slab_is_available()) {
+		base = kmalloc_node(table_size, GFP_KERNEL, nid);
+		if (!base)
+			base = vmalloc_node(table_size, nid);
+	} else {
+		base = __alloc_bootmem_node_nopanic(NODE_DATA(nid), table_size,
+				PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
+	}
 
 	if (!base) {
 		printk(KERN_ERR "page cgroup allocation failure\n");
@@ -135,11 +148,16 @@ void __free_page_cgroup(unsigned long pf
 	if (!ms || !ms->page_cgroup)
 		return;
 	base = ms->page_cgroup + pfn;
-	ms->page_cgroup = NULL;
-	if (is_vmalloc_addr(base))
+	if (is_vmalloc_addr(base)) {
 		vfree(base);
-	else
-		kfree(base);
+		ms->page_cgroup = NULL;
+	} else {
+		struct page *page = virt_to_page(base);
+		if (!PageReserved(page)) { /* Is bootmem ? */
+			kfree(base);
+			ms->page_cgroup = NULL;
+		}
+	}
 }
 
 int online_page_cgroup(unsigned long start_pfn,
@@ -213,6 +231,9 @@ void __init page_cgroup_init(void)
 	unsigned long pfn;
 	int fail = 0;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	for (pfn = 0; !fail && pfn < max_pfn; pfn += PAGES_PER_SECTION) {
 		if (!pfn_present(pfn))
 			continue;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][BUGFIX] memcg: fix page_cgroup allocation
  2008-10-22  1:24 [PATCH][BUGFIX] memcg: fix page_cgroup allocation KAMEZAWA Hiroyuki
@ 2008-10-22  1:37 ` Andrew Morton
  2008-10-22  1:42   ` Li Zefan
  2008-10-22  1:42   ` KAMEZAWA Hiroyuki
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2008-10-22  1:37 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel, linux-mm, balbir, mingo, lizf, nishimura

On Wed, 22 Oct 2008 10:24:04 +0900 KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> Andrew, this is a fix to "x86 cannot boot if memcg is enabled" problem in Linus's git-tree,0
> fix to "memcg: allocate all page_cgroup at boot" patch.
> 
> Thank you for all helps!
> (*) I and Balbir tested this. other testers are welcome :)
> -Kame
> ==
> 
> 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
> 
> 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>
> 
>  init/main.c      |    2 ++
>  mm/memcontrol.c  |    1 -
>  mm/page_cgroup.c |   35 ++++++++++++++++++++++++++++-------
>  3 files changed, 30 insertions(+), 8 deletions(-)
> 
> Index: linux-2.6/init/main.c
> ===================================================================
> --- linux-2.6.orig/init/main.c
> +++ linux-2.6/init/main.c
> @@ -62,6 +62,7 @@
>  #include <linux/signal.h>
>  #include <linux/idr.h>
>  #include <linux/ftrace.h>
> +#include <linux/page_cgroup.h>
>  
>  #include <asm/io.h>
>  #include <asm/bugs.h>
> @@ -647,6 +648,7 @@ asmlinkage void __init start_kernel(void
>  	vmalloc_init();
>  	vfs_caches_init_early();
>  	cpuset_init_early();
> +	page_cgroup_init();
>  	mem_init();
>  	enable_debug_pagealloc();
>  	cpu_hotplug_init();
> Index: linux-2.6/mm/memcontrol.c
> ===================================================================
> --- linux-2.6.orig/mm/memcontrol.c
> +++ linux-2.6/mm/memcontrol.c
> @@ -1088,7 +1088,6 @@ mem_cgroup_create(struct cgroup_subsys *
>  	int node;
>  
>  	if (unlikely((cont->parent) == NULL)) {
> -		page_cgroup_init();
>  		mem = &init_mem_cgroup;
>  	} else {
>  		mem = mem_cgroup_alloc();
> Index: linux-2.6/mm/page_cgroup.c
> ===================================================================
> --- linux-2.6.orig/mm/page_cgroup.c
> +++ linux-2.6/mm/page_cgroup.c
> @@ -4,7 +4,12 @@
>  #include <linux/bit_spinlock.h>
>  #include <linux/page_cgroup.h>
>  #include <linux/hash.h>
> +#include <linux/slab.h>
>  #include <linux/memory.h>
> +#include <linux/cgroup.h>
> +
> +extern struct cgroup_subsys	mem_cgroup_subsys;

no no bad! evil! unclean!

Didn't the linux/cgroup.h -> linux/cgroup_subsys..h inclusion already
declare this for us?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][BUGFIX] memcg: fix page_cgroup allocation
  2008-10-22  1:37 ` Andrew Morton
@ 2008-10-22  1:42   ` Li Zefan
  2008-10-22  1:42   ` KAMEZAWA Hiroyuki
  1 sibling, 0 replies; 4+ messages in thread
From: Li Zefan @ 2008-10-22  1:42 UTC (permalink / raw)
  To: Andrew Morton
  Cc: KAMEZAWA Hiroyuki, linux-kernel, linux-mm, balbir, mingo, nishimura

>> --- linux-2.6.orig/mm/page_cgroup.c
>> +++ linux-2.6/mm/page_cgroup.c
>> @@ -4,7 +4,12 @@
>>  #include <linux/bit_spinlock.h>
>>  #include <linux/page_cgroup.h>
>>  #include <linux/hash.h>
>> +#include <linux/slab.h>
>>  #include <linux/memory.h>
>> +#include <linux/cgroup.h>
>> +
>> +extern struct cgroup_subsys	mem_cgroup_subsys;
> 
> no no bad! evil! unclean!
> 
> Didn't the linux/cgroup.h -> linux/cgroup_subsys..h inclusion already
> declare this for us?
> 

Yes, I think just include <linux/cgroup.h> is enough.

#define SUBSYS(_x) extern struct cgroup_subsys _x ## _subsys;
#include <linux/cgroup_subsys.h>
#undef SUBSYS

and will be expanded to:

extern struct cgroup_subsys cpu_subsys;
extern struct cgroup_subsys cpuset_subsys;
extern struct cgroup_subsys memory_cgroup_subsys;
...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][BUGFIX] memcg: fix page_cgroup allocation
  2008-10-22  1:37 ` Andrew Morton
  2008-10-22  1:42   ` Li Zefan
@ 2008-10-22  1:42   ` KAMEZAWA Hiroyuki
  1 sibling, 0 replies; 4+ messages in thread
From: KAMEZAWA Hiroyuki @ 2008-10-22  1:42 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-mm, balbir, mingo, lizf, nishimura

On Tue, 21 Oct 2008 18:37:38 -0700
Andrew Morton <akpm@linux-foundation.org> wrote:

> Didn't the linux/cgroup.h -> linux/cgroup_subsys..h inclusion already
> declare this for us?
> 
you're right, I'm wrong. fixed one is here. (confirmed by make mm/page_cgroup.i)

Regards,
-Kame
==
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
    and we have to use vmalloc instead of alloc_bootmem() in cgroup_init().
    usage of vmalloc area in x86-32 is important and we should avoid
    vmalloc() in x86-32. So, we want to use alloc_bootmem() from
    sutaible place.

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>

 init/main.c      |    2 ++
 mm/memcontrol.c  |    1 -
 mm/page_cgroup.c |   33 ++++++++++++++++++++++++++-------
 3 files changed, 28 insertions(+), 8 deletions(-)

Index: linux-2.6/init/main.c
===================================================================
--- linux-2.6.orig/init/main.c
+++ linux-2.6/init/main.c
@@ -62,6 +62,7 @@
 #include <linux/signal.h>
 #include <linux/idr.h>
 #include <linux/ftrace.h>
+#include <linux/page_cgroup.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -647,6 +648,7 @@ asmlinkage void __init start_kernel(void
 	vmalloc_init();
 	vfs_caches_init_early();
 	cpuset_init_early();
+	page_cgroup_init();
 	mem_init();
 	enable_debug_pagealloc();
 	cpu_hotplug_init();
Index: linux-2.6/mm/memcontrol.c
===================================================================
--- linux-2.6.orig/mm/memcontrol.c
+++ linux-2.6/mm/memcontrol.c
@@ -1088,7 +1088,6 @@ mem_cgroup_create(struct cgroup_subsys *
 	int node;
 
 	if (unlikely((cont->parent) == NULL)) {
-		page_cgroup_init();
 		mem = &init_mem_cgroup;
 	} else {
 		mem = mem_cgroup_alloc();
Index: linux-2.6/mm/page_cgroup.c
===================================================================
--- linux-2.6.orig/mm/page_cgroup.c
+++ linux-2.6/mm/page_cgroup.c
@@ -4,7 +4,10 @@
 #include <linux/bit_spinlock.h>
 #include <linux/page_cgroup.h>
 #include <linux/hash.h>
+#include <linux/slab.h>
 #include <linux/memory.h>
+#include <linux/cgroup.h>
+
 
 static void __meminit
 __init_page_cgroup(struct page_cgroup *pc, unsigned long pfn)
@@ -66,6 +69,9 @@ void __init page_cgroup_init(void)
 
 	int nid, fail;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	for_each_online_node(nid)  {
 		fail = alloc_node_page_cgroup(nid);
 		if (fail)
@@ -106,9 +112,14 @@ int __meminit init_section_page_cgroup(u
 	nid = page_to_nid(pfn_to_page(pfn));
 
 	table_size = sizeof(struct page_cgroup) * PAGES_PER_SECTION;
-	base = kmalloc_node(table_size, GFP_KERNEL, nid);
-	if (!base)
-		base = vmalloc_node(table_size, nid);
+	if (slab_is_available()) {
+		base = kmalloc_node(table_size, GFP_KERNEL, nid);
+		if (!base)
+			base = vmalloc_node(table_size, nid);
+	} else {
+		base = __alloc_bootmem_node_nopanic(NODE_DATA(nid), table_size,
+				PAGE_SIZE, __pa(MAX_DMA_ADDRESS));
+	}
 
 	if (!base) {
 		printk(KERN_ERR "page cgroup allocation failure\n");
@@ -135,11 +146,16 @@ void __free_page_cgroup(unsigned long pf
 	if (!ms || !ms->page_cgroup)
 		return;
 	base = ms->page_cgroup + pfn;
-	ms->page_cgroup = NULL;
-	if (is_vmalloc_addr(base))
+	if (is_vmalloc_addr(base)) {
 		vfree(base);
-	else
-		kfree(base);
+		ms->page_cgroup = NULL;
+	} else {
+		struct page *page = virt_to_page(base);
+		if (!PageReserved(page)) { /* Is bootmem ? */
+			kfree(base);
+			ms->page_cgroup = NULL;
+		}
+	}
 }
 
 int online_page_cgroup(unsigned long start_pfn,
@@ -213,6 +229,9 @@ void __init page_cgroup_init(void)
 	unsigned long pfn;
 	int fail = 0;
 
+	if (mem_cgroup_subsys.disabled)
+		return;
+
 	for (pfn = 0; !fail && pfn < max_pfn; pfn += PAGES_PER_SECTION) {
 		if (!pfn_present(pfn))
 			continue;



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-22  1:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-22  1:24 [PATCH][BUGFIX] memcg: fix page_cgroup allocation KAMEZAWA Hiroyuki
2008-10-22  1:37 ` Andrew Morton
2008-10-22  1:42   ` Li Zefan
2008-10-22  1:42   ` KAMEZAWA Hiroyuki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).