Closed Bug 1855732 Opened 2 years ago Closed 2 years ago

Make wasm-gc trailer sizes available to the tenured-heap's when-to-GC decision-making machinery

Categories

(Core :: JavaScript: WebAssembly, defect)

defect

Tracking

()

RESOLVED FIXED
120 Branch
Tracking Status
firefox120 --- fixed

People

(Reporter: bvisness, Assigned: jseward)

References

Details

Attachments

(5 files)

Some elements of the Kotlin wasm benchmark suite allocate ridiculous amounts of memory (hundreds of gigabytes on my machine). V8 does not suffer the same.

For example, you can clone https://github.com/bvisness/kotlin-wasm-benchmarks and run gradle jsShell_wasmSingleBenchmark to run the microBenchmarks.ClassBaselineBenchmark suite in isolation with a high iteration count. This causes large amounts of memory usage in SpiderMonkey but not V8.

Initial investigation suggests gradle jsShell_wasmSingleBenchmark uses
excessive memory while allocating gc-arrays with 80KB payload areas.
However, the following does not show the problem:

   (type $tArrayI64 (array i64))
   (func (export "go")
     (local $i i32)
     (loop $cont
       (array.new $tArrayI64 (i64.const 1337) (i32.const 10000))
       drop
       (local.set $i (i32.add (local.get $i) (i32.const 1)))
       (br_if $cont (i32.lt_u (local.get $i) (i32.const 10000000)))
     )
   )
Assignee: nobody → jseward
Attached file standalone.tar.bz2

Here's a standalone test case constructed from a snapshot of
./gradlew jsShell_wasmSingleBenchmark.
Simply untar and run the command specified in HOWTO_RUN.txt.
Does not require the Kotlin framework.

Attached file alloc_many3.js

A standalone (and minimal) test case that shows the problem and that explains why the problem happens.

Depends on: 1858200
Attachment #9358248 - Attachment is patch: false

When applied to a tree that has the fix from the now-landed bug 1858200, the
patches in comment 4 and comment 5 fix the problem on all targets and fairly
accurately show the costs entailed by the fix. However, they are excessively
complex and so are unlikely to be the final implementation.

Summary: Kotlin wasm benchmarks use too much memory → Make wasm-gc trailer sizes available to the tenured-heap's when-to-GC decision-making machinery

For trailer blocks whose owning Wasm{Struct,Array}Objects make it into the
tenured heap, we have to tell the tenured heap how big those trailers are in
order to get major GCs to happen sufficiently frequently. If we don't do
that, programs that allocate many such objects with big trailers can end up
with wildly excessive space use, because the tenured heap's when-to-GC
heuristics are unaware that each (relatively small) Wasm{Struct,Array}Object
is "shadowed" by a large amount of malloc'd space, and so major collection
happens far too infrequently.

The changes are simple -- they just notify the the tenured heap's accounting
system by calling AddCellMemory when an object enters the tenured heap and
GCContext::removeCellMemory when an object leaves the tenured heap (is
finalized).

Some comments have been updated.

As a ridealong, the bizarrely-misnamed MallocedBlockCache::allowSlow has
been renamed to ::allocSlow.

Pushed by jseward@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/069be1480d6f Make wasm-gc trailer sizes available to the tenured-heap's when-to-GC decision-making machinery. r=jonco.
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 120 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: