User defined memory allocator for different purposes (#3316)
Some issues are related with memory fragmentation, which may cause the linear memory cannot be allocated. In WAMR, the memory managed by the system is often trivial, but linear memory usually directly allocates a large block and often remains unchanged for a long time. Their sensitivity and contribution to fragmentation are different, which is suitable for different allocation strategies. If we can control the linear memory's allocation, do not make it from system heap, the overhead of heap management might be avoided. Add `mem_alloc_usage_t usage` as the first argument for user defined malloc/realloc/free functions when `WAMR_BUILD_ALLOC_WITH_USAGE` cmake variable is set as 1, and make passing `Alloc_For_LinearMemory` to the argument when allocating the linear memory.
This commit is contained in:
committed by
GitHub
parent
68bd30c6f9
commit
ba59e56e19
@ -129,6 +129,10 @@ if(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL)
|
||||
set(WAMR_BUILD_GLOBAL_HEAP_SIZE ${_HEAP_SIZE_})
|
||||
endif()
|
||||
|
||||
if (CONFIG_INTERPRETERS_WAMR_MEM_ALLOC_WITH_USAGE)
|
||||
set(WAMR_BUILD_MEM_ALLOC_WITH_USAGE 1)
|
||||
endif()
|
||||
|
||||
if(CONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST)
|
||||
set(WAMR_BUILD_SPEC_TEST 1)
|
||||
endif()
|
||||
|
||||
@ -373,6 +373,11 @@ CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=1
|
||||
CFLAGS += -DWASM_GLOBAL_HEAP_SIZE="$(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL_SIZE) * 1024"
|
||||
else
|
||||
CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=0
|
||||
ifeq ($(CONFIG_INTERPRETERS_WAMR_MEM_ALLOC_WITH_USAGE),y)
|
||||
CFLAGS += -DWASM_MEM_ALLOC_WITH_USAGE=1
|
||||
else
|
||||
CFLAGS += -DWASM_MEM_ALLOC_WITH_USAGE=0
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST),y)
|
||||
|
||||
@ -445,6 +445,9 @@ static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
|
||||
#else
|
||||
static void *
|
||||
malloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USAGE != 0
|
||||
mem_alloc_usage_t usage,
|
||||
#endif
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
@ -455,6 +458,9 @@ malloc_func(
|
||||
|
||||
static void *
|
||||
realloc_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USAGE != 0
|
||||
mem_alloc_usage_t usage, bool full_size_mmaped,
|
||||
#endif
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
@ -465,6 +471,9 @@ realloc_func(
|
||||
|
||||
static void
|
||||
free_func(
|
||||
#if WASM_MEM_ALLOC_WITH_USAGE != 0
|
||||
mem_alloc_usage_t usage,
|
||||
#endif
|
||||
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
|
||||
void *user_data,
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user