in src/pal/pal_apple.h [162:205]
static void notify_using(void* p, size_t size) noexcept
{
KeepErrno e;
SNMALLOC_ASSERT(
is_aligned_block<page_size>(p, size) || (zero_mem == NoZero));
if constexpr (zero_mem == YesZero)
{
void* r = mmap(
p,
size,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
anonymous_memory_fd,
0);
if (SNMALLOC_LIKELY(r != MAP_FAILED))
{
return;
}
}
if constexpr (PalEnforceAccess)
{
// Mark pages as writable for `madvise` below.
//
// `mach_vm_protect` is observably slower in benchmarks.
mprotect(p, size, PROT_READ | PROT_WRITE);
}
// `MADV_FREE_REUSE` can only be applied to writable pages,
// otherwise it's an error.
//
// `mach_vm_behavior_set` is observably slower in benchmarks.
//
// macOS 11 Big Sur may behave in an undocumented manner.
while (madvise(p, size, MADV_FREE_REUSE) == -1 && errno == EAGAIN)
;
if constexpr (zero_mem == YesZero)
{
::bzero(p, size);
}
}