From 3cdb7be478040e799ca878af2d00180e2b7c5316 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 17 Oct 2021 18:12:48 +0100 Subject: [PATCH] MetaEntry: split get_metaslab by intent --- src/backend/address_space_core.h | 2 +- src/mem/localalloc.h | 4 ++-- src/mem/metaslab.h | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/backend/address_space_core.h b/src/backend/address_space_core.h index dcbca96..f8b7251 100644 --- a/src/backend/address_space_core.h +++ b/src/backend/address_space_core.h @@ -125,7 +125,7 @@ namespace snmalloc const MetaEntry& t = Pagemap::template get_metaentry( local_state, address_cast(base)); return capptr::Chunk( - reinterpret_cast(t.get_metaslab())); + reinterpret_cast(t.get_metaslab_no_remote())); } return base->next; diff --git a/src/mem/localalloc.h b/src/mem/localalloc.h index db4bbfa..43423af 100644 --- a/src/mem/localalloc.h +++ b/src/mem/localalloc.h @@ -534,8 +534,8 @@ namespace snmalloc UNUSED(size); # endif - ChunkRecord* slab_record = - reinterpret_cast(entry.get_metaslab()); + auto slab_record = + static_cast(entry.get_metaslab_no_remote()); SNMALLOC_ASSERT( address_cast(slab_record->meta_common.chunk) == address_cast(p_tame)); diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index 1057c14..fcbb293 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -243,8 +243,24 @@ namespace snmalloc pointer_offset(reinterpret_cast(remote), sizeclass); } + /** + * Return the Metaslab field as a void*, guarded by an assert that there is + * no remote that owns this chunk. + */ + [[nodiscard]] SNMALLOC_FAST_PATH void* get_metaslab_no_remote() const + { + SNMALLOC_ASSERT(get_remote() == nullptr); + return static_cast(meta); + } + + /** + * Return the Metaslab metadata associated with this chunk, guarded by an + * assert that this chunk is being used as a slab (i.e., has an associated + * owning allocator). + */ [[nodiscard]] SNMALLOC_FAST_PATH Metaslab* get_metaslab() const { + SNMALLOC_ASSERT(get_remote() != nullptr); return meta; }