Skip to content

Commit

Permalink
in_exec_wasi: Provide configurable stack and heap sizes for Wasm
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Aug 9, 2024
1 parent 03423cf commit 68931d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
35 changes: 34 additions & 1 deletion plugins/in_exec_wasi/in_exec_wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ static int in_exec_wasi_collect(struct flb_input_instance *ins,
}
}

wasm = flb_wasm_instantiate(config, ctx->wasi_path, ctx->accessible_dir_list, -1, fileno(stdoutp), -1);
if (ctx->wasm_conf == NULL) {
flb_plg_error(ctx->ins, "wasm_conf cannot be NULL");
return -1;
}
ctx->wasm_conf->stdoutfd = fileno(stdoutp);

wasm = flb_wasm_instantiate(config, ctx->wasi_path, ctx->accessible_dir_list,
ctx->wasm_conf);
if (wasm == NULL) {
flb_plg_debug(ctx->ins, "instantiate wasm [%s] failed", ctx->wasi_path);
goto collect_end;
Expand Down Expand Up @@ -289,6 +296,7 @@ static int in_exec_wasi_init(struct flb_input_instance *in,
struct flb_config *config, void *data)
{
struct flb_exec_wasi *ctx = NULL;
struct flb_wasm_config *wasm_conf = NULL;
int ret = -1;

/* Allocate space for the configuration */
Expand Down Expand Up @@ -341,6 +349,20 @@ static int in_exec_wasi_init(struct flb_input_instance *in,
flb_plg_error(in, "could not set collector for exec input plugin");
goto init_error;
}

wasm_conf = flb_wasm_config_init(config);
if (wasm_conf == NULL) {
goto init_error;
}
ctx->wasm_conf = wasm_conf;

if (ctx->wasm_heap_size > FLB_WASM_DEFAULT_HEAP_SIZE) {
wasm_conf->heap_size = ctx->wasm_heap_size;
}
if (ctx->wasm_stack_size > FLB_WASM_DEFAULT_STACK_SIZE) {
wasm_conf->stack_size = ctx->wasm_stack_size;
}

ctx->coll_fd = ret;

return 0;
Expand Down Expand Up @@ -391,6 +413,7 @@ static int in_exec_wasi_exit(void *data, struct flb_config *config)
{
struct flb_exec_wasi *ctx = data;

flb_wasm_config_destroy(ctx->wasm_conf);
flb_wasm_destroy_all(config);
delete_exec_wasi_config(ctx);
return 0;
Expand Down Expand Up @@ -433,6 +456,16 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_exec_wasi, oneshot),
"execute the command only once"
},
{
FLB_CONFIG_MAP_SIZE, "wasm_heap_size", DEFAULT_WASM_HEAP_SIZE,
0, FLB_TRUE, offsetof(struct flb_exec_wasi, wasm_heap_size),
"Set the heap size of wasm runtime"
},
{
FLB_CONFIG_MAP_SIZE, "wasm_stack_size", DEFAULT_WASM_STACK_SIZE,
0, FLB_TRUE, offsetof(struct flb_exec_wasi, wasm_stack_size),
"Set the stack size of wasm runtime"
},
/* EOF */
{0}
};
Expand Down
6 changes: 6 additions & 0 deletions plugins/in_exec_wasi/in_exec_wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#define DEFAULT_INTERVAL_SEC "1"
#define DEFAULT_INTERVAL_NSEC "0"

#define DEFAULT_WASM_HEAP_SIZE "8192"
#define DEFAULT_WASM_STACK_SIZE "8192"

struct flb_exec_wasi {
flb_sds_t wasi_path;
struct mk_list *accessible_dir_list; /* list of directories to be
Expand All @@ -44,10 +47,13 @@ struct flb_exec_wasi {
size_t buf_size;
struct flb_input_instance *ins;
struct flb_wasm *wasm;
struct flb_wasm_config *wasm_conf;
int oneshot;
flb_pipefd_t ch_manager[2];
int interval_sec;
int interval_nsec;
size_t wasm_heap_size;
size_t wasm_stack_size;
struct flb_log_event_encoder log_encoder;
int coll_fd;
};
Expand Down

0 comments on commit 68931d1

Please sign in to comment.