feat: Various improvements
This commit is contained in:
@@ -51,10 +51,12 @@ namespace Memory
|
||||
|
||||
HeapAllocator::HeapAllocator()
|
||||
{
|
||||
InsertPagesToFreelist(8);
|
||||
InsertPagesToFreelist(0x32);
|
||||
}
|
||||
|
||||
void* HeapAllocator::Request(size_t size) {
|
||||
Lock.Acquire();
|
||||
|
||||
Node* current = head.next;
|
||||
Node* prev = &head;
|
||||
|
||||
@@ -79,12 +81,15 @@ namespace Memory
|
||||
|
||||
InsertToFreelist(rest, newBlockSize);
|
||||
}
|
||||
|
||||
|
||||
Lock.Release();
|
||||
return block;
|
||||
}
|
||||
|
||||
prev = current;
|
||||
current = current->next;
|
||||
|
||||
Lock.Release();
|
||||
}
|
||||
|
||||
// First pass allocation failed
|
||||
@@ -106,6 +111,8 @@ namespace Memory
|
||||
}
|
||||
|
||||
void HeapAllocator::Free(void* ptr) {
|
||||
Lock.Acquire();
|
||||
|
||||
Header* header = GetHeader(ptr);
|
||||
auto size = header->size;
|
||||
|
||||
@@ -113,11 +120,13 @@ namespace Memory
|
||||
Panic("Bad magic in HeapAllocator header", nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto actualSize = size + sizeof(Header);
|
||||
void* actualBlock = (void*)header;
|
||||
|
||||
InsertToFreelist(actualBlock, size);
|
||||
InsertToFreelist(actualBlock, size);
|
||||
|
||||
Lock.Release();
|
||||
}
|
||||
|
||||
// Traverses the Allocator's linked list for debugging
|
||||
@@ -126,7 +135,7 @@ namespace Memory
|
||||
size_t i{0};
|
||||
|
||||
while (current != nullptr) {
|
||||
kout << "HeapAllocator: " << base::dec << i << " " << current->size << " bytes & address 0x" << base::hex << (uint64_t)current << Kt::newline;
|
||||
Kt::KernelLogStream(Kt::DEBUG, "HeapAllocator") << base::dec << i << " " << current->size << " bytes & address 0x" << base::hex << (uint64_t)current;
|
||||
current = current->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
#include "Memmap.hpp"
|
||||
#include <CppLib/Spinlock.hpp>
|
||||
|
||||
namespace Memory {
|
||||
class HeapAllocator {
|
||||
static constexpr std::size_t headerMagic = 0x6CEF9AB4;
|
||||
kcp::Spinlock Lock;
|
||||
|
||||
struct Node {
|
||||
size_t size;
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace Memory {
|
||||
}
|
||||
|
||||
if (entry->type == LIMINE_MEMMAP_USABLE) {
|
||||
kout << "MemoryManagement: Found conventional memory section (size = " << base::dec << entry->length << " bytes, address = 0x" << base::hex << (uint64_t)entry->base << ")" << newline;
|
||||
|
||||
if (entry->length > currentLargestSection.size) {
|
||||
currentLargestSection = {
|
||||
.address = (uint64_t)entry->base,
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace Memory {
|
||||
head.next = (Page*)g_section.address;
|
||||
head.next->size = section.size;
|
||||
head.next->next = nullptr;
|
||||
|
||||
Kt::KernelLogStream(Kt::DEBUG, "PageFrameAllocator") << "New pool size: " << section.size;
|
||||
}
|
||||
|
||||
void* PageFrameAllocator::Allocate() {
|
||||
|
||||
Reference in New Issue
Block a user