You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can not set TOTAL_MEMORY greater than 2Gb or expand the memory to greater than 2Gb #6566
We are using emscripten to compile to WebAssembly and are hitting a memory problem. Our application can sometime require more than 2Gb of memory. By setting the -s ALLOW_MEMORY_GROWTH=1 the memory expands but then it falls over when it tries to expand beyond 2Gb.
I have also tried to set the -s TOTAL_MEMORY to greater than 2Gb ( -s TOTAL_MEMORY=3221225472). This gives the compilation error:
"Error: total memory size 2147483647 is not a multiple of the 64k wasm page size"
So it seems that trying to set TOTAL_MEMORY to greater then 2Gb actually sets it to 1byte less than 2Gb which gives the error.
Is there a way to use more memory with WebAssembly? Is the 2Gb a fundamental limit or will more memory be able to be used in future releases?
Also maybe a better error message should be returned when trying to set TOTAL_MEMORY to greater than 2Gb.
We are testing with Chrome, the full compiler setting are:
"-s WASM=1 -s NO_EXIT_RUNTIME=1 --bind -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 -s TOTAL_MEMORY=1073741824"
In theory there should be no limit, but in practice, 2GB is a practical limit because many (all?) browsers apply that limit, in particular I know Chrome and Firefox do.
This should get fixed eventually once browsers get around to it. First, 2GB => 4GB is just a bugfix they need to do. Second, wasm64 will allow accessing more than 4GB by design.
I agree that error message is not very informative. I believe it's coming from Chrome, so might be worth also filing there. I also opened #6568 to add a warning in emscripten, but it's possible the browser will hit an error before that gets the chance to be shown...
With respect to the error message "Error: total memory size 2147483647 is not a multiple of the 64k wasm page size", this is coming from the emscripten not from chrome.
The main PRs for this have landed, and so heaps 2GB and larger are now supported. You just need to set MAXIMUM_MEMORY to a size like that, and with growth it can grow to there.
Activity
kripken commentedon May 22, 2018
In theory there should be no limit, but in practice, 2GB is a practical limit because many (all?) browsers apply that limit, in particular I know Chrome and Firefox do.
This should get fixed eventually once browsers get around to it. First, 2GB => 4GB is just a bugfix they need to do. Second, wasm64 will allow accessing more than 4GB by design.
I agree that error message is not very informative. I believe it's coming from Chrome, so might be worth also filing there. I also opened #6568 to add a warning in emscripten, but it's possible the browser will hit an error before that gets the chance to be shown...
DrJohnDale commentedon May 23, 2018
Thank you for the reply, this is helpful to know.
With respect to the error message "Error: total memory size 2147483647 is not a multiple of the 64k wasm page size", this is coming from the emscripten not from chrome.
kripken commentedon May 23, 2018
Thanks, I did a search and didn't find the message, but looking some more I see it's in Binaryen, https://github.com/WebAssembly/binaryen/blob/master/src/wasm-js.cpp#L76 I'll look into improving it.
evanw commentedon Feb 26, 2020
@kripken Would it be possible to re-open this issue now that https://bugs.chromium.org/p/v8/issues/detail?id=7881 has been fixed? I am interested in tracking the progress of enabling a 4gb maximum memory limit in emscripten, but I didn't see an existing issue for tracking this yet.
kripken commentedon Feb 26, 2020
Good idea @evanw , I'm working on toolchain support for 4GB now (following that V8 work), and this looks like the best issue to track, reopening.
Make sbrk() compatible with 2GB+ heaps (#10600)
Add internal CAN_ADDRESS_2GB flag which is set for 2GB+ heap support (#…
JS library fixes for 2GB+ heaps (#10602)
kripken commentedon Mar 27, 2020
The main PRs for this have landed, and so heaps 2GB and larger are now supported. You just need to set
MAXIMUM_MEMORYto a size like that, and with growth it can grow to there.