[ipxe-devel] [PATCH] Merge adjacent memory regions of same type

Eduardo Habkost ehabkost at redhat.com
Wed Feb 16 18:41:24 UTC 2011


Hi, I have submitted this patch to gpxe recently[1], but I guess you'll want to
pull it into ipxe too.

[1] http://article.gmane.org/gmane.network.etherboot.gpxe/1539


Original submission description below:

-----------------------
Date: Fri, 7 Jan 2011 16:19:50 -0200
From: Eduardo Habkost <ehabkost at redhat.com>
Subject: [PATCH RESUBMIT] Merge adjacent memory regions of same type

Hi,

I have noticed that the original submission of this patch had issues
(diff was corrupted), so I am resubmitting it to make sure a good
version of the patch is queued for inclusion.

Original submission:
http://article.gmane.org/gmane.network.etherboot.gpxe/1362
Test report:
http://article.gmane.org/gmane.network.etherboot.gpxe/1502

Original patch description:

    From: Casey Dahlin <cdahlin at redhat.com>

    Some BIOSes can report multiple memory regions which may be adjacent
    and the same type. Since only the first region is used in the
    mboot.c32 layer it's possible to run out of memory when loading all
    of the boot modules. One may get around this problem by having gPXE
    merge these memory regions internally.
---
 src/arch/i386/firmware/pcbios/memmap.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/arch/i386/firmware/pcbios/memmap.c b/src/arch/i386/firmware/pcbios/memmap.c
index 01080c7..02fb3ce 100644
--- a/src/arch/i386/firmware/pcbios/memmap.c
+++ b/src/arch/i386/firmware/pcbios/memmap.c
@@ -156,6 +156,7 @@ unsigned int extmemsize ( void ) {
  */
 static int meme820 ( struct memory_map *memmap ) {
 	struct memory_region *region = memmap->regions;
+	struct memory_region *prev_region = NULL;
 	uint32_t next = 0;
 	uint32_t smap;
 	size_t size;
@@ -238,8 +239,15 @@ static int meme820 ( struct memory_map *memmap ) {
 
 		region->start = e820buf.start;
 		region->end = e820buf.start + e820buf.len;
-		region++;
-		memmap->count++;
+
+		/* Check for adjacent regions and merge them. */
+		if (prev_region && region->start == prev_region->end) {
+			prev_region->end = region->end;
+		} else {
+			prev_region = region;
+			region++;
+			memmap->count++;
+		}
 
 		if ( memmap->count >= ( sizeof ( memmap->regions ) /
 					sizeof ( memmap->regions[0] ) ) ) {
-- 
1.7.3.2




More information about the ipxe-devel mailing list