MemoryProviderStateMixin is not a PAL

This commit is contained in:
Nathaniel Filardo
2020-09-07 11:57:38 +01:00
committed by Matthew Parkinson
parent d79a8184af
commit 1e8d0bd743
5 changed files with 26 additions and 27 deletions

View File

@@ -1063,7 +1063,7 @@ namespace snmalloc
void* p = remove_cache_friendly_offset(head, sizeclass);
if constexpr (zero_mem == YesZero)
{
large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass));
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
}
return p;
}
@@ -1109,8 +1109,8 @@ namespace snmalloc
SlabLink* link = sl.get_next();
slab = get_slab(link);
auto& ffl = small_fast_free_lists[sizeclass];
return slab->alloc<zero_mem>(
sl, ffl, rsize, large_allocator.memory_provider);
return slab->alloc<zero_mem, typename MemoryProvider::Pal>(
sl, ffl, rsize);
}
return small_alloc_rare<zero_mem, allow_reserve>(sizeclass, size);
}
@@ -1182,7 +1182,7 @@ namespace snmalloc
if constexpr (zero_mem == YesZero)
{
large_allocator.memory_provider.zero(p, sizeclass_to_size(sizeclass));
MemoryProvider::Pal::zero(p, sizeclass_to_size(sizeclass));
}
return p;
}
@@ -1313,7 +1313,7 @@ namespace snmalloc
if (slab != nullptr)
{
p = slab->alloc<zero_mem>(size, large_allocator.memory_provider);
p = slab->alloc<zero_mem, typename MemoryProvider::Pal>(size);
if (slab->full())
sc->pop();
@@ -1336,7 +1336,7 @@ namespace snmalloc
slab->init(public_state(), sizeclass, rsize);
chunkmap().set_slab(slab);
p = slab->alloc<zero_mem>(size, large_allocator.memory_provider);
p = slab->alloc<zero_mem, typename MemoryProvider::Pal>(size);
if (!slab->full())
sc->insert(slab);

View File

@@ -57,7 +57,7 @@ namespace snmalloc
// global state of the allocator. This is currently stored in the memory
// provider, so we add this in.
template<SNMALLOC_CONCEPT(ConceptPAL) PAL>
class MemoryProviderStateMixin : public PalNotificationObject, public PAL
class MemoryProviderStateMixin : public PalNotificationObject
{
/**
* Simple flag for checking if another instance of lazy-decommit is
@@ -76,6 +76,8 @@ namespace snmalloc
std::atomic<size_t> peak_memory_used_bytes{0};
public:
using Pal = PAL;
/**
* Memory current available in large_stacks
*/
@@ -258,7 +260,7 @@ namespace snmalloc
p = memory_provider.template reserve<false>(large_class);
if (p == nullptr)
return nullptr;
memory_provider.template notify_using<zero_mem>(p, rsize);
MemoryProvider::Pal::template notify_using<zero_mem>(p, rsize);
}
else
{
@@ -276,19 +278,19 @@ namespace snmalloc
// The first page is already in "use" for the stack element,
// this will need zeroing for a YesZero call.
if constexpr (zero_mem == YesZero)
memory_provider.template zero<true>(p, OS_PAGE_SIZE);
MemoryProvider::Pal::template zero<true>(p, OS_PAGE_SIZE);
// Notify we are using the rest of the allocation.
// Passing zero_mem ensures the PAL provides zeroed pages if
// required.
memory_provider.template notify_using<zero_mem>(
MemoryProvider::Pal::template notify_using<zero_mem>(
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
}
else
{
// This is a superslab that has not been decommitted.
if constexpr (zero_mem == YesZero)
memory_provider.template zero<true>(
MemoryProvider::Pal::template zero<true>(
p, bits::align_up(size, OS_PAGE_SIZE));
else
UNUSED(size);
@@ -304,7 +306,7 @@ namespace snmalloc
if constexpr (decommit_strategy == DecommitSuperLazy)
{
static_assert(
pal_supports<LowMemoryNotification, MemoryProvider>,
pal_supports<LowMemoryNotification, typename MemoryProvider::Pal>,
"A lazy decommit strategy cannot be implemented on platforms "
"without low memory notifications");
}
@@ -316,7 +318,7 @@ namespace snmalloc
(decommit_strategy != DecommitNone) &&
(large_class != 0 || decommit_strategy == DecommitSuper))
{
memory_provider.notify_not_using(
MemoryProvider::Pal::notify_not_using(
pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE);
}

View File

@@ -76,8 +76,8 @@ namespace snmalloc
return sizeclass;
}
template<ZeroMem zero_mem, typename MemoryProvider>
void* alloc(size_t size, MemoryProvider& memory_provider)
template<ZeroMem zero_mem, SNMALLOC_CONCEPT(ConceptPAL) PAL>
void* alloc(size_t size)
{
SNMALLOC_ASSERT(!full());
@@ -86,7 +86,7 @@ namespace snmalloc
free--;
if constexpr (zero_mem == YesZero)
memory_provider.zero(p, size);
PAL::zero(p, size);
else
UNUSED(size);

View File

@@ -36,12 +36,9 @@ namespace snmalloc
* Returns the link as the allocation, and places the free list into the
* `fast_free_list` for further allocations.
*/
template<ZeroMem zero_mem, typename MemoryProvider>
SNMALLOC_FAST_PATH void* alloc(
SlabList& sl,
FreeListHead& fast_free_list,
size_t rsize,
MemoryProvider& memory_provider)
template<ZeroMem zero_mem, SNMALLOC_CONCEPT(ConceptPAL) PAL>
SNMALLOC_FAST_PATH void*
alloc(SlabList& sl, FreeListHead& fast_free_list, size_t rsize)
{
// Read the head from the metadata stored in the superslab.
Metaslab& meta = get_meta();
@@ -73,9 +70,9 @@ namespace snmalloc
if constexpr (zero_mem == YesZero)
{
if (rsize < PAGE_ALIGNED_SIZE)
memory_provider.zero(p, rsize);
PAL::zero(p, rsize);
else
memory_provider.template zero<true>(p, rsize);
PAL::template zero<true>(p, rsize);
}
else
{

View File

@@ -98,17 +98,17 @@ void reduce_pressure(Queue& allocations)
* Template parameter required to handle `if constexpr` always evaluating both
* sides.
*/
template<typename PAL>
template<typename MemoryProvider>
void register_for_pal_notifications()
{
PAL::register_for_low_memory_callback(&update_epoch);
MemoryProvider::Pal::register_for_low_memory_callback(&update_epoch);
}
int main(int argc, char** argv)
{
opt::Opt opt(argc, argv);
if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual>)
if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual::Pal>)
{
register_for_pal_notifications<GlobalVirtual>();
}