Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm: Improve support of embedded systems with limited RAM #1694

Open
vshymanskyy opened this issue Mar 6, 2021 · 4 comments
Open

Wasm: Improve support of embedded systems with limited RAM #1694

vshymanskyy opened this issue Mar 6, 2021 · 4 comments
Labels
wasm WebAssembly

Comments

@vshymanskyy
Copy link

The motivation about this request is the same, as described here: AssemblyScript/assemblyscript#1089

Previously, we were using -heap-size 4096 to limit the (physically) required amount of linear memory.
-heap-size was removed in #1567 , and now the default heap allocator is using the whole page (64KB) of memory.

P.S. Yes, TinyGo compiled to wasm can run on systems with as little as 16 KB of RAM 😎 .
Example: https://github.com/wasm3/wasm3-arduino/tree/master/wasm_apps/tinygo

@aykevl
Copy link
Member

aykevl commented Mar 7, 2021

Previously, we were using -heap-size 4096 to limit the (physically) required amount of linear memory.
-heap-size was removed in #1567 , and now the default heap allocator is using the whole page (64KB) of memory.

Actually, -heap-size=4096 would have allocated 64kB of RAM because that's the page size of WebAssembly, so nothing has changed here. The only difference is that it can now grow beyond that instead of being limited to 64kB. Maybe it just appeared to work before because the application didn't allocate a lot of memory?

@vshymanskyy
Copy link
Author

vshymanskyy commented Mar 10, 2021

@aykevl sorry I got sick ;(
I'll need to dig into this further, but I'm pretty sure on 0.12.0 there was a difference between -heap-size=4096 and, say -heap-size=61440.
Quick question: does the allocator try to put any internal markers or access memory on high addresses, maybe during the initialization?
I'll try to provide a backtrace with 0.17.0 ASAP

@aykevl
Copy link
Member

aykevl commented Mar 10, 2021

I'll need to dig into this further, but I'm pretty sure on 0.12.0 there was a difference between -heap-size=4096 and, say -heap-size=61440.

I'm pretty sure it did not, because it would round the number up to 64K bytes. A non-rounded number would not have been accepted by the WebAssembly linker.

Quick question: does the allocator try to put any internal markers or access memory on high addresses, maybe during the initialization?

Ah, I see. Yes, the first commit of #1567 moved the heap metadata from the start of the heap to the end of the heap. So I'm guessing it worked by accident before that PR because not much memory was allocated, but that PR broke it by moving the metadata to higher addresses.

As a workaround, you could use -gc=leaking which does not attempt to free any memory and also doesn't track which block of memory are allocated (apart from the "start of free area" pointer).

I'm not sure how this can be best solved, it's a rather specific use case after all. Note that you can also use TinyGo directly on many of the chips supported by wasm3, and I think that would be the preferred solution in most cases.

@vshymanskyy
Copy link
Author

vshymanskyy commented Mar 10, 2021 via email

@deadprogram deadprogram added the wasm WebAssembly label Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

3 participants