fully-static PALs

This commit is contained in:
Nathaniel Filardo
2020-09-07 10:42:10 +01:00
committed by Matthew Parkinson
parent cb1694f124
commit bf3c99d87f
10 changed files with 38 additions and 41 deletions

View File

@@ -31,7 +31,7 @@ namespace snmalloc
* operating system to replace the pages with CoW copies of a zero page at
* any point between the call and the next write to that page.
*/
void notify_not_using(void* p, size_t size) noexcept
static void notify_not_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
madvise(p, size, MADV_FREE);

View File

@@ -29,7 +29,7 @@ namespace snmalloc
* Reserve memory at a specific alignment.
*/
template<bool committed>
void* reserve_aligned(size_t size) noexcept
static void* reserve_aligned(size_t size) noexcept
{
// Alignment must be a power of 2.
SNMALLOC_ASSERT(size == bits::next_pow2(size));

View File

@@ -35,20 +35,17 @@ namespace snmalloc
* PALs expose a basic library of memory operations.
*/
template<typename PAL>
concept ConceptPAL_memops = requires(PAL p, void* vp, size_t sz)
concept ConceptPAL_memops = requires(void* vp, size_t sz)
{
{ p.notify_not_using(vp, sz) } noexcept -> ConceptSame<void>;
{ PAL::notify_not_using(vp, sz) } noexcept -> ConceptSame<void>;
/* For reasons unknown, these seem to tickle some bug in MSVC */
# if !defined(_MSC_VER)
{ p.template notify_using<NoZero>(vp, sz) } noexcept
{ PAL::template notify_using<NoZero>(vp, sz) } noexcept
-> ConceptSame<void>;
{ p.template notify_using<YesZero>(vp, sz) } noexcept
{ PAL::template notify_using<YesZero>(vp, sz) } noexcept
-> ConceptSame<void>;
# endif
{ p.template zero<false>(vp, sz) } noexcept -> ConceptSame<void>;
{ p.template zero<true>(vp, sz) } noexcept -> ConceptSame<void>;
{ PAL::template zero<false>(vp, sz) } noexcept -> ConceptSame<void>;
{ PAL::template zero<true>(vp, sz) } noexcept -> ConceptSame<void>;
};
/**
@@ -57,7 +54,7 @@ namespace snmalloc
template<typename PAL>
concept ConceptPAL_reserve_at_least = requires(PAL p, void* vp, size_t sz)
{
{ p.reserve_at_least(sz) } noexcept
{ PAL::reserve_at_least(sz) } noexcept
-> ConceptSame<std::pair<void*, size_t>>;
};
@@ -65,21 +62,21 @@ namespace snmalloc
* Some PALs expose a richer allocator which understands aligned allocations
*/
template<typename PAL>
concept ConceptPAL_reserve_aligned = requires(PAL p, size_t sz)
concept ConceptPAL_reserve_aligned = requires(size_t sz)
{
{ p.template reserve_aligned<false>(sz) } noexcept -> ConceptSame<void*>;
{ p.template reserve_aligned<true>(sz) } noexcept -> ConceptSame<void*>;
{ PAL::template reserve_aligned<true>(sz) } noexcept -> ConceptSame<void*>;
{ PAL::template reserve_aligned<false>(sz) } noexcept
-> ConceptSame<void*>;
};
/**
* Some PALs can provide memory pressure callbacks.
*/
template<typename PAL>
concept ConceptPAL_mem_low_notify =
requires(PAL p, PalNotificationObject* pno)
concept ConceptPAL_mem_low_notify = requires(PalNotificationObject* pno)
{
{ p.expensive_low_memory_check() } -> ConceptSame<bool>;
{ p.register_for_low_memory_callback(pno) } -> ConceptSame<void>;
{ PAL::expensive_low_memory_check() } -> ConceptSame<bool>;
{ PAL::register_for_low_memory_callback(pno) } -> ConceptSame<void>;
};
/**

View File

@@ -34,7 +34,7 @@ namespace snmalloc
}
/// Notify platform that we will not be using these pages
void notify_not_using(void* p, size_t size)
static void notify_not_using(void* p, size_t size)
{
vm_offset_t addr = get_vm_offset(p);
kmem_unback(kernel_object, addr, size);
@@ -42,7 +42,7 @@ namespace snmalloc
/// Notify platform that we will be using these pages
template<ZeroMem zero_mem>
void notify_using(void* p, size_t size)
static void notify_using(void* p, size_t size)
{
vm_offset_t addr = get_vm_offset(p);
int flags = M_WAITOK | ((zero_mem == YesZero) ? M_ZERO : 0);
@@ -54,13 +54,13 @@ namespace snmalloc
/// OS specific function for zeroing memory
template<bool page_aligned = false>
void zero(void* p, size_t size)
static void zero(void* p, size_t size)
{
::bzero(p, size);
}
template<bool committed>
void* reserve_aligned(size_t size) noexcept
static void* reserve_aligned(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);

View File

@@ -31,7 +31,7 @@ namespace snmalloc
* Notify platform that we will not be needing these pages.
* Haiku does not provide madvise call per say only the posix equivalent.
*/
void notify_not_using(void* p, size_t size) noexcept
static void notify_not_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
posix_madvise(p, size, POSIX_MADV_DONTNEED);

View File

@@ -37,7 +37,7 @@ namespace snmalloc
* clear the underlying memory range.
*/
template<bool page_aligned = false>
void zero(void* p, size_t size) noexcept
static void zero(void* p, size_t size) noexcept
{
// QEMU does not seem to be giving the desired behaviour for
// MADV_DONTNEED. switch back to memset only for QEMU.

View File

@@ -62,7 +62,7 @@ namespace snmalloc
}
template<bool page_aligned = false>
void zero(void* p, size_t size) noexcept
static void zero(void* p, size_t size) noexcept
{
oe_memset_s(p, size, 0, size);
}

View File

@@ -11,11 +11,11 @@ namespace snmalloc
{
public:
// Notify platform that we will not be using these pages
void notify_not_using(void*, size_t) noexcept {}
static void notify_not_using(void*, size_t) noexcept {}
// Notify platform that we will not be using these pages
template<ZeroMem zero_mem>
void notify_using(void* p, size_t size) noexcept
static void notify_using(void* p, size_t size) noexcept
{
if constexpr (zero_mem == YesZero)
{

View File

@@ -131,7 +131,7 @@ namespace snmalloc
* high memory pressure conditions, though on Linux this seems to impose
* too much of a performance penalty.
*/
void notify_not_using(void* p, size_t size) noexcept
static void notify_not_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
#ifdef USE_POSIX_COMMIT_CHECKS
@@ -150,7 +150,7 @@ namespace snmalloc
* function.
*/
template<ZeroMem zero_mem>
void notify_using(void* p, size_t size) noexcept
static void notify_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(
is_aligned_block<OS::page_size>(p, size) || (zero_mem == NoZero));
@@ -163,7 +163,7 @@ namespace snmalloc
#endif
if constexpr (zero_mem == YesZero)
static_cast<OS*>(this)->template zero<true>(p, size);
zero<true>(p, size);
}
/**
@@ -178,7 +178,7 @@ namespace snmalloc
* calling bzero at some point.
*/
template<bool page_aligned = false>
void zero(void* p, size_t size) noexcept
static void zero(void* p, size_t size) noexcept
{
if (page_aligned || is_aligned_block<OS::page_size>(p, size))
{
@@ -207,7 +207,7 @@ namespace snmalloc
* POSIX does not define a portable interface for specifying alignment
* greater than a page.
*/
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));

View File

@@ -64,7 +64,7 @@ namespace snmalloc
* Check whether the low memory state is still in effect. This is an
* expensive operation and should not be on any fast paths.
*/
bool expensive_low_memory_check()
static bool expensive_low_memory_check()
{
BOOL result;
QueryMemoryResourceNotification(lowMemoryObject, &result);
@@ -113,7 +113,7 @@ namespace snmalloc
}
/// Notify platform that we will not be using these pages
void notify_not_using(void* p, size_t size) noexcept
static void notify_not_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
@@ -125,7 +125,7 @@ namespace snmalloc
/// Notify platform that we will be using these pages
template<ZeroMem zero_mem>
void notify_using(void* p, size_t size) noexcept
static void notify_using(void* p, size_t size) noexcept
{
SNMALLOC_ASSERT(
is_aligned_block<page_size>(p, size) || (zero_mem == NoZero));
@@ -138,7 +138,7 @@ namespace snmalloc
/// OS specific function for zeroing memory
template<bool page_aligned = false>
void zero(void* p, size_t size) noexcept
static void zero(void* p, size_t size) noexcept
{
if (page_aligned || is_aligned_block<page_size>(p, size))
{
@@ -151,13 +151,13 @@ namespace snmalloc
}
# ifdef USE_SYSTEMATIC_TESTING
size_t& systematic_bump_ptr()
static size_t& systematic_bump_ptr()
{
static size_t bump_ptr = (size_t)0x4000'0000'0000;
return bump_ptr;
}
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
{
// Magic number for over-allocating chosen by the Pal
// These should be further refined based on experiments.
@@ -183,7 +183,7 @@ namespace snmalloc
}
# elif defined(PLATFORM_HAS_VIRTUALALLOC2)
template<bool committed>
void* reserve_aligned(size_t size) noexcept
static void* reserve_aligned(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));
SNMALLOC_ASSERT(size >= minimum_alloc_size);
@@ -213,7 +213,7 @@ namespace snmalloc
return ret;
}
# else
std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
static std::pair<void*, size_t> reserve_at_least(size_t size) noexcept
{
SNMALLOC_ASSERT(size == bits::next_pow2(size));