DuckLogic/zerogc

Copying collector has x132 as many (minor) page faults as the simple collector

Closed this issue · 0 comments

I suspect this is due to the fact we reallocate the entire heap every collection, then copy everything into the new memory.

Normally implementations of Cheney's copying algorithm divide the heap into two equal halves. While the mutator is running only one of these heaps is active. During collection, the live objects are copied from the old heap to the new heap (implicitly compacting them). The old heap is then considered discarded (but not freed) and the mutator uses the new heap.

Both implementations need 2x the used memory during any given collection cycle (which is a major disadvantage to this algorithm). However, the standard implementation effectively caches the old heap while we reallocate it every time. In theory, this could result in less memory use during mutation (because we free the old memory instead of caching it), however allocating large chunks of memory generally require a mmap syscall to the operating system. Accessing the new memory seems to trigger a (minor) page fault because it's not in the TLB or any of the caches.

We're wasting most of our time page-faulting, losing any performance gains we would otherwise win by bump-pointer allocation. We should switch to caching the old heap, like standard

Of course, right now the copying collector still has some SEGFAULTs, which are obviously higher-priority.