Move BACKEND_MARKER to backend/metatypes

And rename it to REMOTE_BACKEND_MARKER to scope it a bit.
This commit is contained in:
Nathaniel Wesley Filardo
2022-03-16 09:58:33 +00:00
committed by Nathaniel Wesley Filardo
parent 9d97a38806
commit b5a66131bd
4 changed files with 18 additions and 7 deletions

View File

@@ -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)

View File

@@ -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;
/**

View File

@@ -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<size_t>(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.

View File

@@ -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)
{