NFC: LargeAlloc::alloc() take rsize and size both

Mostly for similarity with mediumslabs.  Might shave off a few instructions on
some rare paths (when we know that size == rsize == SUPERSLAB_SIZE).
This commit is contained in:
Nathaniel Filardo
2021-04-01 00:29:18 +01:00
committed by Nathaniel Wesley Filardo
parent c94e37f5fc
commit 4cfcf344fc
2 changed files with 16 additions and 10 deletions

View File

@@ -922,8 +922,9 @@ namespace snmalloc
if (super != nullptr)
return super;
super = reinterpret_cast<Superslab*>(
large_allocator.template alloc<NoZero>(0, SUPERSLAB_SIZE));
super =
reinterpret_cast<Superslab*>(large_allocator.template alloc<NoZero>(
0, SUPERSLAB_SIZE, SUPERSLAB_SIZE));
if (super == nullptr)
return super;
@@ -1304,8 +1305,9 @@ namespace snmalloc
sizeclass, rsize, size);
});
}
slab = reinterpret_cast<Mediumslab*>(
large_allocator.template alloc<NoZero>(0, SUPERSLAB_SIZE));
slab =
reinterpret_cast<Mediumslab*>(large_allocator.template alloc<NoZero>(
0, SUPERSLAB_SIZE, SUPERSLAB_SIZE));
if (slab == nullptr)
return nullptr;
@@ -1413,7 +1415,13 @@ namespace snmalloc
size_t large_class = size_bits - SUPERSLAB_BITS;
SNMALLOC_ASSERT(large_class < NUM_LARGE_CLASSES);
void* p = large_allocator.template alloc<zero_mem>(large_class, size);
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
// For superslab size, we always commit the whole range.
if (large_class == 0)
size = rsize;
void* p =
large_allocator.template alloc<zero_mem>(large_class, rsize, size);
if (likely(p != nullptr))
{
chunkmap().set_large_size(p, size);

View File

@@ -290,12 +290,10 @@ namespace snmalloc
LargeAlloc(MemoryProvider& mp) : memory_provider(mp) {}
template<ZeroMem zero_mem = NoZero>
void* alloc(size_t large_class, size_t size)
void* alloc(size_t large_class, size_t rsize, size_t size)
{
size_t rsize = bits::one_at_bit(SUPERSLAB_BITS) << large_class;
// For superslab size, we always commit the whole range.
if (large_class == 0)
size = rsize;
SNMALLOC_ASSERT(
(bits::one_at_bit(SUPERSLAB_BITS) << large_class) == rsize);
void* p = memory_provider.pop_large_stack(large_class);