diff options
Diffstat (limited to 'byterun/compact.c')
-rw-r--r-- | byterun/compact.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/byterun/compact.c b/byterun/compact.c index 17d574bb7..6c2164c31 100644 --- a/byterun/compact.c +++ b/byterun/compact.c @@ -397,7 +397,7 @@ uintnat caml_percent_max; /* used in gc_ctrl.c and memory.c */ void caml_compact_heap (void) { - uintnat target_size; + uintnat target_size, live; do_compaction (); /* Compaction may fail to shrink the heap to a reasonable size @@ -416,13 +416,15 @@ void caml_compact_heap (void) /* We compute: freewords = caml_fl_cur_size (exact) heapsize = caml_heap_size (exact) - usedwords = heap_size - freewords - target_size = usedwords * (1 + caml_percent_free / 100) + live = heap_size - freewords + target_size = live * (1 + caml_percent_free / 100) + = live / 100 * (100 + caml_percent_free) + We add 1 to live/100 to make sure it isn't 0. We recompact if target_size < heap_size / 2 */ - target_size = (caml_stat_heap_size - Bsize_wsize (caml_fl_cur_size)) - * (100 + caml_percent_free) / 100; + live = caml_stat_heap_size - Bsize_wsize (caml_fl_cur_size); + target_size = (live / 100 + 1) * (100 + caml_percent_free); target_size = caml_round_heap_chunk_size (target_size); if (target_size < caml_stat_heap_size / 2){ char *chunk; |