Remove local state from Pagemap representation.

This commit is contained in:
Matthew Parkinson
2022-02-10 11:57:13 +00:00
committed by Matthew Parkinson
parent be98a27bf1
commit eb00f3184f
9 changed files with 72 additions and 114 deletions

View File

@@ -114,7 +114,7 @@ namespace snmalloc
meta->meta_common.chunk = p;
MetaEntry t(meta, remote, sizeclass);
Pagemap::set_metaentry(local_state, address_cast(p), size, t);
Pagemap::set_metaentry(address_cast(p), size, t);
return {p, meta};
}
@@ -146,14 +146,14 @@ namespace snmalloc
auto& local = local_state->local_address_space;
#endif
p = local.template reserve_with_left_over<PAL>(local_state, size);
p = local.template reserve_with_left_over<PAL>(size);
if (p != nullptr)
{
return p;
}
auto refill_size = LOCAL_CACHE_BLOCK;
auto refill = global.template reserve<false>(local_state, refill_size);
auto refill = global.template reserve<false>(refill_size);
if (refill == nullptr)
return nullptr;
@@ -165,10 +165,10 @@ namespace snmalloc
}
#endif
PAL::template notify_using<NoZero>(refill.unsafe_ptr(), refill_size);
local.template add_range<PAL>(local_state, refill, refill_size);
local.template add_range<PAL>(refill, refill_size);
// This should succeed
return local.template reserve_with_left_over<PAL>(local_state, size);
return local.template reserve_with_left_over<PAL>(size);
}
#ifdef SNMALLOC_META_PROTECTED
@@ -179,7 +179,7 @@ namespace snmalloc
size_t rsize = bits::max(OS_PAGE_SIZE, bits::next_pow2(size));
size_t size_request = rsize * 64;
p = global.template reserve<false>(local_state, size_request);
p = global.template reserve<false>(size_request);
if (p == nullptr)
return nullptr;
@@ -195,7 +195,7 @@ namespace snmalloc
SNMALLOC_ASSERT(!is_meta);
#endif
p = global.template reserve_with_left_over<true>(local_state, size);
p = global.template reserve_with_left_over<true>(size);
return p;
}
@@ -241,8 +241,6 @@ namespace snmalloc
public:
using Pal = PAL;
class LocalState;
class Pagemap
{
friend class BackendAllocator;
@@ -252,12 +250,6 @@ namespace snmalloc
concretePagemap;
public:
/**
* Provide a type alias for LocalState so that we can refer to it without
* needing the whole BackendAllocator type at hand.
*/
using LocalState = BackendAllocator::LocalState;
/**
* Get the metadata associated with a chunk.
*
@@ -265,10 +257,8 @@ namespace snmalloc
* to access a location that is not backed by a chunk.
*/
template<bool potentially_out_of_range = false>
SNMALLOC_FAST_PATH static const MetaEntry&
get_metaentry(LocalState* ls, address_t p)
SNMALLOC_FAST_PATH static const MetaEntry& get_metaentry(address_t p)
{
UNUSED(ls);
return concretePagemap.template get<potentially_out_of_range>(p);
}
@@ -279,10 +269,8 @@ namespace snmalloc
* to access a location that is not backed by a chunk.
*/
template<bool potentially_out_of_range = false>
SNMALLOC_FAST_PATH static MetaEntry&
get_metaentry_mut(LocalState* ls, address_t p)
SNMALLOC_FAST_PATH static MetaEntry& get_metaentry_mut(address_t p)
{
UNUSED(ls);
return concretePagemap.template get_mut<potentially_out_of_range>(p);
}
@@ -290,19 +278,16 @@ namespace snmalloc
* Set the metadata associated with a chunk.
*/
SNMALLOC_FAST_PATH
static void
set_metaentry(LocalState* ls, address_t p, size_t size, MetaEntry t)
static void set_metaentry(address_t p, size_t size, MetaEntry t)
{
UNUSED(ls);
for (address_t a = p; a < p + size; a += MIN_CHUNK_SIZE)
{
concretePagemap.set(a, t);
}
}
static void register_range(LocalState* ls, address_t p, size_t sz)
static void register_range(address_t p, size_t sz)
{
UNUSED(ls);
concretePagemap.register_range(p, sz);
}
@@ -314,18 +299,16 @@ namespace snmalloc
template<bool fixed_range_ = fixed_range>
static SNMALLOC_FAST_PATH
std::enable_if_t<fixed_range_, std::pair<address_t, address_t>>
get_bounds(LocalState* local_state)
get_bounds()
{
static_assert(
fixed_range_ == fixed_range, "Don't set SFINAE parameter!");
UNUSED(local_state);
return concretePagemap.get_bounds();
}
static bool is_initialised(LocalState* ls)
static bool is_initialised()
{
UNUSED(ls);
return concretePagemap.is_initialised();
}
};
@@ -372,15 +355,13 @@ namespace snmalloc
}
template<bool fixed_range_ = fixed_range>
static std::enable_if_t<fixed_range_>
init(LocalState* local_state, void* base, size_t length)
static std::enable_if_t<fixed_range_> init(void* base, size_t length)
{
static_assert(fixed_range_ == fixed_range, "Don't set SFINAE parameter!");
auto [heap_base, heap_length] =
Pagemap::concretePagemap.init(base, length);
address_space.add_range(
local_state, capptr::Chunk<void>(heap_base), heap_length);
address_space.add_range(capptr::Chunk<void>(heap_base), heap_length);
}
/**