From 1042fc908a725ac12513fb0e07a568b7fc9883c8 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Fri, 20 Nov 2020 17:47:56 +0000 Subject: [PATCH] alloc: de-static alloc_size We're going to need to amplify the pointer and that's going to require access to our AddressSpaceManager, which we only get non-statically through our LargeAlloc. This patch unto itself makes the world slower, perhaps because Clang can't see the certainty of aliasing of the static and non-static paths to the same structure. However, when we also de-static external_pointer, that goes away and things return to the status quo ante. --- src/mem/alloc.h | 4 ++-- src/override/malloc.cc | 4 ++-- src/test/func/memory/memory.cc | 8 ++++---- src/test/perf/external_pointer/externalpointer.cc | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 910acbe..7830095 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -429,13 +429,13 @@ namespace snmalloc } public: - SNMALLOC_FAST_PATH static size_t alloc_size(const void* p) + SNMALLOC_FAST_PATH size_t alloc_size(const void* p) { #ifdef SNMALLOC_PASS_THROUGH return external_alloc::malloc_usable_size(const_cast(p)); #else // This must be called on an external pointer. - size_t chunkmap_slab_kind = ChunkMap::get(address_cast(p)); + size_t chunkmap_slab_kind = chunkmap().get(address_cast(p)); if (likely(chunkmap_slab_kind == CMSuperslab)) { diff --git a/src/override/malloc.cc b/src/override/malloc.cc index 0c57029..782f488 100644 --- a/src/override/malloc.cc +++ b/src/override/malloc.cc @@ -73,7 +73,7 @@ extern "C" size_t SNMALLOC_NAME_MANGLE(malloc_usable_size)( MALLOC_USABLE_SIZE_QUALIFIER void* ptr) { - return Alloc::alloc_size(ptr); + return ThreadAlloc::get_noncachable()->alloc_size(ptr); } SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(realloc)(void* ptr, size_t size) @@ -95,7 +95,7 @@ extern "C" SNMALLOC_NAME_MANGLE(check_start)(ptr); - size_t sz = Alloc::alloc_size(ptr); + size_t sz = ThreadAlloc::get_noncachable()->alloc_size(ptr); // Keep the current allocation if the given size is in the same sizeclass. if (sz == round_size(size)) { diff --git a/src/test/func/memory/memory.cc b/src/test/func/memory/memory.cc index d123395..a6dd80d 100644 --- a/src/test/func/memory/memory.cc +++ b/src/test/func/memory/memory.cc @@ -295,7 +295,7 @@ void test_external_pointer_large() // store object objects[i] = (size_t*)alloc->alloc(size); // Store allocators size for this object - *objects[i] = Alloc::alloc_size(objects[i]); + *objects[i] = alloc->alloc_size(objects[i]); check_external_pointer_large(objects[i]); if (i > 0) @@ -348,7 +348,7 @@ void test_alloc_16M() const size_t size = 16'000'000; void* p1 = alloc->alloc(size); - SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size); + SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size); alloc->dealloc(p1); } @@ -359,7 +359,7 @@ void test_calloc_16M() const size_t size = 16'000'000; void* p1 = alloc->alloc(size); - SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size); + SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size); alloc->dealloc(p1); } @@ -373,7 +373,7 @@ void test_calloc_large_bug() const size_t size = (SUPERSLAB_SIZE << 3) - 7; void* p1 = alloc->alloc(size); - SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size); + SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size); alloc->dealloc(p1); } diff --git a/src/test/perf/external_pointer/externalpointer.cc b/src/test/perf/external_pointer/externalpointer.cc index 513d3de..6519bba 100644 --- a/src/test/perf/external_pointer/externalpointer.cc +++ b/src/test/perf/external_pointer/externalpointer.cc @@ -33,7 +33,7 @@ namespace test // store object objects[i] = (size_t*)alloc->alloc(size); // Store allocators size for this object - *objects[i] = Alloc::alloc_size(objects[i]); + *objects[i] = alloc->alloc_size(objects[i]); } }