Refactor MetaEntry remote_and_sizeclass

Introduce a class that we can use to more completely separate the frontend
encoding details from the backend.
This commit is contained in:
Nathaniel Wesley Filardo
2022-03-16 13:02:26 +00:00
committed by Nathaniel Wesley Filardo
parent 772e46f878
commit 7940fee00c
8 changed files with 124 additions and 109 deletions

View File

@@ -183,8 +183,8 @@ namespace snmalloc
auto [chunk, meta] = SharedStateHandle::alloc_chunk(
core_alloc->get_backend_local_state(),
large_size_to_chunk_size(size),
core_alloc->public_state(),
size_to_sizeclass_full(size));
MetaslabMetaEntry::encode(
core_alloc->public_state(), size_to_sizeclass_full(size)));
// set up meta data so sizeclass is correct, and hence alloc size, and
// external pointer.
#ifdef SNMALLOC_TRACING
@@ -266,8 +266,9 @@ namespace snmalloc
std::cout << "Remote dealloc post" << p.unsafe_ptr() << " size "
<< alloc_size(p.unsafe_ptr()) << std::endl;
#endif
const MetaEntry& entry =
SharedStateHandle::Pagemap::get_metaentry(address_cast(p));
const MetaslabMetaEntry& entry =
SharedStateHandle::Pagemap::template get_metaentry<MetaslabMetaEntry>(
address_cast(p));
local_cache.remote_dealloc_cache.template dealloc<sizeof(CoreAlloc)>(
entry.get_remote()->trunc_id(), p, key_global);
post_remote_cache();
@@ -624,8 +625,9 @@ namespace snmalloc
capptr::Alloc<void> p_tame = capptr_domesticate<SharedStateHandle>(
core_alloc->backend_state_ptr(), p_wild);
const MetaEntry& entry =
SharedStateHandle::Pagemap::get_metaentry(address_cast(p_tame));
const MetaslabMetaEntry& entry =
SharedStateHandle::Pagemap::template get_metaentry<MetaslabMetaEntry>(
address_cast(p_tame));
if (SNMALLOC_LIKELY(local_cache.remote_allocator == entry.get_remote()))
{
# if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT)
@@ -714,8 +716,9 @@ namespace snmalloc
// To handle this case we require the uninitialised pagemap contain an
// entry for the first chunk of memory, that states it represents a
// large object, so we can pull the check for null off the fast path.
const MetaEntry& entry =
SharedStateHandle::Pagemap::get_metaentry(address_cast(p_raw));
const MetaslabMetaEntry& entry =
SharedStateHandle::Pagemap::template get_metaentry<MetaslabMetaEntry>(
address_cast(p_raw));
return sizeclass_full_to_size(entry.get_sizeclass());
#endif
@@ -759,9 +762,8 @@ namespace snmalloc
size_t remaining_bytes(const void* p)
{
#ifndef SNMALLOC_PASS_THROUGH
const MetaEntry& entry =
SharedStateHandle::Pagemap::template get_metaentry<true>(
address_cast(p));
const MetaslabMetaEntry& entry = SharedStateHandle::Pagemap::
template get_metaentry<MetaslabMetaEntry, true>(address_cast(p));
auto sizeclass = entry.get_sizeclass();
return snmalloc::remaining_bytes(sizeclass, address_cast(p));
@@ -788,9 +790,8 @@ namespace snmalloc
size_t index_in_object(const void* p)
{
#ifndef SNMALLOC_PASS_THROUGH
const MetaEntry& entry =
SharedStateHandle::Pagemap::template get_metaentry<true>(
address_cast(p));
const MetaslabMetaEntry& entry = SharedStateHandle::Pagemap::
template get_metaentry<MetaslabMetaEntry, true>(address_cast(p));
auto sizeclass = entry.get_sizeclass();
return snmalloc::index_in_object(sizeclass, address_cast(p));