Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Wasm: LOH objects seem to consume more memory than expected #8327

Open
yowl opened this issue Sep 14, 2020 · 0 comments
Open

Wasm: LOH objects seem to consume more memory than expected #8327

yowl opened this issue Sep 14, 2020 · 0 comments

Comments

@yowl
Copy link
Contributor

yowl commented Sep 14, 2020

The following code results in emscripten running out of memory

        var mr = new MiniRandom(257);
        var keptObjects = new object[1000];
        for (var i = 0; i < 1000000; i++)
        {
            var r = mr.Next();
            object o;
            o = new long[20000]; // large object heap, 160000 > 85KB
            keptObjects[r % 1000] = o;
        }

This should only be around 160,012,000 bytes, but it appears to go over 2GB

emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
Failed to grow the heap from 2130444288 bytes to 2147483648 bytes, not enough memory!
emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
emscripten_realloc_buffer: Attempted to grow heap from 2130444288 bytes to 2147483648 bytes, but got error: RangeError: WebAssembly.Memory.grow(): Maximum memory size exceeded
Failed to grow the heap from 2130444288 bytes to 2147483648 bytes, not enough memory!
Assertion failed: ret == 0, at: E:\GitHub\corert\src\Native\gc\unix\gcenv.unix.cpp,627,VirtualReserveInner
exception thrown: RuntimeError: abort(Assertion failed: ret == 0, at: E:\GitHub\corert\src\Native\gc\unix\gcenv.unix.cpp,627,VirtualReserveInner) at Error
    at jsStackTrace (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2079:19)
    at stackTrace (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2096:16)
    at abort (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:1796:44)
    at ___assert_fail (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2570:7)
    at VirtualReserveInner(unsigned long, unsigned long, unsigned int, unsigned int) (wasm-function[22264]:0x105b320)
    at GCToOSInterface::VirtualReserve(unsigned long, unsigned long, unsigned int, unsigned short) (wasm-function[22263]:0x105b01e)
    at WKS::gc_heap::grow_brick_card_tables(unsigned char*, unsigned char*, unsigned long, WKS::heap_segment*, WKS::gc_heap*, int) (wasm-function[21342]:0xf6aee1)
    at WKS::gc_heap::get_segment(unsigned long, WKS::gc_oh_num) (wasm-function[21321]:0xf6661c)
    at WKS::gc_heap::get_segment_for_uoh(int, unsigned long) (wasm-function[21358]:0xf6cc33)
    at WKS::gc_heap::get_uoh_segment(int, unsigned long, int*) (wasm-function[21360]:0xf6d7b0),RuntimeError: abort(Assertion failed: ret == 0, at: E:\GitHub\corert\src\Native\gc\unix\gcenv.unix.cpp,627,VirtualReserveInner) at Error
    at jsStackTrace (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2079:19)
    at stackTrace (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2096:16)
    at abort (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:1796:44)
    at ___assert_fail (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2570:7)
    at VirtualReserveInner(unsigned long, unsigned long, unsigned int, unsigned int) (wasm-function[22264]:0x105b320)
    at GCToOSInterface::VirtualReserve(unsigned long, unsigned long, unsigned int, unsigned short) (wasm-function[22263]:0x105b01e)
    at WKS::gc_heap::grow_brick_card_tables(unsigned char*, unsigned char*, unsigned long, WKS::heap_segment*, WKS::gc_heap*, int) (wasm-function[21342]:0xf6aee1)
    at WKS::gc_heap::get_segment(unsigned long, WKS::gc_oh_num) (wasm-function[21321]:0xf6661c)
    at WKS::gc_heap::get_segment_for_uoh(int, unsigned long) (wasm-function[21358]:0xf6cc33)
    at WKS::gc_heap::get_uoh_segment(int, unsigned long, int*) (wasm-function[21360]:0xf6d7b0)
    at abort (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:1802:11)
    at ___assert_fail (E:\github\corert\tests\src\Simple\HelloWasm\bin\Debug\wasm\native\HelloWasm.js:2570:7)
    at VirtualReserveInner(unsigned long, unsigned long, unsigned int, unsigned int) (wasm-function[22264]:0x105b320)
    at GCToOSInterface::VirtualReserve(unsigned long, unsigned long, unsigned int, unsigned short) (wasm-function[22263]:0x105b01e)
    at WKS::gc_heap::grow_brick_card_tables(unsigned char*, unsigned char*, unsigned long, WKS::heap_segment*, WKS::gc_heap*, int) (wasm-function[21342]:0xf6aee1)
    at WKS::gc_heap::get_segment(unsigned long, WKS::gc_oh_num) (wasm-function[21321]:0xf6661c)
    at WKS::gc_heap::get_segment_for_uoh(int, unsigned long) (wasm-function[21358]:0xf6cc33)
    at WKS::gc_heap::get_uoh_segment(int, unsigned long, int*) (wasm-function[21360]:0xf6d7b0)
    at WKS::gc_heap::uoh_get_new_seg(int, unsigned long, int*, oom_reason*) (wasm-function[21549]:0xf9b385)
    at WKS::gc_heap::allocate_uoh(int, unsigned long, alloc_context*, unsigned int, int) (wasm-function[21553]:0xf9d6dc)

If the large arrays are not stored then this code completes, so it appears collection is at least occurring sometimes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant