Skip to content

Can not set TOTAL_MEMORY greater than 2Gb or expand the memory to greater than 2Gb #6566

Closed

Description

@DrJohnDale

Hi,

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"

Cheers.

Activity

  1. kripken commented on May 22, 2018

    @kripken
    Member

    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...

  2. DrJohnDale commented on May 23, 2018

    @DrJohnDale
    Author

    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.

  3. kripken commented on May 23, 2018

    @kripken
    Member

    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.

  4. evanw commented on Feb 26, 2020

    @evanw
    Contributor

    @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.

  5. kripken commented on Feb 26, 2020

    @kripken
    Member

    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.

  6. kripken commented on Mar 27, 2020

    @kripken
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions