Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

How to change memory limits for lucet-wasi #74

Closed
poma opened this issue Mar 29, 2019 · 6 comments
Closed

How to change memory limits for lucet-wasi #74

poma opened this issue Mar 29, 2019 · 6 comments

Comments

@poma
Copy link

poma commented Mar 29, 2019

I get the following error when trying to run my wasm app:

$ lucet-wasi demo.so
thread 'main' panicked at 'instance can be created: LimitsExceeded("heap spec initial size: HeapSpec { reserved_size: 4194304, guard_size: 4194304, initial_size: 1114112, max_size: None }")', src/libcore/result.rs:997:5

It indeed requires much more memory than that, how do I allow it to allocate more?

update: it seems that limits are specified during the compilation. I've tried to set them to 1 Gb:

lucetc --reserved-size 1073741824 --guard-size 1073741824 pedersen_demo_bg.wasm -o demo.so

But I still get the same error

@jedisct1
Copy link
Contributor

This may be related to #76.

Until this is properly fixed, you can bump up the default limit here: https://github.com/fastly/lucet/blob/63fb151565b4794b2917fa13145c9d17e0db9e32/lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs#L346

@ghost
Copy link

ghost commented Mar 29, 2019

Thanks for the report! Indeed we need to expose those as configuration parameters. I've got it going on a branch now and will update this issue when it's merged.

@poma
Copy link
Author

poma commented Mar 29, 2019

While we are at it, maybe someone knows how to correctly compile rust crates to wasm so that lucet can understand them? When I try to compile wasm file generated by wasm-pack that uses wasm-bindgen (the way I typically compile stuff for Chrome), I get an error:

$ lucetc-wasi --reserved-size 1073741824 --guard-size 1073741824 pedersen_demo_bg.wasm -o demo.so
LucetcError { inner: ErrorMessage { msg: "Unknown module for symbol `./pedersen_demo::__wbg_new_59cb74e423758ede`" }

If I comment out #[wasm_bindgen] from my entrypoint, then I get the following error when trying to execute it:

$ lucet-wasi demo.so --entrypoint main
thread 'main' panicked at 'lucet-wasi runtime error: Symbol not found: main', lucet-wasi/src/main.rs:128:23

@ghost
Copy link

ghost commented Mar 29, 2019

The way you compile things for WASI is going to be different from how you compile for the browser today, though there is a polyfill for running WASI programs in the browser as well.

To compile Rust to WASI, you'll need to use Alex's WASI fork of Rust available here: https://github.com/alexcrichton/rust/releases/tag/wasi3

Shortly after this PR is merged, you'll be able to just use a nightly compiler with --target=wasm32-unknown-wasi 🎉

ghost pushed a commit that referenced this issue Mar 29, 2019
@ghost ghost closed this as completed in #77 Mar 29, 2019
@ghost
Copy link

ghost commented Mar 29, 2019

lucet-wasi now has a few new command line arguments for setting memory limits, as well as far more generous default limits. You should now be able to just run your program without any extra specification.

In addition, if you need to specify a larger reserved size to lucetc, that argument is now --min-reserved-size.

@ghost
Copy link

ghost commented Apr 1, 2019

This is now possible, as this blog post illustrates: https://hermanradtke.com/2019/04/01/wasi-example-using-rust-and-lucet.html

Since both of the problems brought up here are now resolved, I'm going to go ahead and close this issue, but feel free to reach out if you have any more questions 🙂

This issue was closed.
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

2 participants