feat: rework physical allocator
This commit is contained in:
parent
e2ea22ad53
commit
bfa71d5836
4 changed files with 364 additions and 44 deletions
|
|
@ -1,37 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "memory/pointer.h"
|
||||
#include "process/process.h"
|
||||
#include "util/optional.h"
|
||||
#include "init/multiboot2.h"
|
||||
|
||||
constexpr const size_t page_size = 4096;
|
||||
|
||||
struct PhysicalAllocator {
|
||||
public:
|
||||
struct allocation_t {
|
||||
paddr_t ptr;
|
||||
size_t page_count;
|
||||
};
|
||||
struct entry_t {
|
||||
uint64_t page_count;
|
||||
pid_t owner;
|
||||
};
|
||||
|
||||
static void init(const multiboot::tag_mmap* multiboot_info);
|
||||
static PhysicalAllocator& getInstance();
|
||||
allocation_t allocPages(size_t page_count, pid_t owner);
|
||||
void free(allocation_t ptr);
|
||||
void force(allocation_t ptr, pid_t owner);
|
||||
entry_t getOwner(paddr_t from);
|
||||
private:
|
||||
struct Page {
|
||||
optional<Page*> next;
|
||||
entry_t entries[255];
|
||||
void forceEntry(entry_t entry);
|
||||
void cleanup();
|
||||
void compact();
|
||||
};
|
||||
static_assert(sizeof(Page) == page_size);
|
||||
Page* storage;
|
||||
};
|
||||
|
||||
optional<allocation_t> allocPages(size_t page_count, size_t alignment_pages = 1);
|
||||
void free(allocation_t ptr);
|
||||
bool force(allocation_t ptr, bool free);
|
||||
|
||||
private:
|
||||
struct page_t {
|
||||
page_t* next;
|
||||
page_t* prev;
|
||||
uint64_t count[510];
|
||||
};
|
||||
static_assert(sizeof(page_t) == page_size);
|
||||
|
||||
page_t* storage;
|
||||
|
||||
friend struct PhysicalAllocatorImpl;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue