Track amount of wasted shared heap memory to decide on collections
Summary:
We use the heuristic "if the heap has grown X times since last collection, try collecting". This works well in a situation where we start with a big heap, and then slowly add / remove things from it.
It doesn't work well when we start with a small heap, and then quickly add (without removing) things to it. We end up running unnecessary collections during this period. This is happening in Hack server because of changes in
D6996738 - we're moving into a direction where the "initial check" that populates heap and used to be run before SharedMem.init_done will now run after this call, and can be interrupted / interleaved with other operations.
We can instead track the actual amount of memory used/wasted and distinguish the situation of "things were added to heap" (and no memory is wasted) from "things were added and removed from heap" (where we have "holes" and wasted memory).
Reviewed By: gregory-nisbet
Differential Revision:
D7362995
fbshipit-source-id:
0e0c257e6fabc271bdf92af1bc6713cd10c8a68a