diff --git a/src/pal/pal_apple.h b/src/pal/pal_apple.h index 53336d3..5565fed 100644 --- a/src/pal/pal_apple.h +++ b/src/pal/pal_apple.h @@ -3,6 +3,7 @@ #ifdef __APPLE__ # include "pal_bsd.h" +# include # include # include @@ -50,6 +51,37 @@ namespace snmalloc else ::bzero(p, size); } + + /** + * Overriding here to mark the page as reusable + * rolling it as much as necessary. + * As above, the x86 h/w worked alright without this change + * however now large allocations work better and more reliably + * with on ARM, not to mention better RSS number accuracy + * for tools based on task_info API. + */ + static void notify_not_using(void* p, size_t size) noexcept + { + SNMALLOC_ASSERT(is_aligned_block(p, size)); + while (madvise(p, size, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) + ; + } + + /** + * same remark as above but we need to mark the page as REUSE + * first + */ + template + static void notify_using(void* p, size_t size) noexcept + { + SNMALLOC_ASSERT( + is_aligned_block(p, size) || (zero_mem == NoZero)); + while (madvise(p, size, MADV_FREE_REUSE) == -1 && errno == EAGAIN) + ; + + if constexpr (zero_mem == YesZero) + zero(p, size); + } }; } // namespace snmalloc #endif