dylibso / chicory

Native JVM WebAssembly runtime
https://chicory.dev/
Apache License 2.0
533 stars 39 forks source link

MemoryLimits: allow to impose constraints to an instance #606

Open evacchi opened 1 month ago

evacchi commented 1 month ago

Modules are able to define their own memory constraints, but one useful feature of Wasm engines is to allow the host to control the use of resources of the guests.

We should allow end-users to refine the memory constraints of a Wasm module so that 1) we can impose finer restrictions on modules that have been compiled with default values (i.e. unrestricted limits) 2) rogue instances cannot grow their memory indefinitely

andreaTP commented 1 month ago

I'm in favor of .withMemoryFactory() :+1: as it also covers the possibility of experimenting with new JVM features and offheap memory.

evacchi commented 1 month ago

updated the top post with a reference to off-heap 👍

electrum commented 2 weeks ago

I think these are complementary features. The MemoryFactory interface would accept MemoryLimits. We shouldn't mix the allocation or access strategy with memory limits.

electrum commented 2 weeks ago

Related, I noticed that Instance.Builder#validateHostMemoryType allows MemoryLimits.MAX_PAGES (65536) and converts that to Memory.RUNTIME_MAX_PAGES (32767). But any intermediate value would fail. Is this the intended behavior?

evacchi commented 2 weeks ago
  1. TBH I'm in favor of separating the two concepts.
  2. re: Memory.RUNTIME_MAX_PAGES I don't think that's intended...