Skip to content

Conversation

@no1wudi
Copy link
Collaborator

@no1wudi no1wudi commented Aug 30, 2022

No description provided.

}

extern void *
gc_heap_stats(void *heap, uint32 *stats, int size);
Copy link
Collaborator

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);

Copy link
Collaborator Author

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

Copy link
Collaborator

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

extern void *
gc_heap_stats(void *heap, uint32 *stats, int size);

int
Copy link
Collaborator

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

wasm_runtime_mallinfo(mem_mallinfo_t *mall)
{
if (memory_mode == MEMORY_MODE_POOL) {
gc_heap_stats(pool_allocator, mall->info, 3);
Copy link
Collaborator

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);

Comment on lines 125 to 134
typedef union {
struct {
uint32_t info[3];
};
struct {
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
};
} mem_mallinfo_t;
Copy link
Collaborator

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;

* Get memory info, only pool mode supported now.
*/
WASM_RUNTIME_API_EXTERN int
wasm_runtime_mallinfo(mem_mallinfo_t *mall);
Copy link
Collaborator

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);

@no1wudi no1wudi force-pushed the main branch 2 times, most recently from d51f3ca to b5b5ad1 Compare August 30, 2022 09:38
#include "wasm_runtime_common.h"
#include "bh_platform.h"
#include "mem_alloc.h"
#include "ems/ems_gc.h"
Copy link
Collaborator

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

{
if (memory_mode == MEMORY_MODE_POOL) {
return mem_allocator_get_alloc_info(pool_allocator, mem_alloc_info);
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove unused line

wasm_runtime_free(void *ptr);

/*
* Get memory info, only pool mode supported now.
Copy link
Collaborator

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>
@wenyongh wenyongh merged commit 77c516a into bytecodealliance:main Aug 31, 2022
wenyongh added a commit to wenyongh/wasm-micro-runtime that referenced this pull request Aug 31, 2022
Add a new API to get free memory in memory pool (bytecodealliance#1430)
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants