When running out of memory in ZoneHigh go alloc memory from ZoneTmpHigh,
add it as reserved to the e820 map and expand ZoneHigh
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
src/malloc.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/malloc.c b/src/malloc.c
index 3733855caf2c..02067b5370f9 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -226,6 +226,20 @@ zonelow_expand(u32 size, u32 align, struct allocinfo_s *fill)
return alloc_new(&ZoneLow, size, align, fill);
}
+static u32
+zonehigh_expand(u32 size, u32 align, struct allocinfo_s *fill)
+{
+ u32 xsize = ALIGN(size, BUILD_MAX_HIGHTABLE);
+ u32 xalign = align > PAGE_SIZE ? align : PAGE_SIZE;
+ u32 xdata = malloc_palloc(&ZoneTmpHigh, xsize, xalign);
+ if (!xdata)
+ return 0;
+
+ alloc_add(&ZoneHigh, xdata, xdata + xsize);
+ e820_add(xdata, size, E820_RESERVED);
+ return alloc_new(&ZoneHigh, size, align, fill);
+}
+
/****************************************************************
* tracked memory allocations
@@ -245,6 +259,8 @@ malloc_palloc(struct zone_s *zone, u32 size, u32 align)
u32 data = alloc_new(zone, size, align, &tempdetail.datainfo);
if (!CONFIG_MALLOC_UPPERMEMORY && !data && zone == &ZoneLow)
data = zonelow_expand(size, align, &tempdetail.datainfo);
+ if (!data && zone == &ZoneHigh)
+ data = zonehigh_expand(size, align, &tempdetail.datainfo);
if (!data)
return 0;
--
2.35.1
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org