pmm: Merge contiguous bootloader reclaimable entries

This commit is contained in:
mintsuki 2020-09-30 22:51:56 +02:00
parent 5f00385847
commit 3c562830d2
2 changed files with 22 additions and 1 deletions

Binary file not shown.

View File

@ -75,7 +75,7 @@ static int align_entry(uint64_t *base, uint64_t *length) {
static void sanitise_entries(void) {
for (size_t i = 0; i < memmap_entries; i++) {
if (memmap[i].type != 1)
if (memmap[i].type != MEMMAP_USABLE)
continue;
// Check if the entry overlaps other entries
@ -133,6 +133,25 @@ static void sanitise_entries(void) {
memmap[min_index] = memmap[p];
memmap[p] = min_e;
}
// Merge contiguous bootloader-reclaimable entries
for (size_t i = 0; i < memmap_entries - 1; i++) {
if (memmap[i].type != MEMMAP_BOOTLOADER_RECLAIMABLE)
continue;
if (memmap[i+1].type == MEMMAP_BOOTLOADER_RECLAIMABLE
&& memmap[i+1].base == memmap[i].base + memmap[i].length) {
print("%u: Merging %X %X to %X %X\n", i, memmap[i].base, memmap[i].length, memmap[i+1].base, memmap[i].length + memmap[i+1].length);
memmap[i].length += memmap[i+1].length;
// Eradicate from memmap
for (size_t j = i+1; j < memmap_entries - 1; j++) {
memmap[j] = memmap[j+1];
}
memmap_entries--;
i--;
}
}
}
struct e820_entry_t *get_memmap(size_t *entries) {
@ -202,6 +221,8 @@ void *ext_mem_alloc_aligned_type(size_t count, size_t alignment, uint32_t type)
// Zero out allocated space
memset(ret, 0, count);
sanitise_entries();
return ret;
}