pub struct InstanceLimits {
    pub count: u32,
    pub size: usize,
    pub tables: u32,
    pub table_elements: u32,
    pub memories: u32,
    pub memory_pages: u64,
}
Expand description

Represents the limits placed on instances by the pooling instance allocator.

Fields

count: u32

The maximum number of concurrent instances supported (default is 1000).

This value has a direct impact on the amount of memory allocated by the pooling instance allocator.

The pooling instance allocator allocates three memory pools with sizes depending on this value:

  • An instance pool, where each entry in the pool can store the runtime representation of an instance, including a maximal VMContext structure.

  • A memory pool, where each entry in the pool contains the reserved address space for each linear memory supported by an instance.

  • A table pool, where each entry in the pool contains the space needed for each WebAssembly table supported by an instance (see table_elements to control the size of each table).

Additionally, this value will also control the maximum number of execution stacks allowed for asynchronous execution (one per instance), when enabled.

The memory pool will reserve a large quantity of host process address space to elide the bounds checks required for correct WebAssembly memory semantics. Even for 64-bit address spaces, the address space is limited when dealing with a large number of supported instances.

For example, on Linux x86_64, the userland address space limit is 128 TiB. That might seem like a lot, but each linear memory will reserve 6 GiB of space by default. Multiply that by the number of linear memories each instance supports and then by the number of supported instances and it becomes apparent that address space can be exhausted depending on the number of supported instances.

size: usize

The maximum size, in bytes, allocated for an instance and its VMContext.

This amount of space is pre-allocated for count number of instances and is used to store the runtime wasmtime_runtime::Instance structure along with its adjacent VMContext structure. The Instance type has a static size but VMContext is dynamically sized depending on the module being instantiated. This size limit loosely correlates to the size of the wasm module, taking into account factors such as:

  • number of functions
  • number of globals
  • number of memories
  • number of tables
  • number of function types

If the allocated size per instance is too small then instantiation of a module will fail at runtime with an error indicating how many bytes were needed. This amount of bytes are committed to memory per-instance when a pooling allocator is created.

The default value for this is 1MB.

tables: u32

The maximum number of defined tables for a module (default is 1).

This value controls the capacity of the VMTableDefinition table in each instance’s VMContext structure.

The allocated size of the table will be tables * sizeof(VMTableDefinition) for each instance regardless of how many tables are defined by an instance’s module.

table_elements: u32

The maximum table elements for any table defined in a module (default is 10000).

If a table’s minimum element limit is greater than this value, the module will fail to instantiate.

If a table’s maximum element limit is unbounded or greater than this value, the maximum will be table_elements for the purpose of any table.grow instruction.

This value is used to reserve the maximum space for each supported table; table elements are pointer-sized in the Wasmtime runtime. Therefore, the space reserved for each instance is tables * table_elements * sizeof::<*const ()>.

memories: u32

The maximum number of defined linear memories for a module (default is 1).

This value controls the capacity of the VMMemoryDefinition table in each instance’s VMContext structure.

The allocated size of the table will be memories * sizeof(VMMemoryDefinition) for each instance regardless of how many memories are defined by an instance’s module.

memory_pages: u64

The maximum number of pages for any linear memory defined in a module (default is 160).

The default of 160 means at most 10 MiB of host memory may be committed for each instance.

If a memory’s minimum page limit is greater than this value, the module will fail to instantiate.

If a memory’s maximum page limit is unbounded or greater than this value, the maximum will be memory_pages for the purpose of any memory.grow instruction.

This value is used to control the maximum accessible space for each linear memory of an instance.

The reservation size of each linear memory is controlled by the static_memory_maximum_size setting and this value cannot exceed the configured static memory maximum size.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.