Stream: git-wasmtime

Topic: wasmtime / issue #3040 Add memory limit per `Store`


view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 15:53):

bkolobara opened issue #3040:

Is it possible to add a memory limit to a Store, similar to the fuel limit?

I'm building a platform for running untrusted Wasm code and I need to limit the memory usage of a particular Store (heap & tables). It could work similar to the fuel property, if a memory limit is reached the call to a Wasm function would trap.

Currently I'm working around it by forcing users to import a memory and table, but that's not ideal because you can't use multi-memory/table modules and there is no way to enforce table + heap < max_memory, only table < max_table && heap < max_heap

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 16:43):

peterhuene commented on issue #3040:

Hi @bkolobara.

While it doesn't inherently trap, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.

If the resource limiter prevents the requested operation, the memory.grow and table.grow instructions will behave as if limits have been reached, at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.

Would that suffice for your use-case or would additional functionality be needed?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 16:44):

peterhuene edited a comment on issue #3040:

Hi @bkolobara.

While it doesn't inherently trap, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.

If the resource limiter prevents the requested operation, the memory.grow and table.grow instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.

Would that suffice for your use-case or would additional functionality be needed?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 16:45):

peterhuene edited a comment on issue #3040:

Hi @bkolobara.

While it doesn't inherently trap on reached limits, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.

If the resource limiter prevents the requested operation, the memory.grow and table.grow instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in low-memory conditions.

Would that suffice for your use-case or would additional functionality be needed?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 16:45):

peterhuene edited a comment on issue #3040:

Hi @bkolobara.

While it doesn't inherently trap on reached limits, Store::limiter can be used to configure a resource limiter for the store that will be notified for any attempt to grow a linear memory or table in the store.

If the resource limiter prevents the requested operation, the memory.grow and table.grow instructions will behave as if limits have been reached (i.e. return -1), at which point it's up to the Wasm program to handle it, either by trapping or internally GC'ing or whatever it wants to do in out-of-memory conditions.

Would that suffice for your use-case or would additional functionality be needed?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 17:07):

bkolobara commented on issue #3040:

This is exactly what I need. I keep looking at the docs every day, but somehow missed this limiter :)

Thanks @peterhuene!

view this post on Zulip Wasmtime GitHub notifications bot (Jun 29 2021 at 17:07):

bkolobara closed issue #3040:

Is it possible to add a memory limit to a Store, similar to the fuel limit?

I'm building a platform for running untrusted Wasm code and I need to limit the memory usage of a particular Store (heap & tables). It could work similar to the fuel property, if a memory limit is reached the call to a Wasm function would trap.

Currently I'm working around it by forcing users to import a memory and table, but that's not ideal because you can't use multi-memory/table modules and there is no way to enforce table + heap < max_memory, only table < max_table && heap < max_heap


Last updated: Nov 22 2024 at 17:03 UTC