Track amount of wasted shared heap memory to decide on collections
commit476e96f4cb57e88e798d68b08a0b8e5a4ca201e6
authorKasper Kopec <kasper@fb.com>
Mon, 26 Mar 2018 00:40:11 +0000 (25 17:40 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Mon, 26 Mar 2018 00:54:13 +0000 (25 17:54 -0700)
tree7f2396434c735d39b3b2847a7872bb68969fdb26
parent6926a1c5f454c32a1e2065d67a0dc6a929535fd5
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
hphp/hack/src/heap/hh_shared.c
hphp/hack/test/unit/heap/test_hashtbl.ml