SP: pass CBChunk, not CBArena, down to Superslab ops

This commit is contained in:
Nathaniel Filardo
2021-04-07 16:52:04 +01:00
committed by Nathaniel Wesley Filardo
parent 95871ff8a1
commit c673b2e0ba
4 changed files with 28 additions and 27 deletions

View File

@@ -105,7 +105,7 @@ namespace snmalloc
* If aligned to a SLAB start, then it is empty, and a new
* slab is required.
*/
CapPtr<void, CBArena> bump_ptrs[NUM_SMALL_CLASSES] = {nullptr};
CapPtr<void, CBChunk> bump_ptrs[NUM_SMALL_CLASSES] = {nullptr};
public:
Stats& stats()
@@ -779,14 +779,19 @@ namespace snmalloc
auto rsize = sizeclass_to_size(i);
FreeListIter ffl;
auto super = Superslab::get(bp);
auto slab = Metaslab::get_slab(bp);
CapPtr<Superslab, CBChunk> super = Superslab::get(bp);
auto super_slabd = capptr_debug_chunkd_from_chunk(super);
CapPtr<Slab, CBChunk> slab = Metaslab::get_slab(bp);
auto slab_slabd = capptr_debug_chunkd_from_chunk(slab);
while (pointer_align_up(bp, SLAB_SIZE) != bp)
{
Slab::alloc_new_list(bp, ffl, rsize, entropy);
while (!ffl.empty())
{
small_dealloc_offseted_inner(super, slab, ffl.take(entropy), i);
small_dealloc_offseted_inner(
super_slabd, slab_slabd, ffl.take(entropy), i);
}
}
}
@@ -1018,7 +1023,7 @@ namespace snmalloc
}
}
SNMALLOC_SLOW_PATH CapPtr<Slab, CBArena> alloc_slab(sizeclass_t sizeclass)
SNMALLOC_SLOW_PATH CapPtr<Slab, CBChunk> alloc_slab(sizeclass_t sizeclass)
{
stats().sizeclass_alloc_slab(sizeclass);
if (Superslab::is_short_sizeclass(sizeclass))
@@ -1029,10 +1034,9 @@ namespace snmalloc
if (super != nullptr)
{
auto slab =
Superslab::alloc_short_slab(super.unsafe_capptr, sizeclass);
auto slab = Superslab::alloc_short_slab(super, sizeclass);
SNMALLOC_ASSERT(super->is_full());
return CapPtr<Slab, CBArena>(slab);
return slab;
}
super = get_superslab();
@@ -1040,9 +1044,9 @@ namespace snmalloc
if (super == nullptr)
return nullptr;
auto slab = Superslab::alloc_short_slab(super.unsafe_capptr, sizeclass);
auto slab = Superslab::alloc_short_slab(super, sizeclass);
reposition_superslab(super);
return CapPtr<Slab, CBArena>(slab);
return slab;
}
auto super = get_superslab();
@@ -1050,9 +1054,9 @@ namespace snmalloc
if (super == nullptr)
return nullptr;
auto slab = Superslab::alloc_slab(super.unsafe_capptr, sizeclass);
auto slab = Superslab::alloc_slab(super, sizeclass);
reposition_superslab(super);
return CapPtr<Slab, CBArena>(slab);
return slab;
}
template<ZeroMem zero_mem>

View File

@@ -325,8 +325,7 @@ namespace snmalloc
* Start building a new free list.
* Provide pointer to the slab to initialise the system.
*/
template<capptr_bounds B> // TODO: CBChunk-only
void open(CapPtr<void, B> p)
void open(CapPtr<void, CBChunk> p)
{
SNMALLOC_ASSERT(empty());
for (size_t i = 0; i < LENGTH; i++)

View File

@@ -34,7 +34,7 @@ namespace snmalloc
* page.
*/
static SNMALLOC_FAST_PATH void alloc_new_list(
CapPtr<void, CBArena>& bumpptr,
CapPtr<void, CBChunk>& bumpptr,
FreeListIter& fast_free_list,
size_t rsize,
LocalEntropy& entropy)
@@ -60,7 +60,7 @@ namespace snmalloc
// Note the wide bounds on curr relative to each of the ->next fields;
// curr is not persisted once the list is built.
CapPtr<PreAllocObject, CBArena> curr =
CapPtr<PreAllocObject, CBChunk> curr =
pointer_offset(bumpptr, 0).template as_static<PreAllocObject>();
curr->next = Aal::capptr_bound<PreAllocObject, CBAlloc>(curr, rsize);

View File

@@ -201,34 +201,32 @@ namespace snmalloc
return CapPtr<Metaslab, B>(&meta[slab_to_index(slab)]);
}
// This is pre-factored to take an explicit self parameter so that we can
// eventually annotate that pointer with additional information.
static Slab* alloc_short_slab(Superslab* self, sizeclass_t sizeclass)
static CapPtr<Slab, CBChunk>
alloc_short_slab(CapPtr<Superslab, CBChunk> self, sizeclass_t sizeclass)
{
if ((self->used & 1) == 1)
return alloc_slab(self, sizeclass);
Slab* slab = reinterpret_cast<Slab*>(self);
auto slab = self.template as_reinterpret<Slab>();
auto& metaz = self->meta[0];
metaz.initialise(sizeclass, CapPtr<Slab, CBChunk>(slab));
metaz.initialise(sizeclass, slab);
self->used++;
return slab;
}
// This is pre-factored to take an explicit self parameter so that we can
// eventually annotate that pointer with additional information.
static Slab* alloc_slab(Superslab* self, sizeclass_t sizeclass)
static CapPtr<Slab, CBChunk>
alloc_slab(CapPtr<Superslab, CBChunk> self, sizeclass_t sizeclass)
{
uint8_t h = self->head;
Slab* slab = reinterpret_cast<Slab*>(
pointer_offset(self, (static_cast<size_t>(h) << SLAB_BITS)));
auto slab = pointer_offset(self, (static_cast<size_t>(h) << SLAB_BITS))
.template as_static<Slab>();
auto& metah = self->meta[h];
uint8_t n = metah.next();
metah.initialise(sizeclass, CapPtr<Slab, CBChunk>(slab));
metah.initialise(sizeclass, slab);
self->head = h + n + 1;
self->used += 2;