linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [2/7] 060 refactor setup_memory i386
@ 2004-10-28 14:26 Andy Whitcroft
  2004-10-28 15:51 ` [Lhms-devel] " Dave Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Whitcroft @ 2004-10-28 14:26 UTC (permalink / raw)
  To: haveblue, lhms-devel; +Cc: linux-mm, apw

Refactor the i386 default and CONFIG_DISCONTIG_MEM setup_memory()
functions to share the common bootmem initialisation code.  This code
is intended to be identical, but there are currently some fixes
applied to one and not the other.  This patch extracts this common
initialisation code.

Revision: $Rev$

Signed-off-by: Andy Whitcroft <apw@shadowen.org>

diffstat 060-refactor-setup_memory-i386
---
 kernel/setup.c |   25 ++++++------
 mm/discontig.c |  117 +--------------------------------------------------------
 2 files changed, 18 insertions(+), 124 deletions(-)

diff -upN reference/arch/i386/kernel/setup.c current/arch/i386/kernel/setup.c
--- reference/arch/i386/kernel/setup.c
+++ current/arch/i386/kernel/setup.c
@@ -941,8 +941,6 @@ unsigned long __init find_max_low_pfn(vo
 	return max_low_pfn;
 }
 
-#ifndef CONFIG_DISCONTIGMEM
-
 /*
  * Free all available memory for boot time allocation.  Used
  * as a callback function by efi_memory_walk()
@@ -1016,15 +1014,15 @@ static void __init reserve_ebda_region(v
 		reserve_bootmem(addr, PAGE_SIZE);	
 }
 
+#ifndef CONFIG_DISCONTIGMEM
+void __init setup_bootmem_allocator(void);
 static unsigned long __init setup_memory(void)
 {
-	unsigned long bootmap_size, start_pfn, max_low_pfn;
-
 	/*
 	 * partially used pages are not usable - thus
 	 * we are rounding upwards:
 	 */
-	start_pfn = PFN_UP(init_pg_tables_end);
+	min_low_pfn = PFN_UP(init_pg_tables_end);
 
 	find_max_pfn();
 
@@ -1040,10 +1038,19 @@ static unsigned long __init setup_memory
 #endif
 	printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
 			pages_to_mb(max_low_pfn));
+
+	setup_bootmem_allocator();
+	return max_low_pfn;
+}
+#endif /* !CONFIG_DISCONTIGMEM */
+
+void __init setup_bootmem_allocator(void)
+{
+	unsigned long bootmap_size;
 	/*
 	 * Initialize the boot-time allocator (with low memory only):
 	 */
-	bootmap_size = init_bootmem(start_pfn, max_low_pfn);
+	bootmap_size = init_bootmem(min_low_pfn, max_low_pfn);
 
 	register_bootmem_low_pages(max_low_pfn);
 
@@ -1053,7 +1060,7 @@ static unsigned long __init setup_memory
 	 * the (very unlikely) case of us accidentally initializing the
 	 * bootmem allocator with an invalid RAM area.
 	 */
-	reserve_bootmem(HIGH_MEMORY, (PFN_PHYS(start_pfn) +
+	reserve_bootmem(HIGH_MEMORY, (PFN_PHYS(min_low_pfn) +
 			 bootmap_size + PAGE_SIZE-1) - (HIGH_MEMORY));
 
 	/*
@@ -1110,11 +1117,7 @@ static unsigned long __init setup_memory
 		}
 	}
 #endif
-	return max_low_pfn;
 }
-#else
-extern unsigned long setup_memory(void);
-#endif /* !CONFIG_DISCONTIGMEM */
 
 /*
  * Request address space for all standard RAM and ROM resources
diff -upN reference/arch/i386/mm/discontig.c current/arch/i386/mm/discontig.c
--- reference/arch/i386/mm/discontig.c
+++ current/arch/i386/mm/discontig.c
@@ -136,46 +136,6 @@ static void __init allocate_pgdat(int ni
 	}
 }
 
-/*
- * Register fully available low RAM pages with the bootmem allocator.
- */
-static void __init register_bootmem_low_pages(unsigned long system_max_low_pfn)
-{
-	int i;
-
-	for (i = 0; i < e820.nr_map; i++) {
-		unsigned long curr_pfn, last_pfn, size;
-		/*
-		 * Reserve usable low memory
-		 */
-		if (e820.map[i].type != E820_RAM)
-			continue;
-		/*
-		 * We are rounding up the start address of usable memory:
-		 */
-		curr_pfn = PFN_UP(e820.map[i].addr);
-		if (curr_pfn >= system_max_low_pfn)
-			continue;
-		/*
-		 * ... and at the end of the usable range downwards:
-		 */
-		last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
-
-		if (last_pfn > system_max_low_pfn)
-			last_pfn = system_max_low_pfn;
-
-		/*
-		 * .. finally, did all the rounding and playing
-		 * around just make the area go away?
-		 */
-		if (last_pfn <= curr_pfn)
-			continue;
-
-		size = last_pfn - curr_pfn;
-		free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn), PFN_PHYS(size));
-	}
-}
-
 void __init remap_numa_kva(void)
 {
 	void *vaddr;
@@ -220,21 +180,11 @@ static unsigned long calculate_numa_rema
 	return reserve_pages;
 }
 
-/*
- * workaround for Dell systems that neglect to reserve EBDA
- */
-static void __init reserve_ebda_region_node(void)
-{
-	unsigned int addr;
-	addr = get_bios_ebda();
-	if (addr)
-		reserve_bootmem_node(NODE_DATA(0), addr, PAGE_SIZE);
-}
-
+extern void setup_bootmem_allocator(void);
 unsigned long __init setup_memory(void)
 {
 	int nid;
-	unsigned long bootmap_size, system_start_pfn, system_max_low_pfn;
+	unsigned long system_start_pfn, system_max_low_pfn;
 	unsigned long reserve_pages, pfn;
 
 	/*
@@ -301,68 +251,9 @@ unsigned long __init setup_memory(void)
 
 	NODE_DATA(0)->bdata = &node0_bdata;
 
-	/*
-	 * Initialize the boot-time allocator (with low memory only):
-	 */
-	bootmap_size = init_bootmem_node(NODE_DATA(0), min_low_pfn, 0, system_max_low_pfn);
+	setup_bootmem_allocator();
 
-	register_bootmem_low_pages(system_max_low_pfn);
-
-	/*
-	 * Reserve the bootmem bitmap itself as well. We do this in two
-	 * steps (first step was init_bootmem()) because this catches
-	 * the (very unlikely) case of us accidentally initializing the
-	 * bootmem allocator with an invalid RAM area.
-	 */
-	reserve_bootmem_node(NODE_DATA(0), HIGH_MEMORY, (PFN_PHYS(min_low_pfn) +
-		 bootmap_size + PAGE_SIZE-1) - (HIGH_MEMORY));
-
-	/*
-	 * reserve physical page 0 - it's a special BIOS page on many boxes,
-	 * enabling clean reboots, SMP operation, laptop functions.
-	 */
-	reserve_bootmem_node(NODE_DATA(0), 0, PAGE_SIZE);
-
-	/*
-	 * But first pinch a few for the stack/trampoline stuff
-	 * FIXME: Don't need the extra page at 4K, but need to fix
-	 * trampoline before removing it. (see the GDT stuff)
-	 */
-	reserve_bootmem_node(NODE_DATA(0), PAGE_SIZE, PAGE_SIZE);
-
-	/* reserve EBDA region, it's a 4K region */
-	reserve_ebda_region_node();
-
-#ifdef CONFIG_ACPI_SLEEP
-	/*
-	 * Reserve low memory region for sleep support.
-	 */
-	acpi_reserve_bootmem();
-#endif
-
-	/*
-	 * Find and reserve possible boot-time SMP configuration:
-	 */
-	find_smp_config();
-
-#ifdef CONFIG_BLK_DEV_INITRD
-	if (LOADER_TYPE && INITRD_START) {
-		if (INITRD_START + INITRD_SIZE <= (system_max_low_pfn << PAGE_SHIFT)) {
-			reserve_bootmem_node(NODE_DATA(0), INITRD_START, INITRD_SIZE);
-			initrd_start =
-				INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
-			initrd_end = initrd_start+INITRD_SIZE;
-		}
-		else {
-			printk(KERN_ERR "initrd extends beyond end of memory "
-			    "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
-			    INITRD_START + INITRD_SIZE,
-			    system_max_low_pfn << PAGE_SHIFT);
-			initrd_start = 0;
-		}
-	}
-#endif
-	return system_max_low_pfn;
+	return max_low_pfn;
 }
 
 void __init zone_sizes_init(void)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

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

* Re: [Lhms-devel] [2/7] 060 refactor setup_memory i386
  2004-10-28 14:26 [2/7] 060 refactor setup_memory i386 Andy Whitcroft
@ 2004-10-28 15:51 ` Dave Hansen
  2004-10-28 15:55   ` Andy Whitcroft
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2004-10-28 15:51 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: lhms-devel, linux-mm

Andy Whitcroft wrote:
> +#ifndef CONFIG_DISCONTIGMEM
> +void __init setup_bootmem_allocator(void);
>  static unsigned long __init setup_memory(void)
>  {
...
> +#endif /* !CONFIG_DISCONTIGMEM */
> +
> +void __init setup_bootmem_allocator(void)
> +{

Won't this double define setup_bootmem_allocator() when 
CONFIG_DISCONTIGMEM is disabled?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

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

* Re: [Lhms-devel] [2/7] 060 refactor setup_memory i386
  2004-10-28 15:51 ` [Lhms-devel] " Dave Hansen
@ 2004-10-28 15:55   ` Andy Whitcroft
  2004-10-28 16:48     ` Dave Hansen
  2004-10-28 17:57     ` Dave Hansen
  0 siblings, 2 replies; 5+ messages in thread
From: Andy Whitcroft @ 2004-10-28 15:55 UTC (permalink / raw)
  To: Dave Hansen; +Cc: lhms-devel, linux-mm

Dave Hansen wrote:
> Andy Whitcroft wrote:
> 
>> +#ifndef CONFIG_DISCONTIGMEM
>> +void __init setup_bootmem_allocator(void);
>>  static unsigned long __init setup_memory(void)
>>  {
> 
> ...
> 
>> +#endif /* !CONFIG_DISCONTIGMEM */
>> +
>> +void __init setup_bootmem_allocator(void)
>> +{
> 
> 
> Won't this double define setup_bootmem_allocator() when 
> CONFIG_DISCONTIGMEM is disabled?

That is a pre-declaration.  There is only one copy of 
setup_bootmem_allocator() which is either used 'here' in the flatmem 
case, or from discontig.c in the DISCONTIGMEM case.  The order is 
backwards to minimise the overall diff; so I needed to declare it.

-apw
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

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

* Re: [Lhms-devel] [2/7] 060 refactor setup_memory i386
  2004-10-28 15:55   ` Andy Whitcroft
@ 2004-10-28 16:48     ` Dave Hansen
  2004-10-28 17:57     ` Dave Hansen
  1 sibling, 0 replies; 5+ messages in thread
From: Dave Hansen @ 2004-10-28 16:48 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: lhms-devel, linux-mm

Andy Whitcroft wrote:
> That is a pre-declaration.  There is only one copy of 
> setup_bootmem_allocator() which is either used 'here' in the flatmem 
> case, or from discontig.c in the DISCONTIGMEM case.  The order is 
> backwards to minimise the overall diff; so I needed to declare it.

Ahhh, I just parsed that wrong.  Silly me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org"> aart@kvack.org </a>

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

* Re: [Lhms-devel] [2/7] 060 refactor setup_memory i386
  2004-10-28 15:55   ` Andy Whitcroft
  2004-10-28 16:48     ` Dave Hansen
@ 2004-10-28 17:57     ` Dave Hansen
  1 sibling, 0 replies; 5+ messages in thread
From: Dave Hansen @ 2004-10-28 17:57 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: lhms-devel, linux-mm

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

There's no reason not to just move setup_bootmem_allocator() above the
first call to it, except for code churn.  This saves a predeclaration.

[-- Attachment #2: 2_7_060_refactor_setup_memory_i386-cleanup.patch --]
[-- Type: text/plain, Size: 2242 bytes --]



---

 sparsemem-dave/arch/i386/kernel/setup.c |   59 +++++++++++++++-----------------
 1 files changed, 29 insertions(+), 30 deletions(-)

diff -puN arch/i386/kernel/setup.c~2_7_060_refactor_setup_memory_i386-cleanup arch/i386/kernel/setup.c
--- sparsemem/arch/i386/kernel/setup.c~2_7_060_refactor_setup_memory_i386-cleanup	2004-10-28 10:23:29.000000000 -0700
+++ sparsemem-dave/arch/i386/kernel/setup.c	2004-10-28 10:24:27.000000000 -0700
@@ -1014,36 +1014,6 @@ static void __init reserve_ebda_region(v
 		reserve_bootmem(addr, PAGE_SIZE);	
 }
 
-#ifndef CONFIG_DISCONTIGMEM
-void __init setup_bootmem_allocator(void);
-static unsigned long __init setup_memory(void)
-{
-	/*
-	 * partially used pages are not usable - thus
-	 * we are rounding upwards:
-	 */
-	min_low_pfn = PFN_UP(init_pg_tables_end);
-
-	find_max_pfn();
-
-	max_low_pfn = find_max_low_pfn();
-
-#ifdef CONFIG_HIGHMEM
-	highstart_pfn = highend_pfn = max_pfn;
-	if (max_pfn > max_low_pfn) {
-		highstart_pfn = max_low_pfn;
-	}
-	printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
-		pages_to_mb(highend_pfn - highstart_pfn));
-#endif
-	printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
-			pages_to_mb(max_low_pfn));
-
-	setup_bootmem_allocator();
-	return max_low_pfn;
-}
-#endif /* !CONFIG_DISCONTIGMEM */
-
 void __init setup_bootmem_allocator(void)
 {
 	unsigned long bootmap_size;
@@ -1119,6 +1089,35 @@ void __init setup_bootmem_allocator(void
 #endif
 }
 
+#ifndef CONFIG_DISCONTIGMEM
+static unsigned long __init setup_memory(void)
+{
+	/*
+	 * partially used pages are not usable - thus
+	 * we are rounding upwards:
+	 */
+	min_low_pfn = PFN_UP(init_pg_tables_end);
+
+	find_max_pfn();
+
+	max_low_pfn = find_max_low_pfn();
+
+#ifdef CONFIG_HIGHMEM
+	highstart_pfn = highend_pfn = max_pfn;
+	if (max_pfn > max_low_pfn) {
+		highstart_pfn = max_low_pfn;
+	}
+	printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
+		pages_to_mb(highend_pfn - highstart_pfn));
+#endif
+	printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
+			pages_to_mb(max_low_pfn));
+
+	setup_bootmem_allocator();
+	return max_low_pfn;
+}
+#endif /* !CONFIG_DISCONTIGMEM */
+
 /*
  * Request address space for all standard RAM and ROM resources
  * and also for regions reported as reserved by the e820.
_

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

end of thread, other threads:[~2004-10-28 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28 14:26 [2/7] 060 refactor setup_memory i386 Andy Whitcroft
2004-10-28 15:51 ` [Lhms-devel] " Dave Hansen
2004-10-28 15:55   ` Andy Whitcroft
2004-10-28 16:48     ` Dave Hansen
2004-10-28 17:57     ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox