Kernel: Tweak SlabAllocator's slab sizes

Nobody was using the 8-byte slab size, so get rid of it and move all of
its capacity to the new 64-byte slab size (which replaces 48-byte.)
This commit is contained in:
Andreas Kling 2020-02-22 14:36:45 +01:00
parent 6428669a37
commit 9fc54ba931
Notes: sideshowbarker 2024-07-19 09:10:11 +09:00

View file

@ -106,53 +106,46 @@ private:
static_assert(sizeof(FreeSlab) == templated_slab_size); static_assert(sizeof(FreeSlab) == templated_slab_size);
}; };
static SlabAllocator<8> s_slab_allocator_8;
static SlabAllocator<16> s_slab_allocator_16; static SlabAllocator<16> s_slab_allocator_16;
static SlabAllocator<32> s_slab_allocator_32; static SlabAllocator<32> s_slab_allocator_32;
static SlabAllocator<48> s_slab_allocator_48; static SlabAllocator<64> s_slab_allocator_64;
static_assert(sizeof(Region) <= s_slab_allocator_48.slab_size()); static_assert(sizeof(Region) <= s_slab_allocator_64.slab_size());
template<typename Callback> template<typename Callback>
void for_each_allocator(Callback callback) void for_each_allocator(Callback callback)
{ {
callback(s_slab_allocator_8);
callback(s_slab_allocator_16); callback(s_slab_allocator_16);
callback(s_slab_allocator_32); callback(s_slab_allocator_32);
callback(s_slab_allocator_48); callback(s_slab_allocator_64);
} }
void slab_alloc_init() void slab_alloc_init()
{ {
s_slab_allocator_8.init(384 * KB);
s_slab_allocator_16.init(128 * KB); s_slab_allocator_16.init(128 * KB);
s_slab_allocator_32.init(128 * KB); s_slab_allocator_32.init(128 * KB);
s_slab_allocator_48.init(128 * KB); s_slab_allocator_64.init(512 * KB);
} }
void* slab_alloc(size_t slab_size) void* slab_alloc(size_t slab_size)
{ {
if (slab_size <= 8)
return s_slab_allocator_8.alloc();
if (slab_size <= 16) if (slab_size <= 16)
return s_slab_allocator_16.alloc(); return s_slab_allocator_16.alloc();
if (slab_size <= 32) if (slab_size <= 32)
return s_slab_allocator_32.alloc(); return s_slab_allocator_32.alloc();
if (slab_size <= 48) if (slab_size <= 64)
return s_slab_allocator_48.alloc(); return s_slab_allocator_64.alloc();
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
void slab_dealloc(void* ptr, size_t slab_size) void slab_dealloc(void* ptr, size_t slab_size)
{ {
if (slab_size <= 8)
return s_slab_allocator_8.dealloc(ptr);
if (slab_size <= 16) if (slab_size <= 16)
return s_slab_allocator_16.dealloc(ptr); return s_slab_allocator_16.dealloc(ptr);
if (slab_size <= 32) if (slab_size <= 32)
return s_slab_allocator_32.dealloc(ptr); return s_slab_allocator_32.dealloc(ptr);
if (slab_size <= 48) if (slab_size <= 64)
return s_slab_allocator_48.dealloc(ptr); return s_slab_allocator_64.dealloc(ptr);
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }