-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
We're embedding wasmtime to execute plugins within our application. These plugins are defined in WIT. The application instantiates multiple instances of the plugin, and drives each instance on its own Tokio task. We started seeing slow memory growth in production. This was surprising because our application is carefully designed to have very flat memory usage. It has a fixed number of Tokio tasks that only communicate with each-other using bounded queues.
When only 1 plugin executes, no memory is leaked, and the application has a flat steady-state memory usage:
When more than 1 plugin executes, the application will leak memory in WASM => HOST callbacks, e.g. 2 instances on 2 tasks was actually pretty steady for a period of time and then started leaking:
Zoomed in view of last chart:
It will sometimes start leaking right away, and other times take a while to start like the trace above. Once it starts leaking, it always continue to leak. At 4 instances (4 plugins on 4 parallel tasks) the leaks blow up immediately:
The higher the level of parallelism, the faster the leak... It feels like there's something shared between instances here that isn't thread-safe.
The leaked allocations are realloc that occurs when "lifting" a list type from WASM => host in a host callback.
Test Case
Not easy to replicate outside of our application ATM.
Steps to Reproduce
I'd like to upload the ZST traces for heaptrack, but github is blocking even a zip of them? They're large, 40-60 MB.
Versions and Environment
Wasmtime version or commit: 29.0.1
Operating system: Linux
Architecture: x86_64




