Closed Bug 1770768 Opened 5 months ago Closed 2 months ago

Use a square-root based heap limit rule for the main GC heap


(Core :: JavaScript: GC, task, P3)




105 Branch
Tracking Status
firefox105 --- fixed


(Reporter: jonco, Assigned: jonco)


(Blocks 1 open bug)



(7 files)

First of all, use a square-root based rule for the main GC heap limit. Later we can apply this rule to other heap limits (malloc and JIT memory).

Severity: -- → N/A
Priority: -- → P3
Depends on: 1771315
Depends on: 1771747
Depends on: 1772082
Depends on: 1776833

This estimates the collection rate per zone based on GC time (including
off-thread sweeping) and zone size pre-GC. The result is smoothed using an
exponential moving average.

We don't have per-zone time information for main thread GC time, so we estimate
proportionally based on the zone's initial size. The patch records per-zone
sweeping time and includes that in the calculation. Compacting time is not
included since that is relatively rare and will skew the result.

Depends on D152864

Calculate the allocation rate per zone. This requires remembering the previous
heap size and also tracking the amouth of memory freed in the mean time.

This uses an exponential moving average to smooth the result but with a much
lower factor, so that the allocation rate decays slowly when a zone stops

Depends on D152865

This patch adds the calculation of the heap limit based on the formula from the paper.

Depends on D152866

Once a second, update the heap limits based on the current allocation rate.
When zones become inactive the allocation rate falls and so does the heap
limit. This results in use collecting idle zones and relaiming memory.

To update the allocation rate periodically we need to use a timer.
Unfortunately we don't have that facility in SpiderMonkey itself so we have to
add some embedding callbacks to let us do this.

I found it was simpler to add callbacks to start and cancel a timer rather than
having a public API and telling the embedding to call it periodically.

The timer is used to update the heap limits once per second, except when the
allocation rate on all zones falls low enough, in which case it is restarted on
the next minor GC.

GCs triggered by reducing heap limits get their own GC reason.

This is only implemented in the browser. I'm not sure it's worth implementing
for the shell. Heap limits are still updated on GC start.

Depends on D152867

I plan to land this preffed off and enable it in a separate bug.

Pushed by
Part 1: Add a GC parameter to enable or disable balanced heap limits r=sfink
Part 2: Add a GC parameter for the heap growth factor used when balanced heap limits are enabled r=sfink
Part 3: Add browser prefs for the new GC parameters r=mccr8,sfink
Part 4: Calculate the garbage collection rate r=sfink
Part 5: Calculate the allocation rate r=sfink
Part 6: Calculate balanced heap limits r=sfink
Regressions: 1791887
You need to log in before you can comment on or make changes to this bug.