From e7dce55f195c573435a4e3204a438c21655b3463 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Fri, 12 Mar 2021 16:37:32 +0000 Subject: [PATCH] Move is_start_of_object into Metaslab. --- src/mem/alloc.h | 2 +- src/mem/metaslab.h | 7 +++++++ src/mem/slab.h | 10 +--------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index ff77794..c336a1f 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -1214,7 +1214,7 @@ namespace snmalloc Superslab* super, Slab* slab, void* p, sizeclass_t sizeclass) { #ifdef CHECK_CLIENT - if (!slab->is_start_of_object(super, p)) + if (!slab->get_meta().is_start_of_object(p)) { error("Not deallocating start of an object"); } diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index ea4200f..0e36c03 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -150,6 +150,13 @@ namespace snmalloc return pointer_align_down(p) == p; } + bool is_start_of_object(void* p) + { + return is_multiple_of_sizeclass( + sizeclass_to_size(sizeclass), + pointer_diff(p, pointer_align_up(pointer_offset(p, 1)))); + } + /** * Check bump-free-list-segment for cycles * diff --git a/src/mem/slab.h b/src/mem/slab.h index c59e82e..025feb6 100644 --- a/src/mem/slab.h +++ b/src/mem/slab.h @@ -63,7 +63,7 @@ namespace snmalloc meta.set_full(); sl.get_next()->remove(); - SNMALLOC_ASSERT(is_start_of_object(Superslab::get(p), p)); + SNMALLOC_ASSERT(meta.is_start_of_object(p)); meta.debug_slab_invariant(this); @@ -110,14 +110,6 @@ namespace snmalloc bumpptr = newbumpptr; } - bool is_start_of_object(Superslab* super, void* p) - { - Metaslab& meta = super->get_meta(this); - return is_multiple_of_sizeclass( - sizeclass_to_size(meta.sizeclass), - pointer_diff(p, pointer_offset(this, SLAB_SIZE))); - } - // Returns true, if it deallocation can proceed without changing any status // bits. Note that this does remove the use from the meta slab, so it // doesn't need doing on the slow path.