mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
deallocate_block() used to call MADV_FREE_REUSABLE / MADV_FREE / MADV_DONTNEED inline on every freed block. With sweep typically freeing many blocks per GC, the cumulative syscall cost shows up as real GC pause time. Move the work onto a single global "decommit worker" thread: - deallocate_block now just poisons the slot and pushes it onto a per-allocator m_freshly_freed queue. No syscalls. - allocate_block prefers m_freshly_freed over m_blocks, so a slot that's recycled before the worker sees it skips the REUSABLE/REUSE pair entirely. This is the main payoff. - Heap::sweep_dead_cells kicks the worker at the end of sweep. The worker sleeps 50 ms after each kick to give the JS thread breathing room, then drains each registered allocator's m_freshly_freed, madvises slots in batches of 64 with sched_yield between batches, and splices them onto m_blocks. - Per-allocator refcount + condvar lets ~BlockAllocator wait until the worker has dropped its reference before our storage goes away. (Chunks themselves remain leaked: type-isolated VM is permanent, so we never tear them down.)