1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

Kernel: Add slab allocator for 256 bytes

Our types are getting a tiny bit larger for x86_64 so we need another
slab allocator to deal with that.
This commit is contained in:
Gunnar Beutner 2021-06-26 00:57:19 +02:00 committed by Andreas Kling
parent e52051903b
commit c4acfdc0fb

View file

@ -110,6 +110,7 @@ static SlabAllocator<16> s_slab_allocator_16;
static SlabAllocator<32> s_slab_allocator_32;
static SlabAllocator<64> s_slab_allocator_64;
static SlabAllocator<128> s_slab_allocator_128;
static SlabAllocator<256> s_slab_allocator_256;
#if ARCH(I386)
static_assert(sizeof(Region) <= s_slab_allocator_128.slab_size());
@ -122,6 +123,7 @@ void for_each_allocator(Callback callback)
callback(s_slab_allocator_32);
callback(s_slab_allocator_64);
callback(s_slab_allocator_128);
callback(s_slab_allocator_256);
}
UNMAP_AFTER_INIT void slab_alloc_init()
@ -130,6 +132,7 @@ UNMAP_AFTER_INIT void slab_alloc_init()
s_slab_allocator_32.init(128 * KiB);
s_slab_allocator_64.init(512 * KiB);
s_slab_allocator_128.init(512 * KiB);
s_slab_allocator_256.init(128 * KiB);
}
void* slab_alloc(size_t slab_size)
@ -142,6 +145,8 @@ void* slab_alloc(size_t slab_size)
return s_slab_allocator_64.alloc();
if (slab_size <= 128)
return s_slab_allocator_128.alloc();
if (slab_size <= 256)
return s_slab_allocator_256.alloc();
VERIFY_NOT_REACHED();
}
@ -155,6 +160,8 @@ void slab_dealloc(void* ptr, size_t slab_size)
return s_slab_allocator_64.dealloc(ptr);
if (slab_size <= 128)
return s_slab_allocator_128.dealloc(ptr);
if (slab_size <= 256)
return s_slab_allocator_256.dealloc(ptr);
VERIFY_NOT_REACHED();
}