Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable shrunk memory by default and add related configurations #4008

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ if (WAMR_BUILD_LINUX_PERF EQUAL 1)
endif ()
endif ()

if (NOT DEFINED WAMR_BUILD_SHRUNK_MEMORY)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're adding a new build options, I think it'd be good to have a relevant documentation in one of the markdown files too. Could you add it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made updates. Please let me know if you have any further comments.

# Enable shrunk memory by default
set (WAMR_BUILD_SHRUNK_MEMORY 1)
endif ()

########################################

message ("-- Build Configurations:")
Expand Down Expand Up @@ -599,3 +604,10 @@ endif()
if (NOT WAMR_BUILD_SANITIZER STREQUAL "")
message (" Sanitizer ${WAMR_BUILD_SANITIZER} enabled")
endif ()
if (WAMR_BUILD_SHRUNK_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=1)
message (" Shrunk memory enabled")
else ()
add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=0)
message (" Shrunk memory disable")
endif ()
4 changes: 4 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,8 @@
#define WASM_ENABLE_SHARED_HEAP 0
#endif

#ifndef WASM_ENABLE_SHRUNK_MEMORY
#define WASM_ENABLE_SHRUNK_MEMORY 1
#endif

#endif /* end of _CONFIG_H_ */
8 changes: 6 additions & 2 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6159,6 +6159,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
WASMMemoryImport *memory_import;
WASMMemory *memory;

#if WASM_ENABLE_SHRUNK_MEMORY != 0
if (aux_data_end_global && aux_heap_base_global
&& aux_stack_top_global) {
uint64 init_memory_size;
Expand Down Expand Up @@ -6196,6 +6197,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}
}
}
#endif

#if WASM_ENABLE_MULTI_MODULE == 0
if (module->import_memory_count) {
Expand Down Expand Up @@ -10021,7 +10023,8 @@ check_memory_access_align(uint8 opcode, uint32 align, char *error_buf,
bh_assert(opcode >= WASM_OP_I32_LOAD && opcode <= WASM_OP_I64_STORE32);
if (align > mem_access_aligns[opcode - WASM_OP_I32_LOAD]) {
set_error_buf(error_buf, error_buf_size,
"alignment must not be larger than natural");
"invalid memop flags: alignment must not be larger "
"than natural");
return false;
}
return true;
Expand Down Expand Up @@ -10060,7 +10063,8 @@ check_simd_memory_access_align(uint8 opcode, uint32 align, char *error_buf,
&& align > mem_access_aligns_load_lane[opcode
- SIMD_v128_load8_lane])) {
set_error_buf(error_buf, error_buf_size,
"alignment must not be larger than natural");
"invalid memop flags: alignment must not be larger "
"than natural");
return false;
}

Expand Down
106 changes: 55 additions & 51 deletions doc/build_wamr.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/memory_tune.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Normally there are some methods to tune the memory usage:
- use XIP mode, refer to [WAMR XIP (Execution In Place) feature introduction](./xip.md) for more details
- when using the Wasm C API in fast interpreter or AOT mode, set `clone_wasm_binary=false` in `LoadArgs` and free the wasm binary buffer (with `wasm_byte_vec_delete`) after module loading; `wasm_module_is_underlying_binary_freeable` can be queried to check if the wasm binary buffer can be safely freed (see [the example](../samples/basic/src/free_buffer_early.c)); after the buffer is freed, `wasm_runtime_get_custom_section` cannot be called anymore
- when using the wasm/AOT loader in fast interpreter or AOT mode, set `wasm_binary_freeable=true` in `LoadArgs` and free the wasm binary buffer (with `wasm_byte_vec_delete`) after module loading; `wasm_runtime_is_underlying_binary_freeable` can be queried to check if the wasm binary buffer can be safely freed; after the buffer is freed, `wasm_runtime_get_custom_section` cannot be called anymore
- `WAMR_BUILD_SHRUNK_MEMORY` can be used to reduce the memory usage of WAMR, but it might affect the standard expected behavior of WAMR.
Loading
Loading