Blame SOURCES/seabios-malloc-use-large-ZoneHigh-when-there-is-enough-memor.patch

14aa00
From f8c75c66a29fae7ff1e3bf23f382cd8f04e695a1 Mon Sep 17 00:00:00 2001
14aa00
From: Gerd Hoffmann <kraxel@redhat.com>
14aa00
Date: Mon, 25 Apr 2022 09:25:31 +0200
14aa00
Subject: [PATCH 2/2] malloc: use large ZoneHigh when there is enough memory
14aa00
14aa00
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
14aa00
RH-MergeRequest: 3: malloc: use large ZoneHigh when there is enough memory
14aa00
RH-Commit: [2/2] 93b15659b39b9772c7620ddfbf558e11008bb8f9 (kraxel/centos-seabios)
14aa00
RH-Bugzilla: 2004662
14aa00
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
14aa00
RH-Acked-by: Oliver Steffen <osteffen@redhat.com>
14aa00
14aa00
In case there is enough memory installed use a large ZoneHigh.
14aa00
14aa00
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
14aa00
(cherry picked from commit dc88f9b72df52b22c35b127b80c487e0b6fca4af)
14aa00
---
14aa00
 src/config.h |  3 ++-
14aa00
 src/malloc.c | 14 +++++++++-----
14aa00
 2 files changed, 11 insertions(+), 6 deletions(-)
14aa00
14aa00
diff --git a/src/config.h b/src/config.h
14aa00
index 93c8dbc2..9abe355b 100644
14aa00
--- a/src/config.h
14aa00
+++ b/src/config.h
14aa00
@@ -17,7 +17,8 @@
14aa00
 // Maximum number of map entries in the e820 map
14aa00
 #define BUILD_MAX_E820 32
14aa00
 // Space to reserve in high-memory for tables
14aa00
-#define BUILD_MAX_HIGHTABLE (256*1024)
14aa00
+#define BUILD_MIN_HIGHTABLE (256*1024)
14aa00
+#define BUILD_MAX_HIGHTABLE (16*1024*1024)
14aa00
 // Largest supported externaly facing drive id
14aa00
 #define BUILD_MAX_EXTDRIVE 16
14aa00
 // Number of bytes the smbios may be and still live in the f-segment
14aa00
diff --git a/src/malloc.c b/src/malloc.c
14aa00
index ecd8c9ac..da840980 100644
14aa00
--- a/src/malloc.c
14aa00
+++ b/src/malloc.c
14aa00
@@ -423,7 +423,7 @@ malloc_preinit(void)
14aa00
 
14aa00
     // Populate temp high ram
14aa00
     u32 highram_start = 0;
14aa00
-    u32 highram_size = BUILD_MAX_HIGHTABLE;
14aa00
+    u32 highram_size = 0;
14aa00
     int i;
14aa00
     for (i=e820_count-1; i>=0; i--) {
14aa00
         struct e820entry *en = &e820_list[i];
14aa00
@@ -434,10 +434,14 @@ malloc_preinit(void)
14aa00
             continue;
14aa00
         u32 s = en->start, e = end;
14aa00
         if (!highram_start) {
14aa00
-            u32 newe = ALIGN_DOWN(e - highram_size, MALLOC_MIN_ALIGN);
14aa00
-            if (newe <= e && newe >= s) {
14aa00
-                highram_start = newe;
14aa00
-                e = newe;
14aa00
+            u32 new_max = ALIGN_DOWN(e - BUILD_MAX_HIGHTABLE, MALLOC_MIN_ALIGN);
14aa00
+            u32 new_min = ALIGN_DOWN(e - BUILD_MIN_HIGHTABLE, MALLOC_MIN_ALIGN);
14aa00
+            if (new_max <= e && new_max >= s + BUILD_MAX_HIGHTABLE) {
14aa00
+                highram_start = e = new_max;
14aa00
+                highram_size = BUILD_MAX_HIGHTABLE;
14aa00
+            } else if (new_min <= e && new_min >= s) {
14aa00
+                highram_start = e = new_min;
14aa00
+                highram_size = BUILD_MIN_HIGHTABLE;
14aa00
             }
14aa00
         }
14aa00
         alloc_add(&ZoneTmpHigh, s, e);
14aa00
-- 
14aa00
2.31.1
14aa00