Skip to content

Commit

Permalink
MemoryProviderStateMixin is not a PAL
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf-msr authored and mjp41 committed Sep 9, 2020
1 parent d79a818 commit 1e8d0bd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
16 changes: 9 additions & 7 deletions src/mem/largealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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");
}
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/mem/mediumslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -86,7 +86,7 @@ namespace snmalloc
free--;

if constexpr (zero_mem == YesZero)
memory_provider.zero(p, size);
PAL::zero(p, size);
else
UNUSED(size);

Expand Down
13 changes: 5 additions & 8 deletions src/mem/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions src/test/perf/low_memory/low-memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
Expand Down

0 comments on commit 1e8d0bd

Please sign in to comment.