Shared heap enhancements for Interpreter and AOT (#4400)
Propose two enhancements: - Shared heap created from preallocated memory buffer: The user can create a shared heap from a pre-allocated buffer and see that memory region as one large chunk; there's no need to dynamically manage it(malloc/free). The user needs to make sure the native address and size of that memory region are valid. - Introduce shared heap chain: The user can create a shared heap chain, from the wasm app point of view, it's still a continuous memory region in wasm app's point of view while in the native it can consist of multiple shared heaps (each of which is a continuous memory region). For example, one 500MB shared heap 1 and one 500 MB shared heap 2 form a chain, in Wasm's point of view, it's one 1GB shared heap. After these enhancements, the data sharing between wasm apps, and between hosts can be more efficient and flexible. Admittedly shared heap management can be more complex for users, but it's similar to the zero-overhead principle. No overhead will be imposed for the users who don't use the shared heap enhancement or don't use the shared heap at all.
This commit is contained in:
@ -55,7 +55,7 @@ thread1_callback(void *arg)
|
||||
i + 1);
|
||||
|
||||
printf("wasm app1 send buf: %s\n\n", buf);
|
||||
if (!bh_post_msg(queue, 1, buf, 1024 * i)) {
|
||||
if (!bh_post_msg(queue, 1, buf, 1024 * (i + 1))) {
|
||||
printf("Failed to post message to queue\n");
|
||||
wasm_runtime_shared_heap_free(module_inst, offset);
|
||||
break;
|
||||
@ -84,7 +84,7 @@ thread1_callback(void *arg)
|
||||
buf = wasm_runtime_addr_app_to_native(module_inst, argv[0]);
|
||||
|
||||
printf("wasm app1 send buf: %s\n\n", buf);
|
||||
if (!bh_post_msg(queue, 1, buf, 1024 * i)) {
|
||||
if (!bh_post_msg(queue, 1, buf, 1024 * (i + 1))) {
|
||||
printf("Failed to post message to queue\n");
|
||||
wasm_runtime_shared_heap_free(module_inst, argv[0]);
|
||||
break;
|
||||
@ -251,7 +251,7 @@ main(int argc, char **argv)
|
||||
heap_init_args.size = 65536;
|
||||
shared_heap = wasm_runtime_create_shared_heap(&heap_init_args);
|
||||
if (!shared_heap) {
|
||||
printf("Create shared heap failed. error: %s\n", error_buf);
|
||||
printf("Create shared heap failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* create thread 1 */
|
||||
struct thread_arg targ1 = { 0 };
|
||||
thread_arg targ1 = { 0 };
|
||||
korp_tid tid1;
|
||||
targ1.queue = queue;
|
||||
targ1.module_inst = module_inst1;
|
||||
@ -279,7 +279,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* create thread 2 */
|
||||
struct thread_arg targ2 = { 0 };
|
||||
thread_arg targ2 = { 0 };
|
||||
korp_tid tid2;
|
||||
targ2.queue = queue;
|
||||
targ2.module_inst = module_inst2;
|
||||
|
||||
Reference in New Issue
Block a user