-
Notifications
You must be signed in to change notification settings - Fork 749
Add a new API to get free mem in mempool #1430
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
Conversation
core/iwasm/common/wasm_memory.c
Outdated
| } | ||
|
|
||
| extern void * | ||
| gc_heap_stats(void *heap, uint32 *stats, int size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a good coding custom, had better implement the API in mem alloc layer, how about:
define struct and implement API in core/shared/mem-alloc/mem_alloc.{hc}:
typedef struct mem_alloc_info_t {
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
} mem_alloc_info_t;
bool
mem_allocator_get_alloc_info(mem_allocator_t allocator, mem_alloc_info_t *mem_alloc_info);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This typedef is dupped with wasm_export.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using a macro to control it (like MEM_ALLOC_OPTION_DEFINED): in wasm_export.h and mem_alloc.h, add:
#ifndef MEM_ALLOC_INFO_DEFINED
#define MEM_ALLOC_INFO_DEFINED
typedef struct mem_alloc_info_t {
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
} mem_alloc_info_t;
#endif
core/iwasm/common/wasm_memory.c
Outdated
| extern void * | ||
| gc_heap_stats(void *heap, uint32 *stats, int size); | ||
|
|
||
| int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better return bool, like other APIs in wasm_export.h
core/iwasm/common/wasm_memory.c
Outdated
| wasm_runtime_mallinfo(mem_mallinfo_t *mall) | ||
| { | ||
| if (memory_mode == MEMORY_MODE_POOL) { | ||
| gc_heap_stats(pool_allocator, mall->info, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return mem_allocator_get_alloc_info(pool_allocator, mem_alloc_info);
core/iwasm/include/wasm_export.h
Outdated
| typedef union { | ||
| struct { | ||
| uint32_t info[3]; | ||
| }; | ||
| struct { | ||
| uint32_t total_size; | ||
| uint32_t total_free_size; | ||
| uint32_t highmark_size; | ||
| }; | ||
| } mem_mallinfo_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
typedef struct mem_alloc_info_t {
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
} mem_alloc_info_t;
core/iwasm/include/wasm_export.h
Outdated
| * Get memory info, only pool mode supported now. | ||
| */ | ||
| WASM_RUNTIME_API_EXTERN int | ||
| wasm_runtime_mallinfo(mem_mallinfo_t *mall); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);d51f3ca to
b5b5ad1
Compare
core/iwasm/common/wasm_memory.c
Outdated
| #include "wasm_runtime_common.h" | ||
| #include "bh_platform.h" | ||
| #include "mem_alloc.h" | ||
| #include "ems/ems_gc.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include ems_gc.h
core/iwasm/common/wasm_memory.c
Outdated
| { | ||
| if (memory_mode == MEMORY_MODE_POOL) { | ||
| return mem_allocator_get_alloc_info(pool_allocator, mem_alloc_info); | ||
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused line
core/iwasm/include/wasm_export.h
Outdated
| wasm_runtime_free(void *ptr); | ||
|
|
||
| /* | ||
| * Get memory info, only pool mode supported now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had better change supported to is supported
Signed-off-by: Huang Qi <huangqi3@xiaomi.com> Change-Id: I4c825661fbcc8208b9c6c6b4668ef2fb8836087e
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
Add a new API to get free memory in memory pool (bytecodealliance#1430)
No description provided.