diff --git a/src/backend/largebuddyrange.h b/src/backend/largebuddyrange.h index 889f7e0..defcc56 100644 --- a/src/backend/largebuddyrange.h +++ b/src/backend/largebuddyrange.h @@ -29,7 +29,8 @@ namespace snmalloc { SNMALLOC_ASSERT((r & (MIN_CHUNK_SIZE - 1)) == 0); // Preserve lower bits. - *ptr = r | address_cast(*ptr & (MIN_CHUNK_SIZE - 1)) | BACKEND_MARKER; + *ptr = r | address_cast(*ptr & (MIN_CHUNK_SIZE - 1)) | + MetaEntry::REMOTE_BACKEND_MARKER; } static Contents get(const Holder* ptr) diff --git a/src/backend/metatypes.h b/src/backend/metatypes.h index 1f089e0..b3c2473 100644 --- a/src/backend/metatypes.h +++ b/src/backend/metatypes.h @@ -123,6 +123,17 @@ namespace snmalloc uintptr_t remote_and_sizeclass{0}; public: + /** + * This bit is set in remote_and_sizeclass to discriminate between the case + * that it is in use by the frontend (0) or by the backend (1). For the + * former case, see mem/metaslab.h; for the latter, see backend/backend.h + * and backend/largebuddyrange.h. + * + * This value is statically checked by the frontend to ensure that its + * bit packing does not conflict; see mem/remoteallocator.h + */ + static constexpr address_t REMOTE_BACKEND_MARKER = 1 << 7; + constexpr MetaEntry() = default; /** diff --git a/src/mem/remoteallocator.h b/src/mem/remoteallocator.h index f8b309e..2853c78 100644 --- a/src/mem/remoteallocator.h +++ b/src/mem/remoteallocator.h @@ -1,5 +1,6 @@ #pragma once +#include "../backend/metatypes.h" #include "../mem/allocconfig.h" #include "../mem/freelist.h" #include "../mem/sizeclasstable.h" @@ -15,14 +16,12 @@ namespace snmalloc static constexpr size_t REMOTE_MIN_ALIGN = bits::max(CACHELINE_SIZE, SIZECLASS_REP_SIZE) << 1; - // This bit is set on the RemoteAllocator* to indicate it is - // actually being used by the backend for some other use. - static constexpr size_t BACKEND_MARKER = REMOTE_MIN_ALIGN >> 1; - // The bit above the sizeclass is always zero unless this is used // by the backend to represent another datastructure such as the buddy // allocator entries. - constexpr size_t REMOTE_WITH_BACKEND_MARKER_ALIGN = BACKEND_MARKER; + constexpr size_t REMOTE_WITH_BACKEND_MARKER_ALIGN = + MetaEntry::REMOTE_BACKEND_MARKER; + static_assert((REMOTE_MIN_ALIGN >> 1) == MetaEntry::REMOTE_BACKEND_MARKER); /** * Global key for all remote lists. diff --git a/src/mem/remotecache.h b/src/mem/remotecache.h index 5e75599..c80944d 100644 --- a/src/mem/remotecache.h +++ b/src/mem/remotecache.h @@ -108,7 +108,7 @@ namespace snmalloc // set implies this is used by the backend, and we should not be // deallocating memory here. snmalloc_check_client( - (address_cast(remote) & BACKEND_MARKER) == 0, + (address_cast(remote) & MetaEntry::REMOTE_BACKEND_MARKER) == 0, "Delayed detection of attempt to free internal structure."); if constexpr (SharedStateHandle::Options.QueueHeadsAreTame) {