Skip to content

Commit

Permalink
[hack] Added a check to decrease latest_heap_size
Browse files Browse the repository at this point in the history
Summary:
Because in some cases the heap can naturally decrease without garbage collection, latest_heap_size can be set to an abnormally high value, preventing GC from happening again.
To fix this, we maintain a new invariant that the latest_heap_size must be at most the current used_heap_size. Thus, if the heap usage decreases after an oldify, latest_heap_size will also decrease, allowing garbage collection to occur again.

Reviewed By: dabek

Differential Revision: D3673343

fbshipit-source-id: 0948e95fb4b54da4ef6374e7323d68cf0afbec41
  • Loading branch information
jamesjwu authored and Facebook Github Bot 0 committed Aug 5, 2016
1 parent 35e0cc1 commit c0c72b7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hack/heap/hh_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,16 @@ void hh_collect(value aggressive_val) {
size_t mem_size = 0;

float space_overhead = aggressive ? 1.2 : 2.0;
if(used_heap_size() < (size_t)(space_overhead * latest_heap_size)) {
size_t used = used_heap_size();
if(used < (size_t)(space_overhead * latest_heap_size)) {
// We have not grown past twice the size since we last gc'd

/* We maintain the invariant that the latest_heap_size
is at most the current heap size, to make sure the GC
always collects */
if (used < latest_heap_size) {
latest_heap_size = used;
}
return;
}

Expand Down

0 comments on commit c0c72b7

Please sign in to comment.