LibGC: Use MADV_FREE_REUSABLE and MADV_FREE_REUSE if available

These are macOS madvise() hints that keep the kernel accounting aware of
how we're using the GC memory. This keeps our memory footprint looking
more accurate.
This commit is contained in:
Andreas Kling
2025-12-18 14:34:27 -06:00
committed by Andreas Kling
parent 716e5f72f2
commit 82f63334d0
Notes: github-actions[bot] 2025-12-20 02:22:38 +00:00

View File

@@ -49,6 +49,12 @@ void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
auto* block = m_blocks.unstable_take(random_index);
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::BLOCK_SIZE);
LSAN_REGISTER_ROOT_REGION(block, HeapBlock::BLOCK_SIZE);
#if defined(MADV_FREE_REUSE) && defined(MADV_FREE_REUSABLE)
if (madvise(block, HeapBlock::BLOCK_SIZE, MADV_FREE_REUSE) < 0) {
perror("madvise(MADV_FREE_REUSE)");
VERIFY_NOT_REACHED();
}
#endif
return block;
}
@@ -74,6 +80,11 @@ void BlockAllocator::deallocate_block(void* block)
warnln("{}", Error::from_windows_error(ret));
VERIFY_NOT_REACHED();
}
#elif defined(MADV_FREE_REUSE) && defined(MADV_FREE_REUSABLE)
if (madvise(block, HeapBlock::BLOCK_SIZE, MADV_FREE_REUSABLE) < 0) {
perror("madvise(MADV_FREE_REUSABLE)");
VERIFY_NOT_REACHED();
}
#elif defined(MADV_FREE)
if (madvise(block, HeapBlock::BLOCK_SIZE, MADV_FREE) < 0) {
perror("madvise(MADV_FREE)");