Kernel: Process FixedWidthAllocators come now in 4 sizes

This commit is contained in:
Bananymous 2023-06-04 01:26:43 +03:00
parent 924fc2118c
commit e97585daf9
1 changed files with 14 additions and 8 deletions

View File

@ -523,14 +523,19 @@ namespace Kernel
return {}; return {};
} }
static constexpr uint16_t next_power_of_two(uint16_t value) static constexpr size_t allocator_size_for_allocation(size_t value)
{ {
value--; if (value <= 256) {
value |= value >> 1; if (value <= 64)
value |= value >> 2; return 64;
value |= value >> 4; else
value |= value >> 8; return 256;
return value + 1; } else {
if (value <= 1024)
return 1024;
else
return 4096;
}
} }
BAN::ErrorOr<void*> Process::allocate(size_t bytes) BAN::ErrorOr<void*> Process::allocate(size_t bytes)
@ -540,8 +545,9 @@ namespace Kernel
if (bytes <= PAGE_SIZE) if (bytes <= PAGE_SIZE)
{ {
// Do fixed width allocation // Do fixed width allocation
size_t allocation_size = next_power_of_two(bytes); size_t allocation_size = allocator_size_for_allocation(bytes);
ASSERT(bytes <= allocation_size); ASSERT(bytes <= allocation_size);
ASSERT(allocation_size <= PAGE_SIZE);
LockGuard _(m_lock); LockGuard _(m_lock);