LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] x86: trim mtrr don't close gap for resource allocation
@ 2008-03-17  0:38 Yinghai Lu
  2008-03-17 16:35 ` Jesse Barnes
  0 siblings, 1 reply; 4+ messages in thread
From: Yinghai Lu @ 2008-03-17  0:38 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar, H. Peter Anvin, steve, Jesse Barnes,
	Andi Kleen
  Cc: Linux Kernel ML

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



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: update_memory_region.patch --]
[-- Type: text/x-patch; name=update_memory_region.patch, Size: 4067 bytes --]

[PATCH] x86: trim mtrr don't close gap for resource allocation.

for
	http://bugzilla.kernel.org/show_bug.cgi?id=10232

use update_memory_range instead of add_memory_range directly
to avoid closing that gap.

Signed-off-by: Yinghai Lu <yhlu.kenrel@gmail.com>

Index: linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/main.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
@@ -711,7 +711,8 @@ int __init mtrr_trim_uncached_memory(uns
 		trim_size = end_pfn;
 		trim_size <<= PAGE_SHIFT;
 		trim_size -= trim_start;
-		add_memory_region(trim_start, trim_size, E820_RESERVED);
+		update_memory_range(trim_start, trim_size, E820_RAM,
+					E820_RESERVED);
 		update_e820();
 		return 1;
 	}
Index: linux-2.6/arch/x86/kernel/e820_32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820_32.c
+++ linux-2.6/arch/x86/kernel/e820_32.c
@@ -736,6 +736,32 @@ static int __init parse_memmap(char *arg
 	return 0;
 }
 early_param("memmap", parse_memmap);
+void __init update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type)
+{
+	int i;
+
+	BUG_ON(old_type == new_type);
+
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		u64 final_start, final_end;
+		if (ei->type != old_type)
+			continue;
+		/* totally covered? */
+		if (ei->addr >= start && ei->size <= size) {
+			ei->type = new_type;
+			continue;
+		}
+		/* partially covered */
+		final_start = max(start, ei->addr);
+		final_end = min(start + size, ei->addr + ei->size);
+		if (final_start >= final_end)
+			continue;
+		add_memory_region(final_start, final_end - final_start,
+					 new_type);
+	}
+}
 void __init update_e820(void)
 {
 	u8 nr_map;
Index: linux-2.6/arch/x86/kernel/e820_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820_64.c
+++ linux-2.6/arch/x86/kernel/e820_64.c
@@ -731,6 +731,33 @@ void __init finish_e820_parsing(void)
 	}
 }
 
+void __init update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type)
+{
+	int i;
+
+	BUG_ON(old_type == new_type);
+
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		u64 final_start, final_end;
+		if (ei->type != old_type)
+			continue;
+		/* totally covered? */
+		if (ei->addr >= start && ei->size <= size) {
+			ei->type = new_type;
+			continue;
+		}
+		/* partially covered */
+		final_start = max(start, ei->addr);
+		final_end = min(start + size, ei->addr + ei->size);
+		if (final_start >= final_end)
+			continue;
+		add_memory_region(final_start, final_end - final_start,
+					 new_type);
+	}
+}
+
 void __init update_e820(void)
 {
 	u8 nr_map;
Index: linux-2.6/include/asm-x86/e820_32.h
===================================================================
--- linux-2.6.orig/include/asm-x86/e820_32.h
+++ linux-2.6/include/asm-x86/e820_32.h
@@ -28,6 +28,8 @@ extern void find_max_pfn(void);
 extern void register_bootmem_low_pages(unsigned long max_low_pfn);
 extern void add_memory_region(unsigned long long start,
 			      unsigned long long size, int type);
+extern void update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type);
 extern void e820_register_memory(void);
 extern void limit_regions(unsigned long long size);
 extern void print_memory_map(char *who);
Index: linux-2.6/include/asm-x86/e820_64.h
===================================================================
--- linux-2.6.orig/include/asm-x86/e820_64.h
+++ linux-2.6/include/asm-x86/e820_64.h
@@ -18,6 +18,8 @@ extern unsigned long find_e820_area(unsi
 				    unsigned long size, unsigned long align);
 extern void add_memory_region(unsigned long start, unsigned long size, 
 			      int type);
+extern void update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type);
 extern void setup_memory_region(void);
 extern void contig_e820_setup(void); 
 extern unsigned long e820_end_of_ram(void);

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

* Re: [PATCH] x86: trim mtrr don't close gap for resource allocation
  2008-03-17  0:38 [PATCH] x86: trim mtrr don't close gap for resource allocation Yinghai Lu
@ 2008-03-17 16:35 ` Jesse Barnes
  0 siblings, 0 replies; 4+ messages in thread
From: Jesse Barnes @ 2008-03-17 16:35 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Andrew Morton, Ingo Molnar, H. Peter Anvin, steve, Andi Kleen,
	Linux Kernel ML

The new function could probably use some higher level comments (though the 
rest of the e820 routines seem similarly devoid of description so it's not a 
big deal).  And given that this patch fixes a regression, it should probably 
get upstream quickly.

Thanks for fixing this so quickly, Yinghai.

Acked-by:  Jesse Barnes <jesse.barnes@intel.com>

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

* Re: [PATCH] x86: trim mtrr don't close gap for resource allocation.
  2008-03-18 23:44   ` Yinghai Lu
@ 2008-03-21 10:44     ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2008-03-21 10:44 UTC (permalink / raw)
  To: yhlu.kernel
  Cc: Andrew Morton, H. Peter Anvin, steve, Jesse Barnes, kernel list


* Yinghai Lu <yhlu.kernel.send@gmail.com> wrote:

> [PATCH] x86: trim mtrr don't close gap for resource allocation.
> 
> for
> 	http://bugzilla.kernel.org/show_bug.cgi?id=10232
> 
> use update_memory_range instead of add_memory_range directly to avoid 
> closing that gap.

thanks Yinghai, applied, and queued up for 2.6.25.

	Ingo

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

* [PATCH] x86: trim mtrr don't close gap for resource allocation.
       [not found] ` <200803181255.10402.yhlu.kernel@gmail.com>
@ 2008-03-18 23:44   ` Yinghai Lu
  2008-03-21 10:44     ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Yinghai Lu @ 2008-03-18 23:44 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar, H. Peter Anvin
  Cc: steve, Jesse Barnes, kernel list

[PATCH] x86: trim mtrr don't close gap for resource allocation.

for
	http://bugzilla.kernel.org/show_bug.cgi?id=10232

use update_memory_range instead of add_memory_range directly
to avoid closing that gap.

Signed-off-by: Yinghai Lu <yhlu.kenrel@gmail.com>

Index: linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/main.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/main.c
@@ -711,7 +711,8 @@ int __init mtrr_trim_uncached_memory(uns
 		trim_size = end_pfn;
 		trim_size <<= PAGE_SHIFT;
 		trim_size -= trim_start;
-		add_memory_region(trim_start, trim_size, E820_RESERVED);
+		update_memory_range(trim_start, trim_size, E820_RAM,
+					E820_RESERVED);
 		update_e820();
 		return 1;
 	}
Index: linux-2.6/arch/x86/kernel/e820_32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820_32.c
+++ linux-2.6/arch/x86/kernel/e820_32.c
@@ -749,6 +749,32 @@ static int __init parse_memmap(char *arg
 	return 0;
 }
 early_param("memmap", parse_memmap);
+void __init update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type)
+{
+	int i;
+
+	BUG_ON(old_type == new_type);
+
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		u64 final_start, final_end;
+		if (ei->type != old_type)
+			continue;
+		/* totally covered? */
+		if (ei->addr >= start && ei->size <= size) {
+			ei->type = new_type;
+			continue;
+		}
+		/* partially covered */
+		final_start = max(start, ei->addr);
+		final_end = min(start + size, ei->addr + ei->size);
+		if (final_start >= final_end)
+			continue;
+		add_memory_region(final_start, final_end - final_start,
+					 new_type);
+	}
+}
 void __init update_e820(void)
 {
 	u8 nr_map;
Index: linux-2.6/arch/x86/kernel/e820_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820_64.c
+++ linux-2.6/arch/x86/kernel/e820_64.c
@@ -735,6 +735,33 @@ void __init finish_e820_parsing(void)
 	}
 }
 
+void __init update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type)
+{
+	int i;
+
+	BUG_ON(old_type == new_type);
+
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		u64 final_start, final_end;
+		if (ei->type != old_type)
+			continue;
+		/* totally covered? */
+		if (ei->addr >= start && ei->size <= size) {
+			ei->type = new_type;
+			continue;
+		}
+		/* partially covered */
+		final_start = max(start, ei->addr);
+		final_end = min(start + size, ei->addr + ei->size);
+		if (final_start >= final_end)
+			continue;
+		add_memory_region(final_start, final_end - final_start,
+					 new_type);
+	}
+}
+
 void __init update_e820(void)
 {
 	u8 nr_map;
Index: linux-2.6/include/asm-x86/e820_32.h
===================================================================
--- linux-2.6.orig/include/asm-x86/e820_32.h
+++ linux-2.6/include/asm-x86/e820_32.h
@@ -28,6 +28,8 @@ extern void find_max_pfn(void);
 extern void register_bootmem_low_pages(unsigned long max_low_pfn);
 extern void add_memory_region(unsigned long long start,
 			      unsigned long long size, int type);
+extern void update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type);
 extern void e820_register_memory(void);
 extern void limit_regions(unsigned long long size);
 extern void print_memory_map(char *who);
Index: linux-2.6/include/asm-x86/e820_64.h
===================================================================
--- linux-2.6.orig/include/asm-x86/e820_64.h
+++ linux-2.6/include/asm-x86/e820_64.h
@@ -18,6 +18,8 @@ extern unsigned long find_e820_area(unsi
 				    unsigned long size, unsigned long align);
 extern void add_memory_region(unsigned long start, unsigned long size, 
 			      int type);
+extern void update_memory_range(u64 start, u64 size, unsigned old_type,
+				unsigned new_type);
 extern void setup_memory_region(void);
 extern void contig_e820_setup(void); 
 extern unsigned long e820_end_of_ram(void);

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

end of thread, other threads:[~2008-03-21 10:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-17  0:38 [PATCH] x86: trim mtrr don't close gap for resource allocation Yinghai Lu
2008-03-17 16:35 ` Jesse Barnes
     [not found] <200803181237.33861.yhlu.kernel@gmail.com>
     [not found] ` <200803181255.10402.yhlu.kernel@gmail.com>
2008-03-18 23:44   ` Yinghai Lu
2008-03-21 10:44     ` Ingo Molnar

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