From: Yinghai Lu <yinghai@kernel.org>
To: Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] x86: introduce bootmem_state -v3
Date: Fri, 06 Mar 2009 16:49:00 -0800 [thread overview]
Message-ID: <49B1C47C.5080401@kernel.org> (raw)
In-Reply-To: <20090306213523.GB3306@elte.hu>
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);
next prev parent reply other threads:[~2009-03-07 0:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Yinghai Lu [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49B1C47C.5080401@kernel.org \
--to=yinghai@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@cs.helsinki.fi \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.