Allow overriding max memory on module instantiation (#3198)

This PR adds a max_memory_pages parameter to module instantiation APIs,
to allow overriding the max memory defined in the WASM module.

Sticking to the max memory defined in the module is quite limiting when
using shared memory in production. If targeted devices have different
memory constraints, many wasm files have to be generated with different
max memory values. And device constraints may not be known in advance.

Being able to set the max memory value during module instantiation allows
to reuse the same wasm module, e.g. by retrying instantiation with different
max memory value.
This commit is contained in:
Enrico Loparco
2024-03-05 10:53:26 +01:00
committed by GitHub
parent 0e8d949440
commit 7692f32a94
15 changed files with 284 additions and 163 deletions

View File

@ -561,13 +561,18 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
WASM_RUNTIME_API_EXTERN void
wasm_runtime_unload(WASMModuleCommon *module);
/* Internal API */
uint32
wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
uint32 module_max_page_count);
/* Internal API */
WASMModuleInstanceCommon *
wasm_runtime_instantiate_internal(WASMModuleCommon *module,
WASMModuleInstanceCommon *parent,
WASMExecEnv *exec_env_main, uint32 stack_size,
uint32 heap_size, char *error_buf,
uint32 error_buf_size);
uint32 heap_size, uint32 max_memory_pages,
char *error_buf, uint32 error_buf_size);
/* Internal API */
void
@ -580,6 +585,12 @@ wasm_runtime_instantiate(WASMModuleCommon *module, uint32 default_stack_size,
uint32 host_managed_heap_size, char *error_buf,
uint32 error_buf_size);
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
wasm_runtime_instantiate_ex(WASMModuleCommon *module,
const InstantiationArgs *args, char *error_buf,
uint32 error_buf_size);
/* See wasm_export.h for description */
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
@ -887,7 +898,8 @@ bool
wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
WASMModuleInstanceCommon *module_inst,
uint32 stack_size, uint32 heap_size,
char *error_buf, uint32 error_buf_size);
uint32 max_memory_pages, char *error_buf,
uint32 error_buf_size);
void
wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
#endif