:: commit d8193abc98bbdafed29ae69885ed7296a1bbd027

mintsuki <mintsuki@protonmail.com> — 2022-10-17 02:34

parents: ce4046d559

pmm: Avoid throwing away big memory ranges that fail to AllocatePages() indiscriminately

diff --git a/common/mm/pmm.s2.c b/common/mm/pmm.s2.c
index 8057cc9b..b7b28699 100644
--- a/common/mm/pmm.s2.c
+++ b/common/mm/pmm.s2.c
@@ -402,8 +402,14 @@ void init_memmap(void) {
                                     memmap[i].length / 4096, &base);
 
         if (status) {
-            print("pmm: WARNING: AllocatePages failure (%d)\n", status);
-            memmap_alloc_range(memmap[i].base, memmap[i].length, MEMMAP_RESERVED, MEMMAP_USABLE, true, false, false);
+            for (size_t j = 0; j < memmap[i].length; j += 4096) {
+                uint64_t length = memmap[i].length - j < 4096 ? memmap[i].length - j : 4096;
+                base = memmap[i].base + j;
+                status = gBS->AllocatePages(AllocateAddress, EfiLoaderData, length, &base);
+                if (status) {
+                    memmap_alloc_range(base, length, MEMMAP_EFI_RECLAIMABLE, MEMMAP_USABLE, true, false, false);
+                }
+            }
         }
     }
 
tab: 248 wrap: offon