-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
proposal: cmd/link: add wasminitmem and wasmmaxmem params #69018
Comments
If we do this, it would probably be One question is whether these settings are better to be per-build or per-program. If it is per-program, i.e. for the same program you'd expect the same setting in most cases, maybe it can be directives in the main package, like While Wasm does allow setting max memory at build time, would it make sense to be a run time setting? (The initial memory size would have to be a build time setting.) Could you explain more about your use cases? So we can see what is the best option here. Thanks. |
cc @golang/wasm |
@cherrymui thank you
good point
I agree with you that per-build settings (i.e. linker flags) are more flexible, I would be prefer this
You are right, max memory can be set in runtime, so this setting in the linker is not so important, but initial memory is necessary
My users write small functions for data processing, my service compiles it into wasi and executes it. These are often very small functions that only need 2MB of memory, but |
Is there an opportunity to just adjust the initial memory down? I don't know why it's high by default if we can allocate more as we go. |
Currently it is set to the size of all global data + 16 MB. From the comment it is enough for the runtime to initialize without growing memory. I suppose we can lower it, though I'm not sure if we can grow memory at very early stage of runtime initialization. If we lower the default, I think we still need the flag, so users who want the old behavior can change it back. If the initial memory is set to be smaller than the global data size, it probably won't work. So we probably require it to be bigger than data size. |
If we need max maybe the flags should be wasmminmem and wasmmaxmem. |
This proposal has been added to the active column of the proposals project |
Retitled to be -wasminitmem and -wasmmaxmem. Any other comments? |
What's the use case for setting the maximum memory? What's the downside of the linker just defaulting to a lower initial memory? One thing I'm a bit confused about: simply initializing the runtime requires some heap allocation, which I thought would force the wasm linear memory to immediately grow to some non-trivial size. Is that not the case? |
Setting a maximum size on memory is a thing you can do to control the memory footprint, especially since engines can use different allocation strategies when they know the memory can't grow beyond a certain point. For example, an engine may be able to reserve the maximum size up front so that Also, |
Proposal Details
Hello!
The problem
I am compiling my application to
GOOS=wasip1 GOARCH=wasm
and I want to control the wasm memory more accurate.wasm-ld
provides the following parameters for this:But
go tool link
doesn't allow me to set these values. And I cannot use the wasm-ld because-linkmode=external
requires CGO but CGO doesn't support wasm.Proposal
I propose to add the
initial-memory
andmax-memory
cli-parameters togo tool link
Solving
I think that a solving is not too hard and I wish I could help. I expect that the edit should be to pass a couple of constants from the cli-parameters to the module that is responsible for initial memory and max memory. But I looked into the linker code and didn't find where these values are set. Maybe you can tell me how best to solve this task.
The text was updated successfully, but these errors were encountered: