4 ms·
Yes, when you fork all the pages in the address space are referenced, and copied when modified. However if you have a GC it will go around touching objects in t
by ot 9y ago
Yes, when you fork all the pages in the address space are referenced, and copied when modified.
However if you have a GC it will go around touching objects in the child process, and there's a good chance it will end up touching a few bytes in each page, nullifying the benefits of COW.
- rurban 9y agoExactly. That's why you normally don't call refcounting a GC, as it writes to objects on referencing, and thereby destroys COW. With Perl it's even more stupid, they write to the const strings also, not just the refcount. And still call it COW. I call it write on assign, WOA. A normal GC leaves it alone and does not force fresh memory maps for these.
- ot 9y agoIt's not just refcounting, GCs also normally have some sort of bookkeeping that is updated in the background, for example a mark&sweep GC will need to mark the objects. See the comment about the object header in the OP.
- rurban 9y agoThis GC bookkeeping cannot be compared to the refcounting madness. A GC needs 1-2 bits during the GC, but does not disturb COW pages at all during run-time. It also has no word overhead, these 2 bits easily fit into every object. Also a GC compacts the live heap, which makes all upcoming accesses much faster. Well, not Mark & Sweep, but a compacting GC.