Skip to content

Commit

Permalink
erts: Tweak vheap resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhogberg committed Apr 5, 2024
1 parent ecd8df8 commit 968cb0b
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions erts/emulator/beam/erl_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,8 +2861,7 @@ shrink_new_heap(Process *p, Uint new_sz, Eterm *objv, int nobj)
}

static Uint64
do_next_vheap_size(Uint64 vheap, Uint64 vheap_sz) {

next_vheap_size(Process* p, Uint64 vheap, Uint64 vheap_sz) {
/* grow
*
* vheap_sz ======================
Expand All @@ -2876,35 +2875,31 @@ do_next_vheap_size(Uint64 vheap, Uint64 vheap_sz) {
* vheap ~ - 25% shrink
*
* ----------------------
*
* In most benchmarks we see the best performance when growing quickly and
* shrinking slowly, so the factors have been chosen accordingly (1.618 is
* the golden ratio).
*/
static const double growth_factor = 1.618 * 2, shrink_factor = 1.618;

if ((Uint64) vheap/3 > (Uint64) (vheap_sz/4)) {
Uint64 new_vheap_sz = vheap_sz;
ASSERT(p->min_vheap_size <= vheap_sz);

while((Uint64) vheap/3 > (Uint64) (vheap_sz/4)) {
/* the golden ratio = 1.618 */
new_vheap_sz = (Uint64) vheap_sz * 1.618;
if (new_vheap_sz < vheap_sz ) {
return vheap_sz;
}
vheap_sz = new_vheap_sz;
}

return vheap_sz;
if (vheap < (vheap_sz / 4)) {
return MAX(p->min_vheap_size, (Uint64)(vheap_sz / shrink_factor));
}

if (vheap < (Uint64) (vheap_sz/4)) {
return (vheap_sz >> 1);
}
while ((vheap / 3) > (vheap_sz / 4)) {
Uint64 new_vheap_sz = vheap_sz * growth_factor;

return vheap_sz;
if (new_vheap_sz < vheap_sz) {
return vheap_sz;
}

}
ASSERT(p->min_vheap_size <= new_vheap_sz);
vheap_sz = new_vheap_sz;
}

static Uint64
next_vheap_size(Process* p, Uint64 vheap, Uint64 vheap_sz) {
Uint64 new_vheap_sz = do_next_vheap_size(vheap, vheap_sz);
return new_vheap_sz < p->min_vheap_size ? p->min_vheap_size : new_vheap_sz;
return vheap_sz;
}

static ERTS_INLINE void
Expand Down

0 comments on commit 968cb0b

Please sign in to comment.