All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 07/17] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c
@ 2009-03-05 12:54 Pekka Enberg
  2009-03-05 13:37 ` [tip:x86/mm] " Pekka Enberg
  2009-03-05 19:14 ` [PATCH 07/17] " Yinghai Lu
  0 siblings, 2 replies; 27+ messages in thread
From: Pekka Enberg @ 2009-03-05 12:54 UTC (permalink / raw)
  To: mingo; +Cc: x86, linux-kernel, Yinghai Lu

Impact: cleanup

This patch renames after_init_bootmem to after_bootmem in mm/init_32.c to
reduce the diff to the 64-bit version of of init_memory_mapping().

Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---
 arch/x86/mm/init_32.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 559715b..cc5c399 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -63,7 +63,7 @@ static unsigned long __initdata table_start;
 static unsigned long __meminitdata table_end;
 static unsigned long __meminitdata table_top;
 
-static int __initdata after_init_bootmem;
+int after_bootmem;
 
 int direct_gbpages;
 
@@ -92,7 +92,7 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_init_bootmem)
+		if (after_bootmem)
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
 		else
 			pmd_table = (pmd_t *)alloc_low_page();
@@ -119,7 +119,7 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_init_bootmem) {
+		if (after_bootmem) {
 #ifdef CONFIG_DEBUG_PAGEALLOC
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
@@ -158,7 +158,7 @@ static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd,
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_init_bootmem);
+		BUG_ON(after_bootmem);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -831,7 +831,7 @@ void __init setup_bootmem_allocator(void)
 	bootmap = setup_node_bootmem(0, 0, max_low_pfn, bootmap);
 #endif
 
-	after_init_bootmem = 1;
+	after_bootmem = 1;
 }
 
 static void __init find_early_table_space(unsigned long end, int use_pse,
@@ -1037,7 +1037,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 	for (i = 0; i < nr_range; i++)
@@ -1052,11 +1052,11 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 
 	__flush_tlb_all();
 
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		reserve_early(table_start << PAGE_SHIFT,
 				 table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		early_memtest(start, end);
 
 	return end >> PAGE_SHIFT;
-- 
1.5.4.3


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

* [tip:x86/mm] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c
  2009-03-05 12:54 [PATCH 07/17] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c Pekka Enberg
@ 2009-03-05 13:37 ` Pekka Enberg
  2009-03-05 19:14 ` [PATCH 07/17] " Yinghai Lu
  1 sibling, 0 replies; 27+ messages in thread
From: Pekka Enberg @ 2009-03-05 13:37 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, yinghai, penberg, tglx, mingo

Commit-ID:  c464573cb3d3bdd45eed8f5f59596f84ede95a0c
Gitweb:     http://git.kernel.org/tip/c464573cb3d3bdd45eed8f5f59596f84ede95a0c
Author:     "Pekka Enberg" <penberg@cs.helsinki.fi>
AuthorDate: Thu, 5 Mar 2009 14:54:58 +0200
Commit:     Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 5 Mar 2009 14:17:13 +0100

x86: rename after_init_bootmem to after_bootmem in mm/init_32.c

Impact: cleanup

This patch renames after_init_bootmem to after_bootmem in
mm/init_32.c to reduce the diff to the 64-bit version of of
init_memory_mapping().

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Yinghai Lu <yinghai@kernel.org>
LKML-Reference: <1236257708-27269-7-git-send-email-penberg@cs.helsinki.fi>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 arch/x86/mm/init_32.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 559715b..cc5c399 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -63,7 +63,7 @@ static unsigned long __initdata table_start;
 static unsigned long __meminitdata table_end;
 static unsigned long __meminitdata table_top;
 
-static int __initdata after_init_bootmem;
+int after_bootmem;
 
 int direct_gbpages;
 
@@ -92,7 +92,7 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_init_bootmem)
+		if (after_bootmem)
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
 		else
 			pmd_table = (pmd_t *)alloc_low_page();
@@ -119,7 +119,7 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_init_bootmem) {
+		if (after_bootmem) {
 #ifdef CONFIG_DEBUG_PAGEALLOC
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
@@ -158,7 +158,7 @@ static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd,
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_init_bootmem);
+		BUG_ON(after_bootmem);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -831,7 +831,7 @@ void __init setup_bootmem_allocator(void)
 	bootmap = setup_node_bootmem(0, 0, max_low_pfn, bootmap);
 #endif
 
-	after_init_bootmem = 1;
+	after_bootmem = 1;
 }
 
 static void __init find_early_table_space(unsigned long end, int use_pse,
@@ -1037,7 +1037,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 	for (i = 0; i < nr_range; i++)
@@ -1052,11 +1052,11 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 
 	__flush_tlb_all();
 
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		reserve_early(table_start << PAGE_SHIFT,
 				 table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_init_bootmem)
+	if (!after_bootmem)
 		early_memtest(start, end);
 
 	return end >> PAGE_SHIFT;

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

* Re: [PATCH 07/17] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c
  2009-03-05 12:54 [PATCH 07/17] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c Pekka Enberg
  2009-03-05 13:37 ` [tip:x86/mm] " Pekka Enberg
@ 2009-03-05 19:14 ` Yinghai Lu
       [not found]   ` <49B02C68.1030203@cs.helsinki.fi>
  1 sibling, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-05 19:14 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: mingo, x86, linux-kernel

Pekka Enberg wrote:
> Impact: cleanup
> 
> This patch renames after_init_bootmem to after_bootmem in mm/init_32.c to
> reduce the diff to the 64-bit version of of init_memory_mapping().

not sure,
after_init_bootmem seems bootmem could be used.
after_bootmem seems bootmem are freed already.

YH

> 
> Cc: Yinghai Lu <yinghai@kernel.org>
> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
> ---
>  arch/x86/mm/init_32.c |   16 ++++++++--------
>  1 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
> index 559715b..cc5c399 100644
> --- a/arch/x86/mm/init_32.c
> +++ b/arch/x86/mm/init_32.c
> @@ -63,7 +63,7 @@ static unsigned long __initdata table_start;
>  static unsigned long __meminitdata table_end;
>  static unsigned long __meminitdata table_top;
>  
> -static int __initdata after_init_bootmem;
> +int after_bootmem;
>  
>  int direct_gbpages;
>  
> @@ -92,7 +92,7 @@ static pmd_t * __init one_md_table_init(pgd_t *pgd)
>  
>  #ifdef CONFIG_X86_PAE
>  	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
> -		if (after_init_bootmem)
> +		if (after_bootmem)
>  			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
>  		else
>  			pmd_table = (pmd_t *)alloc_low_page();
> @@ -119,7 +119,7 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
>  	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
>  		pte_t *page_table = NULL;
>  
> -		if (after_init_bootmem) {
> +		if (after_bootmem) {
>  #ifdef CONFIG_DEBUG_PAGEALLOC
>  			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
>  #endif
> @@ -158,7 +158,7 @@ static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd,
>  		pte_t *newpte;
>  		int i;
>  
> -		BUG_ON(after_init_bootmem);
> +		BUG_ON(after_bootmem);
>  		newpte = alloc_low_page();
>  		for (i = 0; i < PTRS_PER_PTE; i++)
>  			set_pte(newpte + i, pte[i]);
> @@ -831,7 +831,7 @@ void __init setup_bootmem_allocator(void)
>  	bootmap = setup_node_bootmem(0, 0, max_low_pfn, bootmap);
>  #endif
>  
> -	after_init_bootmem = 1;
> +	after_bootmem = 1;
>  }
>  
>  static void __init find_early_table_space(unsigned long end, int use_pse,
> @@ -1037,7 +1037,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>  	 * memory mapped. Unfortunately this is done currently before the
>  	 * nodes are discovered.
>  	 */
> -	if (!after_init_bootmem)
> +	if (!after_bootmem)
>  		find_early_table_space(end, use_pse, use_gbpages);
>  
>  	for (i = 0; i < nr_range; i++)
> @@ -1052,11 +1052,11 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
>  
>  	__flush_tlb_all();
>  
> -	if (!after_init_bootmem)
> +	if (!after_bootmem)
>  		reserve_early(table_start << PAGE_SHIFT,
>  				 table_end << PAGE_SHIFT, "PGTABLE");
>  
> -	if (!after_init_bootmem)
> +	if (!after_bootmem)
>  		early_memtest(start, end);
>  
>  	return end >> PAGE_SHIFT;


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

* [PATCH] x86: introduce bootmem_state
       [not found]   ` <49B02C68.1030203@cs.helsinki.fi>
@ 2009-03-05 23:45     ` Yinghai Lu
  2009-03-06  6:14       ` H. Peter Anvin
  2009-03-06 14:59       ` Ingo Molnar
  0 siblings, 2 replies; 27+ messages in thread
From: Yinghai Lu @ 2009-03-05 23:45 UTC (permalink / raw)
  To: mingo, Thomas Gleixner, H. Peter Anvin, Andrew Morton
  Cc: Pekka Enberg, linux-kernel


Impact: cleanup

extend after_bootmem and after_init_bootmem to bootmem_state
and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/kernel/setup.c |    1 +
 arch/x86/mm/init.c      |   13 +++++++------
 arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
 arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
 include/linux/mm.h      |    8 ++++++++
 5 files changed, 55 insertions(+), 28 deletions(-)

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup.c
+++ linux-2.6/arch/x86/kernel/setup.c
@@ -885,6 +885,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	initmem_init(0, max_pfn);
+	bootmem_state = DURING_BOOTMEM;
 
 #ifdef CONFIG_ACPI_SLEEP
 	/*
Index: linux-2.6/arch/x86/mm/init.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init.c
+++ linux-2.6/arch/x86/mm/init.c
@@ -14,7 +14,7 @@ unsigned long __initdata e820_table_star
 unsigned long __meminitdata e820_table_end;
 unsigned long __meminitdata e820_table_top;
 
-int after_bootmem;
+enum bootmem_state_t bootmem_state = BEFORE_BOOTMEM;
 
 int direct_gbpages
 #ifdef CONFIG_DIRECT_GBPAGES
@@ -143,7 +143,7 @@ unsigned long __init_refok init_memory_m
 
 	printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end);
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		init_gbpages();
 
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
@@ -283,7 +283,7 @@ unsigned long __init_refok init_memory_m
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 #ifdef CONFIG_X86_32
@@ -304,16 +304,17 @@ unsigned long __init_refok init_memory_m
 #endif
 
 #ifdef CONFIG_X86_64
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		mmu_cr4_features = read_cr4();
 #endif
 	__flush_tlb_all();
 
-	if (!after_bootmem && e820_table_end > e820_table_start)
+	if (bootmem_state == BEFORE_BOOTMEM &&
+	    e820_table_end > e820_table_start)
 		reserve_early(e820_table_start << PAGE_SHIFT,
 				 e820_table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		early_memtest(start, end);
 
 	return ret >> PAGE_SHIFT;
Index: linux-2.6/arch/x86/mm/init_32.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_32.c
+++ linux-2.6/arch/x86/mm/init_32.c
@@ -82,14 +82,20 @@ static __init void *alloc_low_page(void)
 static pmd_t * __init one_md_table_init(pgd_t *pgd)
 {
 	pud_t *pud;
-	pmd_t *pmd_table;
+	pmd_t *pmd_table = NULL;
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_bootmem)
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		else
+			break;
+		case BEFORE_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_md_table_init\n");
+		}
 		paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
 		set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
 		pud = pud_offset(pgd, 0);
@@ -113,15 +119,21 @@ static pte_t * __init one_page_table_ini
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_bootmem) {
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
 			if (!page_table)
 				page_table =
 				(pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		} else
+			break;
+		case BEFORE_BOOTMEM:
 			page_table = (pte_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_page_table_init\n");
+		}
 
 		paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
 		set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
@@ -169,7 +181,7 @@ static pte_t *__init page_table_kmap_che
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_bootmem);
+		BUG_ON(bootmem_state != BEFORE_BOOTMEM);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -855,8 +867,6 @@ void __init setup_bootmem_allocator(void
 		bootmap = setup_node_bootmem(nodeid, start_pfn, end_pfn,
 						 bootmap);
 	}
-
-	after_bootmem = 1;
 }
 
 /*
@@ -923,6 +933,8 @@ void __init mem_init(void)
 	/* this will put all low memory onto the freelists */
 	totalram_pages += free_all_bootmem();
 
+	bootmem_state = AFTER_BOOTMEM;
+
 	reservedpages = 0;
 	for (tmp = 0; tmp < max_low_pfn; tmp++)
 		/*
Index: linux-2.6/arch/x86/mm/init_64.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_64.c
+++ linux-2.6/arch/x86/mm/init_64.c
@@ -140,20 +140,26 @@ __setup("noexec32=", nonx32_setup);
 
 /*
  * NOTE: This function is marked __ref because it calls __init function
- * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
+ * (alloc_bootmem_pages). It's safe to do it ONLY when DURING_BOOTMEM.
  */
 static __ref void *spp_getpage(void)
 {
-	void *ptr;
+	void *ptr = NULL;
 
-	if (after_bootmem)
+	switch (bootmem_state) {
+	case AFTER_BOOTMEM:
 		ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
-	else
+		break;
+	case DURING_BOOTMEM:
 		ptr = alloc_bootmem_pages(PAGE_SIZE);
+		break;
+	default:
+		panic("calling spp_getpage before bootmem\n");
+	}
 
 	if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
 		panic("set_pte_phys: cannot allocate page data %s\n",
-			after_bootmem ? "after bootmem" : "");
+			bootmem_state == AFTER_BOOTMEM ? "after bootmem" : "");
 	}
 
 	pr_debug("spp_getpage %p\n", ptr);
@@ -320,16 +326,17 @@ void __init cleanup_highmap(void)
 
 static __ref void *alloc_low_page(unsigned long *phys)
 {
-	unsigned long pfn = e820_table_end++;
+	unsigned long pfn;
 	void *adr;
 
-	if (after_bootmem) {
+	if (bootmem_state == AFTER_BOOTMEM) {
 		adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
 		*phys = __pa(adr);
 
 		return adr;
 	}
 
+	pfn = e820_table_end++;
 	if (pfn >= e820_table_top)
 		panic("alloc_low_page: ran out of memory");
 
@@ -341,7 +348,7 @@ static __ref void *alloc_low_page(unsign
 
 static __ref void unmap_low_page(void *adr)
 {
-	if (after_bootmem)
+	if (bootmem_state == AFTER_BOOTMEM)
 		return;
 
 	early_iounmap(adr, PAGE_SIZE);
@@ -360,7 +367,7 @@ phys_pte_init(pte_t *pte_page, unsigned
 	for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
 
 		if (addr >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for(; i < PTRS_PER_PTE; i++, pte++)
 					set_pte(pte, __pte(0));
 			}
@@ -416,7 +423,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned
 		pgprot_t new_prot = prot;
 
 		if (address >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for (; i < PTRS_PER_PMD; i++, pmd++)
 					set_pmd(pmd, __pmd(0));
 			}
@@ -502,7 +509,7 @@ phys_pud_init(pud_t *pud_page, unsigned
 		if (addr >= end)
 			break;
 
-		if (!after_bootmem &&
+		if (bootmem_state != AFTER_BOOTMEM &&
 				!e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
 			set_pud(pud, __pud(0));
 			continue;
@@ -693,8 +700,6 @@ void __init mem_init(void)
 
 	/* clear_bss() already clear the empty_zero_page */
 
-	reservedpages = 0;
-
 	/* this will put all low memory onto the freelists */
 #ifdef CONFIG_NUMA
 	totalram_pages = numa_free_all_bootmem();
@@ -702,9 +707,9 @@ void __init mem_init(void)
 	totalram_pages = free_all_bootmem();
 #endif
 
+	bootmem_state = AFTER_BOOTMEM;
 	absent_pages = absent_pages_in_range(0, max_pfn);
 	reservedpages = max_pfn - totalram_pages - absent_pages;
-	after_bootmem = 1;
 
 	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
Index: linux-2.6/include/linux/mm.h
===================================================================
--- linux-2.6.orig/include/linux/mm.h
+++ linux-2.6/include/linux/mm.h
@@ -1067,6 +1067,14 @@ extern void __init mmap_init(void);
 extern void show_mem(void);
 extern void si_meminfo(struct sysinfo * val);
 extern void si_meminfo_node(struct sysinfo *val, int nid);
+
+enum bootmem_state_t {
+	BEFORE_BOOTMEM = 0,
+	DURING_BOOTMEM,
+	AFTER_BOOTMEM
+};
+extern enum bootmem_state_t bootmem_state;
+
 extern int after_bootmem;
 
 #ifdef CONFIG_NUMA

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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-05 23:45     ` [PATCH] x86: introduce bootmem_state Yinghai Lu
@ 2009-03-06  6:14       ` H. Peter Anvin
  2009-03-06  6:38         ` Yinghai Lu
  2009-03-06 22:12         ` Jeremy Fitzhardinge
  2009-03-06 14:59       ` Ingo Molnar
  1 sibling, 2 replies; 27+ messages in thread
From: H. Peter Anvin @ 2009-03-06  6:14 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg, linux-kernel

Yinghai Lu wrote:
> Impact: cleanup
> 
> extend after_bootmem and after_init_bootmem to bootmem_state
> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> 

Wouldn't it make more sense to add these as system_state enumerations
and use relational comparisons on them (< <= >= >)?

	-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.


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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06  6:14       ` H. Peter Anvin
@ 2009-03-06  6:38         ` Yinghai Lu
  2009-03-06 22:12         ` Jeremy Fitzhardinge
  1 sibling, 0 replies; 27+ messages in thread
From: Yinghai Lu @ 2009-03-06  6:38 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg, linux-kernel

H. Peter Anvin wrote:
> Yinghai Lu wrote:
>> Impact: cleanup
>>
>> extend after_bootmem and after_init_bootmem to bootmem_state
>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
>>
> 
> Wouldn't it make more sense to add these as system_state enumerations
> and use relational comparisons on them (< <= >= >)?

it is for fixing problem for x86 32/64 merging.
64bit after_bootmem: after bootmem is freed
32bit after_init_bootmem, after we got bootmem initialized.

and previous init_memory_mapping() merging wrongly rename after_init_bootmem to after_bootmem.

also there is after_paging_init, could be merged lated...

but may change bootmem_state to mm_state

YH

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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-05 23:45     ` [PATCH] x86: introduce bootmem_state Yinghai Lu
  2009-03-06  6:14       ` H. Peter Anvin
@ 2009-03-06 14:59       ` Ingo Molnar
  2009-03-06 18:20         ` Yinghai Lu
  2009-03-06 18:38         ` [PATCH] x86: introduce bootmem_state -v2 Yinghai Lu
  1 sibling, 2 replies; 27+ messages in thread
From: Ingo Molnar @ 2009-03-06 14:59 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel


* Yinghai Lu <yinghai@kernel.org> wrote:

> Impact: cleanup
> 
> extend after_bootmem and after_init_bootmem to bootmem_state 
> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM

Ok, that indeed makes all these bootstrap initialization details 
cleaner and more transparent.

> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
>  arch/x86/kernel/setup.c |    1 +
>  arch/x86/mm/init.c      |   13 +++++++------
>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>  include/linux/mm.h      |    8 ++++++++
>  5 files changed, 55 insertions(+), 28 deletions(-)

Note: "git grep after_bootmem" will show you another affected 
architecture as well.

> +++ linux-2.6/include/linux/mm.h
> @@ -1067,6 +1067,14 @@ extern void __init mmap_init(void);
>  extern void show_mem(void);
>  extern void si_meminfo(struct sysinfo * val);
>  extern void si_meminfo_node(struct sysinfo *val, int nid);
> +
> +enum bootmem_state_t {
> +	BEFORE_BOOTMEM = 0,

(nit: =0 is not required. )

> +	DURING_BOOTMEM,
> +	AFTER_BOOTMEM
> +};
> +extern enum bootmem_state_t bootmem_state;

(nit: we put newlines after enum definitions)

	Ingo

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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06 14:59       ` Ingo Molnar
@ 2009-03-06 18:20         ` Yinghai Lu
  2009-03-06 18:38         ` [PATCH] x86: introduce bootmem_state -v2 Yinghai Lu
  1 sibling, 0 replies; 27+ messages in thread
From: Yinghai Lu @ 2009-03-06 18:20 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel

Ingo Molnar wrote:
> * Yinghai Lu <yinghai@kernel.org> wrote:
> 
>> Impact: cleanup
>>
>> extend after_bootmem and after_init_bootmem to bootmem_state 
>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> 
> Ok, that indeed makes all these bootstrap initialization details 
> cleaner and more transparent.
> 
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>
>> ---
>>  arch/x86/kernel/setup.c |    1 +
>>  arch/x86/mm/init.c      |   13 +++++++------
>>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>>  include/linux/mm.h      |    8 ++++++++
>>  5 files changed, 55 insertions(+), 28 deletions(-)
> 
> Note: "git grep after_bootmem" will show you another affected 
> architecture as well.

that is sh, will send patch to them later if needed.

> 
>> +++ linux-2.6/include/linux/mm.h
>> @@ -1067,6 +1067,14 @@ extern void __init mmap_init(void);
>>  extern void show_mem(void);
>>  extern void si_meminfo(struct sysinfo * val);
>>  extern void si_meminfo_node(struct sysinfo *val, int nid);
>> +
>> +enum bootmem_state_t {
>> +	BEFORE_BOOTMEM = 0,
> 
> (nit: =0 is not required. )
some other enum, has it too...
> 
>> +	DURING_BOOTMEM,
>> +	AFTER_BOOTMEM
>> +};
>> +extern enum bootmem_state_t bootmem_state;
> 
> (nit: we put newlines after enum definitions)

ok

YH

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

* [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 14:59       ` Ingo Molnar
  2009-03-06 18:20         ` Yinghai Lu
@ 2009-03-06 18:38         ` Yinghai Lu
  2009-03-06 19:12           ` Ingo Molnar
  1 sibling, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-06 18:38 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel


Impact: cleanup

extend after_bootmem and after_init_bootmem to bootmem_state
and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM

v2: style changes according to ingo

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/kernel/setup.c |    1 +
 arch/x86/mm/init.c      |   13 +++++++------
 arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
 arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
 include/linux/mm.h      |    9 +++++++++
 5 files changed, 56 insertions(+), 28 deletions(-)

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup.c
+++ linux-2.6/arch/x86/kernel/setup.c
@@ -885,6 +885,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	initmem_init(0, max_pfn);
+	bootmem_state = DURING_BOOTMEM;
 
 #ifdef CONFIG_ACPI_SLEEP
 	/*
Index: linux-2.6/arch/x86/mm/init.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init.c
+++ linux-2.6/arch/x86/mm/init.c
@@ -14,7 +14,7 @@ unsigned long __initdata e820_table_star
 unsigned long __meminitdata e820_table_end;
 unsigned long __meminitdata e820_table_top;
 
-int after_bootmem;
+enum bootmem_state bootmem_state = BEFORE_BOOTMEM;
 
 int direct_gbpages
 #ifdef CONFIG_DIRECT_GBPAGES
@@ -206,7 +206,7 @@ unsigned long __init_refok init_memory_m
 
 	printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end);
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		init_gbpages();
 
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
@@ -342,7 +342,7 @@ unsigned long __init_refok init_memory_m
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 #ifdef CONFIG_X86_32
@@ -363,16 +363,17 @@ unsigned long __init_refok init_memory_m
 #endif
 
 #ifdef CONFIG_X86_64
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		mmu_cr4_features = read_cr4();
 #endif
 	__flush_tlb_all();
 
-	if (!after_bootmem && e820_table_end > e820_table_start)
+	if (bootmem_state == BEFORE_BOOTMEM &&
+	    e820_table_end > e820_table_start)
 		reserve_early(e820_table_start << PAGE_SHIFT,
 				 e820_table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		early_memtest(start, end);
 
 	return ret >> PAGE_SHIFT;
Index: linux-2.6/arch/x86/mm/init_32.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_32.c
+++ linux-2.6/arch/x86/mm/init_32.c
@@ -82,14 +82,20 @@ static __init void *alloc_low_page(void)
 static pmd_t * __init one_md_table_init(pgd_t *pgd)
 {
 	pud_t *pud;
-	pmd_t *pmd_table;
+	pmd_t *pmd_table = NULL;
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_bootmem)
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		else
+			break;
+		case BEFORE_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_md_table_init\n");
+		}
 		paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
 		set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
 		pud = pud_offset(pgd, 0);
@@ -113,15 +119,21 @@ static pte_t * __init one_page_table_ini
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_bootmem) {
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
 			if (!page_table)
 				page_table =
 				(pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		} else
+			break;
+		case BEFORE_BOOTMEM:
 			page_table = (pte_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_page_table_init\n");
+		}
 
 		paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
 		set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
@@ -169,7 +181,7 @@ static pte_t *__init page_table_kmap_che
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_bootmem);
+		BUG_ON(bootmem_state != BEFORE_BOOTMEM);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -803,8 +815,6 @@ void __init setup_bootmem_allocator(void
 		bootmap = setup_node_bootmem(nodeid, start_pfn, end_pfn,
 						 bootmap);
 	}
-
-	after_bootmem = 1;
 }
 
 /*
@@ -871,6 +881,8 @@ void __init mem_init(void)
 	/* this will put all low memory onto the freelists */
 	totalram_pages += free_all_bootmem();
 
+	bootmem_state = AFTER_BOOTMEM;
+
 	reservedpages = 0;
 	for (tmp = 0; tmp < max_low_pfn; tmp++)
 		/*
Index: linux-2.6/arch/x86/mm/init_64.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_64.c
+++ linux-2.6/arch/x86/mm/init_64.c
@@ -107,20 +107,26 @@ __setup("noexec32=", nonx32_setup);
 
 /*
  * NOTE: This function is marked __ref because it calls __init function
- * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
+ * (alloc_bootmem_pages). It's safe to do it ONLY when DURING_BOOTMEM.
  */
 static __ref void *spp_getpage(void)
 {
-	void *ptr;
+	void *ptr = NULL;
 
-	if (after_bootmem)
+	switch (bootmem_state) {
+	case AFTER_BOOTMEM:
 		ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
-	else
+		break;
+	case DURING_BOOTMEM:
 		ptr = alloc_bootmem_pages(PAGE_SIZE);
+		break;
+	default:
+		panic("calling spp_getpage before bootmem\n");
+	}
 
 	if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
 		panic("set_pte_phys: cannot allocate page data %s\n",
-			after_bootmem ? "after bootmem" : "");
+			bootmem_state == AFTER_BOOTMEM ? "after bootmem" : "");
 	}
 
 	pr_debug("spp_getpage %p\n", ptr);
@@ -287,16 +293,17 @@ void __init cleanup_highmap(void)
 
 static __ref void *alloc_low_page(unsigned long *phys)
 {
-	unsigned long pfn = e820_table_end++;
+	unsigned long pfn;
 	void *adr;
 
-	if (after_bootmem) {
+	if (bootmem_state == AFTER_BOOTMEM) {
 		adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
 		*phys = __pa(adr);
 
 		return adr;
 	}
 
+	pfn = e820_table_end++;
 	if (pfn >= e820_table_top)
 		panic("alloc_low_page: ran out of memory");
 
@@ -308,7 +315,7 @@ static __ref void *alloc_low_page(unsign
 
 static __ref void unmap_low_page(void *adr)
 {
-	if (after_bootmem)
+	if (bootmem_state == AFTER_BOOTMEM)
 		return;
 
 	early_iounmap(adr, PAGE_SIZE);
@@ -327,7 +334,7 @@ phys_pte_init(pte_t *pte_page, unsigned
 	for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
 
 		if (addr >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for(; i < PTRS_PER_PTE; i++, pte++)
 					set_pte(pte, __pte(0));
 			}
@@ -383,7 +390,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned
 		pgprot_t new_prot = prot;
 
 		if (address >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for (; i < PTRS_PER_PMD; i++, pmd++)
 					set_pmd(pmd, __pmd(0));
 			}
@@ -469,7 +476,7 @@ phys_pud_init(pud_t *pud_page, unsigned
 		if (addr >= end)
 			break;
 
-		if (!after_bootmem &&
+		if (bootmem_state != AFTER_BOOTMEM &&
 				!e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
 			set_pud(pud, __pud(0));
 			continue;
@@ -660,8 +667,6 @@ void __init mem_init(void)
 
 	/* clear_bss() already clear the empty_zero_page */
 
-	reservedpages = 0;
-
 	/* this will put all low memory onto the freelists */
 #ifdef CONFIG_NUMA
 	totalram_pages = numa_free_all_bootmem();
@@ -669,9 +674,9 @@ void __init mem_init(void)
 	totalram_pages = free_all_bootmem();
 #endif
 
+	bootmem_state = AFTER_BOOTMEM;
 	absent_pages = absent_pages_in_range(0, max_pfn);
 	reservedpages = max_pfn - totalram_pages - absent_pages;
-	after_bootmem = 1;
 
 	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
Index: linux-2.6/include/linux/mm.h
===================================================================
--- linux-2.6.orig/include/linux/mm.h
+++ linux-2.6/include/linux/mm.h
@@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
 extern void show_mem(void);
 extern void si_meminfo(struct sysinfo * val);
 extern void si_meminfo_node(struct sysinfo *val, int nid);
+
+enum bootmem_state {
+	BEFORE_BOOTMEM,
+	DURING_BOOTMEM,
+	AFTER_BOOTMEM
+};
+
+extern enum bootmem_state bootmem_state;
+
 extern int after_bootmem;
 
 #ifdef CONFIG_NUMA

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 18:38         ` [PATCH] x86: introduce bootmem_state -v2 Yinghai Lu
@ 2009-03-06 19:12           ` Ingo Molnar
  2009-03-06 19:30             ` Andrew Morton
  2009-03-06 19:50             ` Yinghai Lu
  0 siblings, 2 replies; 27+ messages in thread
From: Ingo Molnar @ 2009-03-06 19:12 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel


* Yinghai Lu <yinghai@kernel.org> wrote:

> 
> Impact: cleanup
> 
> extend after_bootmem and after_init_bootmem to bootmem_state
> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> 
> v2: style changes according to ingo
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
>  arch/x86/kernel/setup.c |    1 +
>  arch/x86/mm/init.c      |   13 +++++++------
>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>  include/linux/mm.h      |    9 +++++++++
>  5 files changed, 56 insertions(+), 28 deletions(-)

> Index: linux-2.6/include/linux/mm.h
> ===================================================================
> --- linux-2.6.orig/include/linux/mm.h
> +++ linux-2.6/include/linux/mm.h
> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
>  extern void show_mem(void);
>  extern void si_meminfo(struct sysinfo * val);
>  extern void si_meminfo_node(struct sysinfo *val, int nid);
> +
> +enum bootmem_state {
> +	BEFORE_BOOTMEM,
> +	DURING_BOOTMEM,
> +	AFTER_BOOTMEM
> +};
> +
> +extern enum bootmem_state bootmem_state;
> +
>  extern int after_bootmem;

Btw., the after_bootmem variable itself should either move to 
x86 (and arch/sh), or should be defined in mm/bootmem.c.

Right now we have this weird mm.h construct that is not actually 
useful to generic code.

Andrew, what would be your preference?

	Ingo

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 19:12           ` Ingo Molnar
@ 2009-03-06 19:30             ` Andrew Morton
  2009-03-06 19:36               ` Ingo Molnar
  2009-03-06 19:50             ` Yinghai Lu
  1 sibling, 1 reply; 27+ messages in thread
From: Andrew Morton @ 2009-03-06 19:30 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: yinghai, tglx, hpa, penberg, linux-kernel

On Fri, 6 Mar 2009 20:12:49 +0100
Ingo Molnar <mingo@elte.hu> wrote:

> 
> * Yinghai Lu <yinghai@kernel.org> wrote:
> 
> > 
> > Impact: cleanup
> > 
> > extend after_bootmem and after_init_bootmem to bootmem_state
> > and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> > 
> > v2: style changes according to ingo
> > 
> > Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> > 
> > ---
> >  arch/x86/kernel/setup.c |    1 +
> >  arch/x86/mm/init.c      |   13 +++++++------
> >  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
> >  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
> >  include/linux/mm.h      |    9 +++++++++
> >  5 files changed, 56 insertions(+), 28 deletions(-)
> 
> > Index: linux-2.6/include/linux/mm.h
> > ===================================================================
> > --- linux-2.6.orig/include/linux/mm.h
> > +++ linux-2.6/include/linux/mm.h
> > @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
> >  extern void show_mem(void);
> >  extern void si_meminfo(struct sysinfo * val);
> >  extern void si_meminfo_node(struct sysinfo *val, int nid);
> > +
> > +enum bootmem_state {
> > +	BEFORE_BOOTMEM,
> > +	DURING_BOOTMEM,
> > +	AFTER_BOOTMEM
> > +};
> > +
> > +extern enum bootmem_state bootmem_state;
> > +
> >  extern int after_bootmem;
> 
> Btw., the after_bootmem variable itself should either move to 
> x86 (and arch/sh), or should be defined in mm/bootmem.c.
> 
> Right now we have this weird mm.h construct that is not actually 
> useful to generic code.
> 
> Andrew, what would be your preference?
> 

If two architectures are using it then it should be provided by core
kernel?

This is obvious if the state transitions are occurring in core-kernel
code, but if the transitions are happening in arch code then making it
a core concept assumes consistency between different architectures
which might not exist.

IOW: dunno.

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 19:30             ` Andrew Morton
@ 2009-03-06 19:36               ` Ingo Molnar
  2009-03-06 22:06                 ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 27+ messages in thread
From: Ingo Molnar @ 2009-03-06 19:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: yinghai, tglx, hpa, penberg, linux-kernel


* Andrew Morton <akpm@linux-foundation.org> wrote:

> On Fri, 6 Mar 2009 20:12:49 +0100
> Ingo Molnar <mingo@elte.hu> wrote:
> 
> > 
> > * Yinghai Lu <yinghai@kernel.org> wrote:
> > 
> > > 
> > > Impact: cleanup
> > > 
> > > extend after_bootmem and after_init_bootmem to bootmem_state
> > > and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> > > 
> > > v2: style changes according to ingo
> > > 
> > > Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> > > 
> > > ---
> > >  arch/x86/kernel/setup.c |    1 +
> > >  arch/x86/mm/init.c      |   13 +++++++------
> > >  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
> > >  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
> > >  include/linux/mm.h      |    9 +++++++++
> > >  5 files changed, 56 insertions(+), 28 deletions(-)
> > 
> > > Index: linux-2.6/include/linux/mm.h
> > > ===================================================================
> > > --- linux-2.6.orig/include/linux/mm.h
> > > +++ linux-2.6/include/linux/mm.h
> > > @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
> > >  extern void show_mem(void);
> > >  extern void si_meminfo(struct sysinfo * val);
> > >  extern void si_meminfo_node(struct sysinfo *val, int nid);
> > > +
> > > +enum bootmem_state {
> > > +	BEFORE_BOOTMEM,
> > > +	DURING_BOOTMEM,
> > > +	AFTER_BOOTMEM
> > > +};
> > > +
> > > +extern enum bootmem_state bootmem_state;
> > > +
> > >  extern int after_bootmem;
> > 
> > Btw., the after_bootmem variable itself should either move to 
> > x86 (and arch/sh), or should be defined in mm/bootmem.c.
> > 
> > Right now we have this weird mm.h construct that is not actually 
> > useful to generic code.
> > 
> > Andrew, what would be your preference?
> > 
> 
> If two architectures are using it then it should be provided 
> by core kernel?
> 
> This is obvious if the state transitions are occurring in 
> core-kernel code, but if the transitions are happening in arch 
> code then making it a core concept assumes consistency between 
> different architectures which might not exist.
> 
> IOW: dunno.

Core kernel could provide a wrapper allocator which calls the 
right method depending on which state we are in. It will call 
bootmem_alloc() if called early, and kmalloc() if called later. 
Or something like that. Would there be any utility in that?

	Ingo

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 19:12           ` Ingo Molnar
  2009-03-06 19:30             ` Andrew Morton
@ 2009-03-06 19:50             ` Yinghai Lu
  2009-03-06 20:15               ` Ingo Molnar
  1 sibling, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-06 19:50 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel

Ingo Molnar wrote:
> * Yinghai Lu <yinghai@kernel.org> wrote:
> 
>> Impact: cleanup
>>
>> extend after_bootmem and after_init_bootmem to bootmem_state
>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
>>
>> v2: style changes according to ingo
>>
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>
>> ---
>>  arch/x86/kernel/setup.c |    1 +
>>  arch/x86/mm/init.c      |   13 +++++++------
>>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>>  include/linux/mm.h      |    9 +++++++++
>>  5 files changed, 56 insertions(+), 28 deletions(-)
> 
>> Index: linux-2.6/include/linux/mm.h
>> ===================================================================
>> --- linux-2.6.orig/include/linux/mm.h
>> +++ linux-2.6/include/linux/mm.h
>> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
>>  extern void show_mem(void);
>>  extern void si_meminfo(struct sysinfo * val);
>>  extern void si_meminfo_node(struct sysinfo *val, int nid);
>> +
>> +enum bootmem_state {
>> +	BEFORE_BOOTMEM,
>> +	DURING_BOOTMEM,
>> +	AFTER_BOOTMEM
>> +};
>> +
>> +extern enum bootmem_state bootmem_state;
>> +
>>  extern int after_bootmem;
> 
> Btw., the after_bootmem variable itself should either move to 
> x86 (and arch/sh), or should be defined in mm/bootmem.c.
> 
> Right now we have this weird mm.h construct that is not actually 
> useful to generic code.

with this patch, only sh is using after_bootmem. could
1. make sh to use bootmem_state
2. then remove after_bootmem

YH

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 19:50             ` Yinghai Lu
@ 2009-03-06 20:15               ` Ingo Molnar
  2009-03-06 20:40                 ` Yinghai Lu
  0 siblings, 1 reply; 27+ messages in thread
From: Ingo Molnar @ 2009-03-06 20:15 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel


* Yinghai Lu <yinghai@kernel.org> wrote:

> Ingo Molnar wrote:
> > * Yinghai Lu <yinghai@kernel.org> wrote:
> > 
> >> Impact: cleanup
> >>
> >> extend after_bootmem and after_init_bootmem to bootmem_state
> >> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> >>
> >> v2: style changes according to ingo
> >>
> >> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> >>
> >> ---
> >>  arch/x86/kernel/setup.c |    1 +
> >>  arch/x86/mm/init.c      |   13 +++++++------
> >>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
> >>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
> >>  include/linux/mm.h      |    9 +++++++++
> >>  5 files changed, 56 insertions(+), 28 deletions(-)
> > 
> >> Index: linux-2.6/include/linux/mm.h
> >> ===================================================================
> >> --- linux-2.6.orig/include/linux/mm.h
> >> +++ linux-2.6/include/linux/mm.h
> >> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
> >>  extern void show_mem(void);
> >>  extern void si_meminfo(struct sysinfo * val);
> >>  extern void si_meminfo_node(struct sysinfo *val, int nid);
> >> +
> >> +enum bootmem_state {
> >> +	BEFORE_BOOTMEM,
> >> +	DURING_BOOTMEM,
> >> +	AFTER_BOOTMEM
> >> +};
> >> +
> >> +extern enum bootmem_state bootmem_state;
> >> +
> >>  extern int after_bootmem;
> > 
> > Btw., the after_bootmem variable itself should either move 
> > to x86 (and arch/sh), or should be defined in mm/bootmem.c.
> > 
> > Right now we have this weird mm.h construct that is not 
> > actually useful to generic code.
> 
> with this patch, only sh is using after_bootmem. could
> 1. make sh to use bootmem_state
> 2. then remove after_bootmem

Hm, lets leave arch/sh alone for now i think - the commits are 
desintd for the x86 tree.

But we should move our after_bootmem to arch/x86/include/ and 
not pollute mm.h with it. It's an x86 internal detail for now.

	Ingo

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 20:15               ` Ingo Molnar
@ 2009-03-06 20:40                 ` Yinghai Lu
  2009-03-06 21:35                   ` Ingo Molnar
  0 siblings, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-06 20:40 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel

Ingo Molnar wrote:
> * Yinghai Lu <yinghai@kernel.org> wrote:
> 
>> Ingo Molnar wrote:
>>> * Yinghai Lu <yinghai@kernel.org> wrote:
>>>
>>>> Impact: cleanup
>>>>
>>>> extend after_bootmem and after_init_bootmem to bootmem_state
>>>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
>>>>
>>>> v2: style changes according to ingo
>>>>
>>>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>>>
>>>> ---
>>>>  arch/x86/kernel/setup.c |    1 +
>>>>  arch/x86/mm/init.c      |   13 +++++++------
>>>>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>>>>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>>>>  include/linux/mm.h      |    9 +++++++++
>>>>  5 files changed, 56 insertions(+), 28 deletions(-)
>>>> Index: linux-2.6/include/linux/mm.h
>>>> ===================================================================
>>>> --- linux-2.6.orig/include/linux/mm.h
>>>> +++ linux-2.6/include/linux/mm.h
>>>> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
>>>>  extern void show_mem(void);
>>>>  extern void si_meminfo(struct sysinfo * val);
>>>>  extern void si_meminfo_node(struct sysinfo *val, int nid);
>>>> +
>>>> +enum bootmem_state {
>>>> +	BEFORE_BOOTMEM,
>>>> +	DURING_BOOTMEM,
>>>> +	AFTER_BOOTMEM
>>>> +};
>>>> +
>>>> +extern enum bootmem_state bootmem_state;
>>>> +
>>>>  extern int after_bootmem;
>>> Btw., the after_bootmem variable itself should either move 
>>> to x86 (and arch/sh), or should be defined in mm/bootmem.c.
>>>
>>> Right now we have this weird mm.h construct that is not 
>>> actually useful to generic code.
>> with this patch, only sh is using after_bootmem. could
>> 1. make sh to use bootmem_state
>> 2. then remove after_bootmem
> 
> Hm, lets leave arch/sh alone for now i think - the commits are 
> desintd for the x86 tree.
> 
> But we should move our after_bootmem to arch/x86/include/ and 
> not pollute mm.h with it. It's an x86 internal detail for now.
> 

you mean move bootmem_state to arch/x86/include ?
with this patch are not using after_bootmem anymore.

YH

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 20:40                 ` Yinghai Lu
@ 2009-03-06 21:35                   ` Ingo Molnar
  2009-03-07  0:49                     ` [PATCH] x86: introduce bootmem_state -v3 Yinghai Lu
  0 siblings, 1 reply; 27+ messages in thread
From: Ingo Molnar @ 2009-03-06 21:35 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, H. Peter Anvin, Andrew Morton, Pekka Enberg,
	linux-kernel


* Yinghai Lu <yinghai@kernel.org> wrote:

> Ingo Molnar wrote:
> > * Yinghai Lu <yinghai@kernel.org> wrote:
> > 
> >> Ingo Molnar wrote:
> >>> * Yinghai Lu <yinghai@kernel.org> wrote:
> >>>
> >>>> Impact: cleanup
> >>>>
> >>>> extend after_bootmem and after_init_bootmem to bootmem_state
> >>>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
> >>>>
> >>>> v2: style changes according to ingo
> >>>>
> >>>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> >>>>
> >>>> ---
> >>>>  arch/x86/kernel/setup.c |    1 +
> >>>>  arch/x86/mm/init.c      |   13 +++++++------
> >>>>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
> >>>>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
> >>>>  include/linux/mm.h      |    9 +++++++++
> >>>>  5 files changed, 56 insertions(+), 28 deletions(-)
> >>>> Index: linux-2.6/include/linux/mm.h
> >>>> ===================================================================
> >>>> --- linux-2.6.orig/include/linux/mm.h
> >>>> +++ linux-2.6/include/linux/mm.h
> >>>> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
> >>>>  extern void show_mem(void);
> >>>>  extern void si_meminfo(struct sysinfo * val);
> >>>>  extern void si_meminfo_node(struct sysinfo *val, int nid);
> >>>> +
> >>>> +enum bootmem_state {
> >>>> +	BEFORE_BOOTMEM,
> >>>> +	DURING_BOOTMEM,
> >>>> +	AFTER_BOOTMEM
> >>>> +};
> >>>> +
> >>>> +extern enum bootmem_state bootmem_state;
> >>>> +
> >>>>  extern int after_bootmem;
> >>> Btw., the after_bootmem variable itself should either move 
> >>> to x86 (and arch/sh), or should be defined in mm/bootmem.c.
> >>>
> >>> Right now we have this weird mm.h construct that is not 
> >>> actually useful to generic code.
> >> with this patch, only sh is using after_bootmem. could
> >> 1. make sh to use bootmem_state
> >> 2. then remove after_bootmem
> > 
> > Hm, lets leave arch/sh alone for now i think - the commits are 
> > desintd for the x86 tree.
> > 
> > But we should move our after_bootmem to arch/x86/include/ and 
> > not pollute mm.h with it. It's an x86 internal detail for now.
> > 
> 
> you mean move bootmem_state to arch/x86/include ?
> with this patch are not using after_bootmem anymore.

Correct. So basically we change x86 to use bootmem_state only, 
and leave mm.h alone. arch/sh can still use after_bootmem. 
(which it should likely move to its own header files - but 
that's for a different patch)

	Ingo

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

* Re: [PATCH] x86: introduce bootmem_state -v2
  2009-03-06 19:36               ` Ingo Molnar
@ 2009-03-06 22:06                 ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 27+ messages in thread
From: Jeremy Fitzhardinge @ 2009-03-06 22:06 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, yinghai, tglx, hpa, penberg, linux-kernel

Ingo Molnar wrote:
> * Andrew Morton <akpm@linux-foundation.org> wrote:
>
>   
>> On Fri, 6 Mar 2009 20:12:49 +0100
>> Ingo Molnar <mingo@elte.hu> wrote:
>>
>>     
>>> * Yinghai Lu <yinghai@kernel.org> wrote:
>>>
>>>       
>>>> Impact: cleanup
>>>>
>>>> extend after_bootmem and after_init_bootmem to bootmem_state
>>>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
>>>>
>>>> v2: style changes according to ingo
>>>>
>>>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>>>>
>>>> ---
>>>>  arch/x86/kernel/setup.c |    1 +
>>>>  arch/x86/mm/init.c      |   13 +++++++------
>>>>  arch/x86/mm/init_32.c   |   28 ++++++++++++++++++++--------
>>>>  arch/x86/mm/init_64.c   |   33 +++++++++++++++++++--------------
>>>>  include/linux/mm.h      |    9 +++++++++
>>>>  5 files changed, 56 insertions(+), 28 deletions(-)
>>>>         
>>>> Index: linux-2.6/include/linux/mm.h
>>>> ===================================================================
>>>> --- linux-2.6.orig/include/linux/mm.h
>>>> +++ linux-2.6/include/linux/mm.h
>>>> @@ -1067,6 +1067,15 @@ extern void __init mmap_init(void);
>>>>  extern void show_mem(void);
>>>>  extern void si_meminfo(struct sysinfo * val);
>>>>  extern void si_meminfo_node(struct sysinfo *val, int nid);
>>>> +
>>>> +enum bootmem_state {
>>>> +	BEFORE_BOOTMEM,
>>>> +	DURING_BOOTMEM,
>>>> +	AFTER_BOOTMEM
>>>> +};
>>>> +
>>>> +extern enum bootmem_state bootmem_state;
>>>> +
>>>>  extern int after_bootmem;
>>>>         
>>> Btw., the after_bootmem variable itself should either move to 
>>> x86 (and arch/sh), or should be defined in mm/bootmem.c.
>>>
>>> Right now we have this weird mm.h construct that is not actually 
>>> useful to generic code.
>>>
>>> Andrew, what would be your preference?
>>>
>>>       
>> If two architectures are using it then it should be provided 
>> by core kernel?
>>
>> This is obvious if the state transitions are occurring in 
>> core-kernel code, but if the transitions are happening in arch 
>> code then making it a core concept assumes consistency between 
>> different architectures which might not exist.
>>
>> IOW: dunno.
>>     
>
> Core kernel could provide a wrapper allocator which calls the 
> right method depending on which state we are in. It will call 
> bootmem_alloc() if called early, and kmalloc() if called later. 
> Or something like that. Would there be any utility in that?
>   

Yes, so long as you're never intending to free the memory (since you 
won't know which free function to use for a given pointer - assuming one 
even exists).  And code which does:

    p = use_anytime_alloctor();

...
    kfree(p);        /* I know it was really allocated by kmalloc */


should be shot.

    J

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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06  6:14       ` H. Peter Anvin
  2009-03-06  6:38         ` Yinghai Lu
@ 2009-03-06 22:12         ` Jeremy Fitzhardinge
  2009-03-06 23:34           ` H. Peter Anvin
  1 sibling, 1 reply; 27+ messages in thread
From: Jeremy Fitzhardinge @ 2009-03-06 22:12 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Yinghai Lu, mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg,
	linux-kernel

H. Peter Anvin wrote:
> Yinghai Lu wrote:
>   
>> Impact: cleanup
>>
>> extend after_bootmem and after_init_bootmem to bootmem_state
>> and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM
>>
>>     
>
> Wouldn't it make more sense to add these as system_state enumerations
> and use relational comparisons on them (< <= >= >)?

Please, no.  system_state should be deprecated; its hard enough to have 
a notion of some kind of system-wide state, but putting subsystem 
specific substates into it just makes things worse.

    J

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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06 22:12         ` Jeremy Fitzhardinge
@ 2009-03-06 23:34           ` H. Peter Anvin
  2009-03-07  0:01             ` Andrew Morton
  2009-03-07  0:10             ` Jeremy Fitzhardinge
  0 siblings, 2 replies; 27+ messages in thread
From: H. Peter Anvin @ 2009-03-06 23:34 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Yinghai Lu, mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg,
	linux-kernel

Jeremy Fitzhardinge wrote:
> 
> Please, no.  system_state should be deprecated; its hard enough to have 
> a notion of some kind of system-wide state, but putting subsystem 
> specific substates into it just makes things worse.
> 

Does it?  It seems to me to have a bunch of state variables which can 
interact in $DEITY knows how many ways sounds like a bad idea.

	-hpa


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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06 23:34           ` H. Peter Anvin
@ 2009-03-07  0:01             ` Andrew Morton
  2009-03-07  0:10             ` Jeremy Fitzhardinge
  1 sibling, 0 replies; 27+ messages in thread
From: Andrew Morton @ 2009-03-07  0:01 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: jeremy, yinghai, mingo, tglx, penberg, linux-kernel

On Fri, 06 Mar 2009 15:34:01 -0800
"H. Peter Anvin" <hpa@zytor.com> wrote:

> Jeremy Fitzhardinge wrote:
> > 
> > Please, no.  system_state should be deprecated; its hard enough to have 
> > a notion of some kind of system-wide state, but putting subsystem 
> > specific substates into it just makes things worse.
> > 
> 
> Does it?  It seems to me to have a bunch of state variables which can 
> interact in $DEITY knows how many ways sounds like a bad idea.
> 

No, that's the whole point.  If each subsystem adds its own
subsystem-private state then the subsystems *won't* interact.


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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-06 23:34           ` H. Peter Anvin
  2009-03-07  0:01             ` Andrew Morton
@ 2009-03-07  0:10             ` Jeremy Fitzhardinge
  2009-03-07  0:11               ` H. Peter Anvin
  1 sibling, 1 reply; 27+ messages in thread
From: Jeremy Fitzhardinge @ 2009-03-07  0:10 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Yinghai Lu, mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg,
	linux-kernel

H. Peter Anvin wrote:
> Jeremy Fitzhardinge wrote:
>>
>> Please, no.  system_state should be deprecated; its hard enough to 
>> have a notion of some kind of system-wide state, but putting 
>> subsystem specific substates into it just makes things worse.
>>
>
> Does it?  It seems to me to have a bunch of state variables which can 
> interact in $DEITY knows how many ways sounds like a bad idea.

If each state variable describes the state of a single subsystem in a 
well-defined way then it is meaningful and fairly easy to understand;  I 
would love to have a straightforward way to query which allocator is 
safe to use at a given moment.

The total number of states is always going to be subsys1 * subsys2 * 
..., but folding them all into one state variable only makes sense if we 
have a well-defined set of states *and* transitions between them.  But 
even then it implies that we have enough coupling between our subsystems 
that we would even care what their aggregate state is, which is already 
a bad idea.  If we keep the internal workings of our subsystems as 
internal details, then having private state variables is the way to go.

The real problem with system_state is that it has a few broadly-defined 
values, but no real explanation of what they mean, so they end up 
getting used in inappropriate ways (like the virt_addr_valid() thing I 
fixed yesterday).

    J


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

* Re: [PATCH] x86: introduce bootmem_state
  2009-03-07  0:10             ` Jeremy Fitzhardinge
@ 2009-03-07  0:11               ` H. Peter Anvin
  0 siblings, 0 replies; 27+ messages in thread
From: H. Peter Anvin @ 2009-03-07  0:11 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Yinghai Lu, mingo, Thomas Gleixner, Andrew Morton, Pekka Enberg,
	linux-kernel

Jeremy Fitzhardinge wrote:
> 
> The total number of states is always going to be subsys1 * subsys2 * 
> ..., but folding them all into one state variable only makes sense if we 
> have a well-defined set of states *and* transitions between them.  But 
> even then it implies that we have enough coupling between our subsystems 
> that we would even care what their aggregate state is, which is already 
> a bad idea.  If we keep the internal workings of our subsystems as 
> internal details, then having private state variables is the way to go.
> 
> The real problem with system_state is that it has a few broadly-defined 
> values, but no real explanation of what they mean, so they end up 
> getting used in inappropriate ways (like the virt_addr_valid() thing I 
> fixed yesterday).
> 

Obviously.

	-hpa


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

* [PATCH] x86: introduce bootmem_state -v3
  2009-03-06 21:35                   ` Ingo Molnar
@ 2009-03-07  0:49                     ` Yinghai Lu
  2009-03-08 18:54                       ` [tip:kmemcheck] x86: introduce bootmem_state Yinghai Lu
  0 siblings, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-07  0:49 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner, H. Peter Anvin, Andrew Morton
  Cc: Pekka Enberg, linux-kernel


Impact: cleanup

extend after_bootmem and after_init_bootmem to bootmem_state
and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM

v2: style changes according to ingo
v3: move bootmem_state declaring to arch/x86/include

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/include/asm/page_types.h |    8 ++++++++
 arch/x86/kernel/setup.c           |    1 +
 arch/x86/mm/init.c                |   13 +++++++------
 arch/x86/mm/init_32.c             |   28 ++++++++++++++++++++--------
 arch/x86/mm/init_64.c             |   33 +++++++++++++++++++--------------
 5 files changed, 55 insertions(+), 28 deletions(-)

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup.c
+++ linux-2.6/arch/x86/kernel/setup.c
@@ -885,6 +885,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	initmem_init(0, max_pfn);
+	bootmem_state = DURING_BOOTMEM;
 
 #ifdef CONFIG_ACPI_SLEEP
 	/*
Index: linux-2.6/arch/x86/mm/init.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init.c
+++ linux-2.6/arch/x86/mm/init.c
@@ -14,7 +14,7 @@ unsigned long __initdata e820_table_star
 unsigned long __meminitdata e820_table_end;
 unsigned long __meminitdata e820_table_top;
 
-int after_bootmem;
+enum bootmem_state bootmem_state = BEFORE_BOOTMEM;
 
 int direct_gbpages
 #ifdef CONFIG_DIRECT_GBPAGES
@@ -206,7 +206,7 @@ unsigned long __init_refok init_memory_m
 
 	printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end);
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		init_gbpages();
 
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
@@ -342,7 +342,7 @@ unsigned long __init_refok init_memory_m
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 #ifdef CONFIG_X86_32
@@ -363,16 +363,17 @@ unsigned long __init_refok init_memory_m
 #endif
 
 #ifdef CONFIG_X86_64
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		mmu_cr4_features = read_cr4();
 #endif
 	__flush_tlb_all();
 
-	if (!after_bootmem && e820_table_end > e820_table_start)
+	if (bootmem_state == BEFORE_BOOTMEM &&
+	    e820_table_end > e820_table_start)
 		reserve_early(e820_table_start << PAGE_SHIFT,
 				 e820_table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		early_memtest(start, end);
 
 	return ret >> PAGE_SHIFT;
Index: linux-2.6/arch/x86/mm/init_32.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_32.c
+++ linux-2.6/arch/x86/mm/init_32.c
@@ -82,14 +82,20 @@ static __init void *alloc_low_page(void)
 static pmd_t * __init one_md_table_init(pgd_t *pgd)
 {
 	pud_t *pud;
-	pmd_t *pmd_table;
+	pmd_t *pmd_table = NULL;
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_bootmem)
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		else
+			break;
+		case BEFORE_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_md_table_init\n");
+		}
 		paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
 		set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
 		pud = pud_offset(pgd, 0);
@@ -113,15 +119,21 @@ static pte_t * __init one_page_table_ini
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_bootmem) {
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
 			if (!page_table)
 				page_table =
 				(pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		} else
+			break;
+		case BEFORE_BOOTMEM:
 			page_table = (pte_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_page_table_init\n");
+		}
 
 		paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
 		set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
@@ -169,7 +181,7 @@ static pte_t *__init page_table_kmap_che
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_bootmem);
+		BUG_ON(bootmem_state != BEFORE_BOOTMEM);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -803,8 +815,6 @@ void __init setup_bootmem_allocator(void
 		bootmap = setup_node_bootmem(nodeid, start_pfn, end_pfn,
 						 bootmap);
 	}
-
-	after_bootmem = 1;
 }
 
 /*
@@ -871,6 +881,8 @@ void __init mem_init(void)
 	/* this will put all low memory onto the freelists */
 	totalram_pages += free_all_bootmem();
 
+	bootmem_state = AFTER_BOOTMEM;
+
 	reservedpages = 0;
 	for (tmp = 0; tmp < max_low_pfn; tmp++)
 		/*
Index: linux-2.6/arch/x86/mm/init_64.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_64.c
+++ linux-2.6/arch/x86/mm/init_64.c
@@ -107,20 +107,26 @@ __setup("noexec32=", nonx32_setup);
 
 /*
  * NOTE: This function is marked __ref because it calls __init function
- * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
+ * (alloc_bootmem_pages). It's safe to do it ONLY when DURING_BOOTMEM.
  */
 static __ref void *spp_getpage(void)
 {
-	void *ptr;
+	void *ptr = NULL;
 
-	if (after_bootmem)
+	switch (bootmem_state) {
+	case AFTER_BOOTMEM:
 		ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
-	else
+		break;
+	case DURING_BOOTMEM:
 		ptr = alloc_bootmem_pages(PAGE_SIZE);
+		break;
+	default:
+		panic("calling spp_getpage before bootmem\n");
+	}
 
 	if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
 		panic("set_pte_phys: cannot allocate page data %s\n",
-			after_bootmem ? "after bootmem" : "");
+			bootmem_state == AFTER_BOOTMEM ? "after bootmem" : "");
 	}
 
 	pr_debug("spp_getpage %p\n", ptr);
@@ -287,16 +293,17 @@ void __init cleanup_highmap(void)
 
 static __ref void *alloc_low_page(unsigned long *phys)
 {
-	unsigned long pfn = e820_table_end++;
+	unsigned long pfn;
 	void *adr;
 
-	if (after_bootmem) {
+	if (bootmem_state == AFTER_BOOTMEM) {
 		adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
 		*phys = __pa(adr);
 
 		return adr;
 	}
 
+	pfn = e820_table_end++;
 	if (pfn >= e820_table_top)
 		panic("alloc_low_page: ran out of memory");
 
@@ -308,7 +315,7 @@ static __ref void *alloc_low_page(unsign
 
 static __ref void unmap_low_page(void *adr)
 {
-	if (after_bootmem)
+	if (bootmem_state == AFTER_BOOTMEM)
 		return;
 
 	early_iounmap(adr, PAGE_SIZE);
@@ -327,7 +334,7 @@ phys_pte_init(pte_t *pte_page, unsigned
 	for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
 
 		if (addr >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for(; i < PTRS_PER_PTE; i++, pte++)
 					set_pte(pte, __pte(0));
 			}
@@ -383,7 +390,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned
 		pgprot_t new_prot = prot;
 
 		if (address >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for (; i < PTRS_PER_PMD; i++, pmd++)
 					set_pmd(pmd, __pmd(0));
 			}
@@ -469,7 +476,7 @@ phys_pud_init(pud_t *pud_page, unsigned
 		if (addr >= end)
 			break;
 
-		if (!after_bootmem &&
+		if (bootmem_state != AFTER_BOOTMEM &&
 				!e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
 			set_pud(pud, __pud(0));
 			continue;
@@ -660,8 +667,6 @@ void __init mem_init(void)
 
 	/* clear_bss() already clear the empty_zero_page */
 
-	reservedpages = 0;
-
 	/* this will put all low memory onto the freelists */
 #ifdef CONFIG_NUMA
 	totalram_pages = numa_free_all_bootmem();
@@ -669,9 +674,9 @@ void __init mem_init(void)
 	totalram_pages = free_all_bootmem();
 #endif
 
+	bootmem_state = AFTER_BOOTMEM;
 	absent_pages = absent_pages_in_range(0, max_pfn);
 	reservedpages = max_pfn - totalram_pages - absent_pages;
-	after_bootmem = 1;
 
 	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
Index: linux-2.6/arch/x86/include/asm/page_types.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/page_types.h
+++ linux-2.6/arch/x86/include/asm/page_types.h
@@ -40,6 +40,14 @@
 
 #ifndef __ASSEMBLY__
 
+enum bootmem_state {
+	BEFORE_BOOTMEM,
+	DURING_BOOTMEM,
+	AFTER_BOOTMEM
+};
+
+extern enum bootmem_state bootmem_state;
+
 extern int page_is_ram(unsigned long pagenr);
 extern int devmem_is_allowed(unsigned long pagenr);
 

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

* [tip:kmemcheck] x86: introduce bootmem_state
  2009-03-07  0:49                     ` [PATCH] x86: introduce bootmem_state -v3 Yinghai Lu
@ 2009-03-08 18:54                       ` Yinghai Lu
  2009-03-08 18:58                         ` Ingo Molnar
  0 siblings, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-08 18:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, yinghai, akpm, penberg, tglx, mingo

Commit-ID:  4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
Gitweb:     http://git.kernel.org/tip/4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
Author:     "Yinghai Lu" <yinghai@kernel.org>
AuthorDate: Fri, 6 Mar 2009 16:49:00 -0800
Commit:     Ingo Molnar <mingo@elte.hu>
CommitDate: Sun, 8 Mar 2009 19:43:09 +0100

x86: introduce bootmem_state

Impact: cleanup

extend after_bootmem and after_init_bootmem to bootmem_state
and will have BEFORE_BOOTMEM, DURING_BOOTMEM, AFTER_BOOTMEM

v2: style changes according to ingo
v3: move bootmem_state declaring to arch/x86/include

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Andrew Morton <akpm@linux-foundation.org>
LKML-Reference: <49B1C47C.5080401@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 arch/x86/include/asm/page_types.h |    8 ++++++++
 arch/x86/kernel/setup.c           |    1 +
 arch/x86/mm/init.c                |   13 +++++++------
 arch/x86/mm/init_32.c             |   28 ++++++++++++++++++++--------
 arch/x86/mm/init_64.c             |   33 +++++++++++++++++++--------------
 5 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/arch/x86/include/asm/page_types.h b/arch/x86/include/asm/page_types.h
index 826ad37..f8b9c88 100644
--- a/arch/x86/include/asm/page_types.h
+++ b/arch/x86/include/asm/page_types.h
@@ -40,6 +40,14 @@
 
 #ifndef __ASSEMBLY__
 
+enum bootmem_state {
+	BEFORE_BOOTMEM,
+	DURING_BOOTMEM,
+	AFTER_BOOTMEM
+};
+
+extern enum bootmem_state bootmem_state;
+
 extern int page_is_ram(unsigned long pagenr);
 extern int devmem_is_allowed(unsigned long pagenr);
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index f28c56e..ce9e888 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -885,6 +885,7 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	initmem_init(0, max_pfn);
+	bootmem_state = DURING_BOOTMEM;
 
 #ifdef CONFIG_ACPI_SLEEP
 	/*
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index a8d2933..f98b501 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -14,7 +14,7 @@ unsigned long __initdata e820_table_start;
 unsigned long __meminitdata e820_table_end;
 unsigned long __meminitdata e820_table_top;
 
-int after_bootmem;
+enum bootmem_state bootmem_state = BEFORE_BOOTMEM;
 
 int direct_gbpages
 #ifdef CONFIG_DIRECT_GBPAGES
@@ -143,7 +143,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 
 	printk(KERN_INFO "init_memory_mapping: %016lx-%016lx\n", start, end);
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		init_gbpages();
 
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
@@ -283,7 +283,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 	 * memory mapped. Unfortunately this is done currently before the
 	 * nodes are discovered.
 	 */
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		find_early_table_space(end, use_pse, use_gbpages);
 
 #ifdef CONFIG_X86_32
@@ -304,16 +304,17 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
 #endif
 
 #ifdef CONFIG_X86_64
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		mmu_cr4_features = read_cr4();
 #endif
 	__flush_tlb_all();
 
-	if (!after_bootmem && e820_table_end > e820_table_start)
+	if (bootmem_state == BEFORE_BOOTMEM &&
+	    e820_table_end > e820_table_start)
 		reserve_early(e820_table_start << PAGE_SHIFT,
 				 e820_table_end << PAGE_SHIFT, "PGTABLE");
 
-	if (!after_bootmem)
+	if (bootmem_state == BEFORE_BOOTMEM)
 		early_memtest(start, end);
 
 	return ret >> PAGE_SHIFT;
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index ccadfb1..34ef5c7 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -82,14 +82,20 @@ static __init void *alloc_low_page(void)
 static pmd_t * __init one_md_table_init(pgd_t *pgd)
 {
 	pud_t *pud;
-	pmd_t *pmd_table;
+	pmd_t *pmd_table = NULL;
 
 #ifdef CONFIG_X86_PAE
 	if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
-		if (after_bootmem)
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		else
+			break;
+		case BEFORE_BOOTMEM:
 			pmd_table = (pmd_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_md_table_init\n");
+		}
 		paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
 		set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
 		pud = pud_offset(pgd, 0);
@@ -113,15 +119,21 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
 	if (!(pmd_val(*pmd) & _PAGE_PRESENT)) {
 		pte_t *page_table = NULL;
 
-		if (after_bootmem) {
+		switch (bootmem_state) {
+		case DURING_BOOTMEM:
 #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KMEMCHECK)
 			page_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
 #endif
 			if (!page_table)
 				page_table =
 				(pte_t *)alloc_bootmem_low_pages(PAGE_SIZE);
-		} else
+			break;
+		case BEFORE_BOOTMEM:
 			page_table = (pte_t *)alloc_low_page();
+			break;
+		default:
+			panic("after bootmem call one_page_table_init\n");
+		}
 
 		paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
 		set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
@@ -169,7 +181,7 @@ static pte_t *__init page_table_kmap_check(pte_t *pte, pmd_t *pmd,
 		pte_t *newpte;
 		int i;
 
-		BUG_ON(after_bootmem);
+		BUG_ON(bootmem_state != BEFORE_BOOTMEM);
 		newpte = alloc_low_page();
 		for (i = 0; i < PTRS_PER_PTE; i++)
 			set_pte(newpte + i, pte[i]);
@@ -855,8 +867,6 @@ void __init setup_bootmem_allocator(void)
 		bootmap = setup_node_bootmem(nodeid, start_pfn, end_pfn,
 						 bootmap);
 	}
-
-	after_bootmem = 1;
 }
 
 /*
@@ -923,6 +933,8 @@ void __init mem_init(void)
 	/* this will put all low memory onto the freelists */
 	totalram_pages += free_all_bootmem();
 
+	bootmem_state = AFTER_BOOTMEM;
+
 	reservedpages = 0;
 	for (tmp = 0; tmp < max_low_pfn; tmp++)
 		/*
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index e127f2e..20ade92 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -140,20 +140,26 @@ __setup("noexec32=", nonx32_setup);
 
 /*
  * NOTE: This function is marked __ref because it calls __init function
- * (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
+ * (alloc_bootmem_pages). It's safe to do it ONLY when DURING_BOOTMEM.
  */
 static __ref void *spp_getpage(void)
 {
-	void *ptr;
+	void *ptr = NULL;
 
-	if (after_bootmem)
+	switch (bootmem_state) {
+	case AFTER_BOOTMEM:
 		ptr = (void *) get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
-	else
+		break;
+	case DURING_BOOTMEM:
 		ptr = alloc_bootmem_pages(PAGE_SIZE);
+		break;
+	default:
+		panic("calling spp_getpage before bootmem\n");
+	}
 
 	if (!ptr || ((unsigned long)ptr & ~PAGE_MASK)) {
 		panic("set_pte_phys: cannot allocate page data %s\n",
-			after_bootmem ? "after bootmem" : "");
+			bootmem_state == AFTER_BOOTMEM ? "after bootmem" : "");
 	}
 
 	pr_debug("spp_getpage %p\n", ptr);
@@ -320,16 +326,17 @@ void __init cleanup_highmap(void)
 
 static __ref void *alloc_low_page(unsigned long *phys)
 {
-	unsigned long pfn = e820_table_end++;
+	unsigned long pfn;
 	void *adr;
 
-	if (after_bootmem) {
+	if (bootmem_state == AFTER_BOOTMEM) {
 		adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
 		*phys = __pa(adr);
 
 		return adr;
 	}
 
+	pfn = e820_table_end++;
 	if (pfn >= e820_table_top)
 		panic("alloc_low_page: ran out of memory");
 
@@ -341,7 +348,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
 
 static __ref void unmap_low_page(void *adr)
 {
-	if (after_bootmem)
+	if (bootmem_state == AFTER_BOOTMEM)
 		return;
 
 	early_iounmap(adr, PAGE_SIZE);
@@ -360,7 +367,7 @@ phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end,
 	for(i = pte_index(addr); i < PTRS_PER_PTE; i++, addr += PAGE_SIZE, pte++) {
 
 		if (addr >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for(; i < PTRS_PER_PTE; i++, pte++)
 					set_pte(pte, __pte(0));
 			}
@@ -416,7 +423,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
 		pgprot_t new_prot = prot;
 
 		if (address >= end) {
-			if (!after_bootmem) {
+			if (bootmem_state != AFTER_BOOTMEM) {
 				for (; i < PTRS_PER_PMD; i++, pmd++)
 					set_pmd(pmd, __pmd(0));
 			}
@@ -502,7 +509,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
 		if (addr >= end)
 			break;
 
-		if (!after_bootmem &&
+		if (bootmem_state != AFTER_BOOTMEM &&
 				!e820_any_mapped(addr, addr+PUD_SIZE, 0)) {
 			set_pud(pud, __pud(0));
 			continue;
@@ -693,8 +700,6 @@ void __init mem_init(void)
 
 	/* clear_bss() already clear the empty_zero_page */
 
-	reservedpages = 0;
-
 	/* this will put all low memory onto the freelists */
 #ifdef CONFIG_NUMA
 	totalram_pages = numa_free_all_bootmem();
@@ -702,9 +707,9 @@ void __init mem_init(void)
 	totalram_pages = free_all_bootmem();
 #endif
 
+	bootmem_state = AFTER_BOOTMEM;
 	absent_pages = absent_pages_in_range(0, max_pfn);
 	reservedpages = max_pfn - totalram_pages - absent_pages;
-	after_bootmem = 1;
 
 	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;

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

* Re: [tip:kmemcheck] x86: introduce bootmem_state
  2009-03-08 18:54                       ` [tip:kmemcheck] x86: introduce bootmem_state Yinghai Lu
@ 2009-03-08 18:58                         ` Ingo Molnar
  2009-03-08 19:30                           ` Yinghai Lu
  0 siblings, 1 reply; 27+ messages in thread
From: Ingo Molnar @ 2009-03-08 18:58 UTC (permalink / raw)
  To: mingo, hpa, linux-kernel, yinghai, penberg, akpm, tglx, Vegard Nossum
  Cc: linux-tip-commits


* Yinghai Lu <yinghai@kernel.org> wrote:

> Commit-ID:  4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
> Gitweb:     http://git.kernel.org/tip/4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
> Author:     "Yinghai Lu" <yinghai@kernel.org>
> AuthorDate: Fri, 6 Mar 2009 16:49:00 -0800
> Commit:     Ingo Molnar <mingo@elte.hu>
> CommitDate: Sun, 8 Mar 2009 19:43:09 +0100
> 
> x86: introduce bootmem_state
> 
> Impact: cleanup

Note, this cleanup ended up in the tip:kmemcheck branch because 
it modifies the same code so there's dependencies.

	Ingo

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

* Re: [tip:kmemcheck] x86: introduce bootmem_state
  2009-03-08 18:58                         ` Ingo Molnar
@ 2009-03-08 19:30                           ` Yinghai Lu
  2009-03-08 20:32                             ` Ingo Molnar
  0 siblings, 1 reply; 27+ messages in thread
From: Yinghai Lu @ 2009-03-08 19:30 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: mingo, hpa, linux-kernel, penberg, akpm, tglx, Vegard Nossum,
	linux-tip-commits

On Sun, Mar 8, 2009 at 11:58 AM, Ingo Molnar <mingo@elte.hu> wrote:
>
> * Yinghai Lu <yinghai@kernel.org> wrote:
>
>> Commit-ID:  4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
>> Gitweb:     http://git.kernel.org/tip/4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
>> Author:     "Yinghai Lu" <yinghai@kernel.org>
>> AuthorDate: Fri, 6 Mar 2009 16:49:00 -0800
>> Commit:     Ingo Molnar <mingo@elte.hu>
>> CommitDate: Sun, 8 Mar 2009 19:43:09 +0100
>>
>> x86: introduce bootmem_state
>>
>> Impact: cleanup
>
> Note, this cleanup ended up in the tip:kmemcheck branch because
> it modifies the same code so there's dependencies.

not sure. it seems it should be with tip/x86/mm

YH

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

* Re: [tip:kmemcheck] x86: introduce bootmem_state
  2009-03-08 19:30                           ` Yinghai Lu
@ 2009-03-08 20:32                             ` Ingo Molnar
  0 siblings, 0 replies; 27+ messages in thread
From: Ingo Molnar @ 2009-03-08 20:32 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: mingo, hpa, linux-kernel, penberg, akpm, tglx, Vegard Nossum,
	linux-tip-commits


* Yinghai Lu <yinghai@kernel.org> wrote:

> On Sun, Mar 8, 2009 at 11:58 AM, Ingo Molnar <mingo@elte.hu> wrote:
> >
> > * Yinghai Lu <yinghai@kernel.org> wrote:
> >
> >> Commit-ID:  4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
> >> Gitweb:     http://git.kernel.org/tip/4c76c04421dfe7be3e5a1d8ab1b2a3be0b02558e
> >> Author:     "Yinghai Lu" <yinghai@kernel.org>
> >> AuthorDate: Fri, 6 Mar 2009 16:49:00 -0800
> >> Commit:     Ingo Molnar <mingo@elte.hu>
> >> CommitDate: Sun, 8 Mar 2009 19:43:09 +0100
> >>
> >> x86: introduce bootmem_state
> >>
> >> Impact: cleanup
> >
> > Note, this cleanup ended up in the tip:kmemcheck branch because
> > it modifies the same code so there's dependencies.
> 
> not sure. it seems it should be with tip/x86/mm

kmemcheck has the latest changes to that area and it has x86/mm 
merged too.

	Ingo

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

end of thread, other threads:[~2009-03-08 20:33 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-05 12:54 [PATCH 07/17] x86: rename after_init_bootmem to after_bootmem in mm/init_32.c Pekka Enberg
2009-03-05 13:37 ` [tip:x86/mm] " Pekka Enberg
2009-03-05 19:14 ` [PATCH 07/17] " Yinghai Lu
     [not found]   ` <49B02C68.1030203@cs.helsinki.fi>
2009-03-05 23:45     ` [PATCH] x86: introduce bootmem_state Yinghai Lu
2009-03-06  6:14       ` H. Peter Anvin
2009-03-06  6:38         ` Yinghai Lu
2009-03-06 22:12         ` Jeremy Fitzhardinge
2009-03-06 23:34           ` H. Peter Anvin
2009-03-07  0:01             ` Andrew Morton
2009-03-07  0:10             ` Jeremy Fitzhardinge
2009-03-07  0:11               ` H. Peter Anvin
2009-03-06 14:59       ` Ingo Molnar
2009-03-06 18:20         ` Yinghai Lu
2009-03-06 18:38         ` [PATCH] x86: introduce bootmem_state -v2 Yinghai Lu
2009-03-06 19:12           ` Ingo Molnar
2009-03-06 19:30             ` Andrew Morton
2009-03-06 19:36               ` Ingo Molnar
2009-03-06 22:06                 ` Jeremy Fitzhardinge
2009-03-06 19:50             ` Yinghai Lu
2009-03-06 20:15               ` Ingo Molnar
2009-03-06 20:40                 ` Yinghai Lu
2009-03-06 21:35                   ` Ingo Molnar
2009-03-07  0:49                     ` [PATCH] x86: introduce bootmem_state -v3 Yinghai Lu
2009-03-08 18:54                       ` [tip:kmemcheck] x86: introduce bootmem_state Yinghai Lu
2009-03-08 18:58                         ` Ingo Molnar
2009-03-08 19:30                           ` Yinghai Lu
2009-03-08 20:32                             ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.