diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 04eeccb..77dbe5d 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -105,7 +105,7 @@ namespace snmalloc * If aligned to a SLAB start, then it is empty, and a new * slab is required. */ - CapPtr bump_ptrs[NUM_SMALL_CLASSES] = {nullptr}; + CapPtr 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 super = Superslab::get(bp); + auto super_slabd = capptr_debug_chunkd_from_chunk(super); + + CapPtr 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 alloc_slab(sizeclass_t sizeclass) + SNMALLOC_SLOW_PATH CapPtr 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); + 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); + 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); + return slab; } template diff --git a/src/mem/freelist.h b/src/mem/freelist.h index 7843379..9454a2c 100644 --- a/src/mem/freelist.h +++ b/src/mem/freelist.h @@ -325,8 +325,7 @@ namespace snmalloc * Start building a new free list. * Provide pointer to the slab to initialise the system. */ - template // TODO: CBChunk-only - void open(CapPtr p) + void open(CapPtr p) { SNMALLOC_ASSERT(empty()); for (size_t i = 0; i < LENGTH; i++) diff --git a/src/mem/slab.h b/src/mem/slab.h index 42694ac..d8f8b1f 100644 --- a/src/mem/slab.h +++ b/src/mem/slab.h @@ -34,7 +34,7 @@ namespace snmalloc * page. */ static SNMALLOC_FAST_PATH void alloc_new_list( - CapPtr& bumpptr, + CapPtr& 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 curr = + CapPtr curr = pointer_offset(bumpptr, 0).template as_static(); curr->next = Aal::capptr_bound(curr, rsize); diff --git a/src/mem/superslab.h b/src/mem/superslab.h index 8846096..2777503 100644 --- a/src/mem/superslab.h +++ b/src/mem/superslab.h @@ -201,34 +201,32 @@ namespace snmalloc return CapPtr(&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 + alloc_short_slab(CapPtr self, sizeclass_t sizeclass) { if ((self->used & 1) == 1) return alloc_slab(self, sizeclass); - Slab* slab = reinterpret_cast(self); + auto slab = self.template as_reinterpret(); auto& metaz = self->meta[0]; - metaz.initialise(sizeclass, CapPtr(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 + alloc_slab(CapPtr self, sizeclass_t sizeclass) { uint8_t h = self->head; - Slab* slab = reinterpret_cast( - pointer_offset(self, (static_cast(h) << SLAB_BITS))); + auto slab = pointer_offset(self, (static_cast(h) << SLAB_BITS)) + .template as_static(); auto& metah = self->meta[h]; uint8_t n = metah.next(); - metah.initialise(sizeclass, CapPtr(slab)); + metah.initialise(sizeclass, slab); self->head = h + n + 1; self->used += 2;