pmm: Only align memory map when explicitly requested as not to fragment ext_mem allocations too much
This commit is contained in:
parent
769ab76e78
commit
36b5be1380
BIN
limine-pxe.bin
BIN
limine-pxe.bin
Binary file not shown.
BIN
limine.bin
BIN
limine.bin
Binary file not shown.
|
@ -209,7 +209,7 @@ static int ext2_get_inode(struct ext2_inode *ret, struct part *part,
|
|||
}
|
||||
|
||||
static uint32_t *create_alloc_map(struct ext2_file_handle *fd,
|
||||
struct ext2_inode *inode) {
|
||||
struct ext2_inode *inode) {
|
||||
if (inode->i_flags & EXT4_EXTENTS_FLAG)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ void print_memmap(struct e820_entry_t *mm, size_t size) {
|
|||
}
|
||||
}
|
||||
|
||||
static int align_entry(uint64_t *base, uint64_t *length) {
|
||||
static bool align_entry(uint64_t *base, uint64_t *length) {
|
||||
if (*length < PAGE_SIZE)
|
||||
return -1;
|
||||
|
||||
|
@ -57,7 +57,7 @@ static int align_entry(uint64_t *base, uint64_t *length) {
|
|||
*length = ALIGN_DOWN(*length, PAGE_SIZE);
|
||||
|
||||
if (!length)
|
||||
return -1;
|
||||
return false;
|
||||
|
||||
uint64_t top = *base + *length;
|
||||
|
||||
|
@ -66,14 +66,14 @@ static int align_entry(uint64_t *base, uint64_t *length) {
|
|||
*length -= MEMMAP_BASE - *base;
|
||||
*base = MEMMAP_BASE;
|
||||
} else {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void sanitise_entries(void) {
|
||||
static void sanitise_entries(bool align_entries) {
|
||||
for (size_t i = 0; i < memmap_entries; i++) {
|
||||
if (memmap[i].type != MEMMAP_USABLE)
|
||||
continue;
|
||||
|
@ -109,7 +109,11 @@ static void sanitise_entries(void) {
|
|||
memmap[i].length = top - base;
|
||||
}
|
||||
|
||||
if (!memmap[i].length || align_entry(&memmap[i].base, &memmap[i].length)) {
|
||||
bool success = true;
|
||||
if (align_entries)
|
||||
success = align_entry(&memmap[i].base, &memmap[i].length);
|
||||
|
||||
if (!memmap[i].length || !success) {
|
||||
// Eradicate from memmap
|
||||
for (size_t j = i; j < memmap_entries - 1; j++) {
|
||||
memmap[j] = memmap[j+1];
|
||||
|
@ -154,7 +158,7 @@ static void sanitise_entries(void) {
|
|||
}
|
||||
|
||||
struct e820_entry_t *get_memmap(size_t *entries) {
|
||||
sanitise_entries();
|
||||
sanitise_entries(true);
|
||||
|
||||
*entries = memmap_entries;
|
||||
|
||||
|
@ -170,7 +174,7 @@ void init_memmap(void) {
|
|||
memmap[memmap_entries++] = e820_map[i];
|
||||
}
|
||||
|
||||
sanitise_entries();
|
||||
sanitise_entries(false);
|
||||
}
|
||||
|
||||
void *ext_mem_alloc(size_t count) {
|
||||
|
@ -217,7 +221,7 @@ 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();
|
||||
sanitise_entries(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -293,26 +293,6 @@ void stivale2_load(char *cmdline) {
|
|||
if (bits == 64)
|
||||
pagemap = stivale_build_pagemap(level5pg && level5pg_requested);
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Create memmap struct tag
|
||||
//////////////////////////////////////////////
|
||||
{
|
||||
size_t memmap_entries;
|
||||
struct e820_entry_t *memmap = get_memmap(&memmap_entries);
|
||||
|
||||
struct stivale2_struct_tag_memmap *tag =
|
||||
conv_mem_alloc(sizeof(struct stivale2_struct_tag_memmap) +
|
||||
sizeof(struct e820_entry_t) * memmap_entries);
|
||||
|
||||
tag->tag.identifier = STIVALE2_STRUCT_TAG_MEMMAP_ID;
|
||||
tag->entries = (uint64_t)memmap_entries;
|
||||
|
||||
memcpy((void*)tag + sizeof(struct stivale2_struct_tag_memmap),
|
||||
memmap, sizeof(struct e820_entry_t) * memmap_entries);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Create SMP struct tag
|
||||
//////////////////////////////////////////////
|
||||
|
@ -349,6 +329,26 @@ void stivale2_load(char *cmdline) {
|
|||
break;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Create memmap struct tag
|
||||
//////////////////////////////////////////////
|
||||
{
|
||||
size_t memmap_entries;
|
||||
struct e820_entry_t *memmap = get_memmap(&memmap_entries);
|
||||
|
||||
struct stivale2_struct_tag_memmap *tag =
|
||||
conv_mem_alloc(sizeof(struct stivale2_struct_tag_memmap) +
|
||||
sizeof(struct e820_entry_t) * memmap_entries);
|
||||
|
||||
tag->tag.identifier = STIVALE2_STRUCT_TAG_MEMMAP_ID;
|
||||
tag->entries = (uint64_t)memmap_entries;
|
||||
|
||||
memcpy((void*)tag + sizeof(struct stivale2_struct_tag_memmap),
|
||||
memmap, sizeof(struct e820_entry_t) * memmap_entries);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
stivale_spinup(bits, level5pg && level5pg_requested, pagemap,
|
||||
entry_point, &stivale2_struct, stivale2_hdr.stack);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue