2023-05-18 09:46:41 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-08-02 00:54:37 -07:00
|
|
|
#include <glacier/memory/unique_ptr.h>
|
2023-05-18 09:46:41 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-11-15 12:53:14 -08:00
|
|
|
#include "memory/constants.h"
|
2023-08-02 00:54:37 -07:00
|
|
|
#include "memory/slab_allocator.h"
|
|
|
|
|
2023-05-18 09:46:41 -07:00
|
|
|
class KernelHeap {
|
|
|
|
public:
|
2023-11-15 12:53:14 -08:00
|
|
|
KernelHeap();
|
2023-08-02 00:54:37 -07:00
|
|
|
void InitializeSlabAllocators();
|
2023-05-18 09:46:41 -07:00
|
|
|
|
|
|
|
void* Allocate(uint64_t size);
|
|
|
|
|
2023-08-02 00:54:37 -07:00
|
|
|
void Free(void* address);
|
|
|
|
|
2023-11-15 12:36:18 -08:00
|
|
|
static void DumpDebugData();
|
2023-06-07 10:01:22 -07:00
|
|
|
|
2023-05-18 09:46:41 -07:00
|
|
|
private:
|
2023-11-15 12:53:14 -08:00
|
|
|
uint64_t next_addr_ = kKernelBuddyHeapStart;
|
|
|
|
uint64_t upper_bound_ = kKernelBuddyHeapEnd;
|
2023-06-07 10:01:22 -07:00
|
|
|
|
2023-11-15 12:36:18 -08:00
|
|
|
uint64_t alloc_count_ = 0;
|
|
|
|
|
2023-11-15 13:02:34 -08:00
|
|
|
SlabAllocator slab_8_{8};
|
|
|
|
SlabAllocator slab_16_{16};
|
|
|
|
SlabAllocator slab_32_{32};
|
2023-11-15 13:06:14 -08:00
|
|
|
SlabAllocator slab_64_{64};
|
|
|
|
SlabAllocator slab_128_{128};
|
2023-08-02 00:54:37 -07:00
|
|
|
|
2023-11-15 13:10:53 -08:00
|
|
|
// 0: 128B-256B
|
|
|
|
// 1: 256B-512B
|
|
|
|
// 2: 512B-1KiB
|
|
|
|
// 3: 1KiB-2KiB
|
|
|
|
// 4: 2KiB-4KiB
|
|
|
|
// 5: 4KiB+
|
|
|
|
uint64_t distributions[6];
|
2023-06-07 10:01:22 -07:00
|
|
|
|
|
|
|
void RecordSize(uint64_t size);
|
2023-11-15 12:36:18 -08:00
|
|
|
|
|
|
|
void DumpDebugDataInternal();
|
2023-05-18 09:46:41 -07:00
|
|
|
};
|