[gPXE] [PATCH] Merge adjacent memory regions of same type
Casey Dahlin
cdahlin at redhat.com
Tue Oct 12 16:36:35 EDT 2010
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.
--- a/src/arch/i386/firmware/pcbios/memmap.c
+++ b/src/arch/i386/firmware/pcbios/memmap.c
@@ -154,6 +154,7 @@
*/
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;
@@ -236,9 +237,16 @@
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] ) ) ) {
DBG ( "INT 15,e820 too many regions returnedn" );
More information about the gPXE
mailing list