What would be the best way to get memory currently used by the wasm? Right now the only thing that comes into my mind is subtracting the last offset I get from my wasm program from the base pointer of the data
From the guest or the host?
This would be from the host. Interested in the size of the current mem used by my wasm sandbox
I have this snippet, which sums the size of linear memories owned by a wasmtime::Instance
let memories = instance
.exports(&mut store)
.flat_map(|export| export.into_memory())
.collect::<Vec<_>>();
let memory_used = &memories
.into_iter()
.map(|mem| mem.size(&store))
.sum::<u64>();
I don't recall exactly why it has to be so convoluted... maybe because of how it borrows store
? :thinking:
Oh and that count is wasm pages, so * 64KB for bytes
thank you for the code! Very sorry I didn't explain it properly. Not looking for the page size but memory in use by the sandbox so I guess this would be less than or equal to the size of the sandbox
There isn't one clear answer to your question. Some of the resources used by an instance will be shared across all instances or all instances of a single module.
I don't think there are any global statistics for memory usage tracked by wasmtime
I see, I think the best I can do right now is try to get an estimate, I will do more research on this. Thank you
For tracking wasm memory used within a Store
you can use the Store::limiter
interface which will get notified when wasm grows memory
Last updated: Dec 23 2024 at 14:03 UTC