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 5 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
2 changes: 1 addition & 1 deletion .github/workflows/spec_test_on_nuttx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
if: contains(matrix.wamr_test_option.mode, 'aot')
working-directory: apps/interpreters/wamr/wamr/wamr-compiler
run: |
cmake -Bbuild .
cmake -B build -DWAMR_BUILD_SHRUNK_MEMORY=0 -S .
cmake --build build

# the nuttx version we use for xtensa requires esptool.py newer than
Expand Down
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_ */
21 changes: 12 additions & 9 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6156,9 +6156,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}

if (!module->possible_memory_grow) {
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 All @@ -6168,7 +6166,8 @@ load_from_sections(WASMModule *module, WASMSection *sections,
* valid range of uint32 */
if (shrunk_memory_size <= UINT32_MAX) {
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
WASMMemoryImport *memory_import =
&module->import_memories[0].u.memory;
init_memory_size =
(uint64)memory_import->mem_type.num_bytes_per_page
* memory_import->mem_type.init_page_count;
Expand All @@ -6183,7 +6182,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}

if (module->memory_count) {
memory = &module->memories[0];
WASMMemory *memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
Expand All @@ -6196,10 +6195,12 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}
}
}
#endif

#if WASM_ENABLE_MULTI_MODULE == 0
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
WASMMemoryImport *memory_import =
&module->import_memories[0].u.memory;
/* Only resize the memory to one big page if num_bytes_per_page is
* in valid range of uint32 */
if (memory_import->mem_type.init_page_count < DEFAULT_MAX_PAGES) {
Expand All @@ -6215,7 +6216,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
}
}
if (module->memory_count) {
memory = &module->memories[0];
WASMMemory *memory = &module->memories[0];
/* Only resize(shrunk) the memory size if num_bytes_per_page is in
* valid range of uint32 */
if (memory->init_page_count < DEFAULT_MAX_PAGES) {
Expand Down Expand Up @@ -10021,7 +10022,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 +10062,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
Loading
Loading