From 7d0ef9ef24da708c210189ceee34dc4e23395801 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Mon, 17 Oct 2022 04:34:27 +0200 Subject: [PATCH] pmm: Avoid throwing away big memory ranges that fail to AllocatePages() indiscriminately --- common/mm/pmm.s2.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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); + } + } } }