Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the GHC garbage collector have any special optimisations for large objects?

Tags:

haskell

ghc

Does the GHC garbage collector handle "large" objects specially? Or does it treat them exactly the same as any other object?

Some GC engines put large objects in a separate area, which gets scanned less regularly and possibly has a different collection algorithm (e.g., compacting instead of copying, or maybe even using freelists rather than attempting to defragment). Does GHC do anything like this?

like image 311
MathematicalOrchid Avatar asked Apr 24 '13 07:04

MathematicalOrchid


1 Answers

Yes. The GHC heap is not kept in one contiguous stretch of memory; rather, it is organized into blocks.

When an allocated object’s size is above a specific threshold (block_size*8/10, where block_size is 4k, so roughly 3.2k), the block holding the object is marked as large (BF_LARGE). Now, when garbage collection occurs, rather than copy large objects from this block to a new one, the block itself is added to the new generation's set of blocks; this involves fiddling with a linked list (a large object list, to be precise).

Since this means that it may take a while for us to reclaim dead space inside a large block, it does mean that large objects can suffer from fragmentation, as seen in bug 7831. However, this doesn't usually occur until individual allocations hit half of the megablock size, 1M.

like image 179
Edward Z. Yang Avatar answered Oct 29 '22 03:10

Edward Z. Yang