mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-23 19:30:31 +00:00
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:
committed by
Andreas Kling
parent
716e5f72f2
commit
82f63334d0
Notes:
github-actions[bot]
2025-12-20 02:22:38 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/82f63334d09 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7187
@@ -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)");
|
||||
|
||||
Reference in New Issue
Block a user