wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

`-W max-table-elements` has no effect for `wasmtime serve`

Open dicej opened this issue 1 year ago • 2 comments

While working on resource support for the C# wit-bindgen generator, I created an example app targeting wasi:http/[email protected]. However, wasmtime serve couldn't run it due to one of the tables containing more than 10000 entries:

 $ wasmtime serve target/stripped.wasm 
Error: table index 0 has a minimum element size of 10511 which exceeds the limit of 10000

Next, I tried wasmtime serve -W max-table-elements=20000 target/stripped.wasm instead, but got the same error. Looking at the code, it seems that the pooling allocator is enabled by default for wasmtime serve, and since it has its own configuration knobs which are not controlled by e.g. -W max-table-elements, there's no way to change the limit from its default. There's also no way I can see to disable the pooling allocator, given that the only reference to the --pooling-allocator option is in old_cli.rs, which is disabled in the default build.

I'd suggest that -W options such as max-table-elements should be applied to the pooling allocator when it is enabled. ~~We might also consider raising the default considering that even simple C# apps tend to exceed it (although we could instead consider that a bug in the C# Native AOT compiler, e.g. insufficient dead code elimination?).~~ EDIT: I was building with -c Debug; the release build results in a table about half the size, which is well under the current default limit.

dicej avatar Apr 29 '24 20:04 dicej

As I noted in my edit above, building the C# app using -c Release ensured that the max table size in the component was well under the default limit, but then I ran into what appears to be an allocation failure during .NET runtime initialization, possibly due to the default memory pages limit being lower than what the .NET runtime needs. I'm going to test that theory using a custom build and report back here.

dicej avatar Apr 29 '24 21:04 dicej

Indeed, setting the memory pages limit to 1600 (i.e. 100MiB) allows the app the run without trapping.

dicej avatar Apr 30 '24 02:04 dicej