Always allocate Instance memory with malloc (#5656)
This commit removes the pooling of `Instance` allocations from the pooling instance allocator. This means that the allocation of `Instance` (and `VMContext`) memory, now always happens through the system `malloc` and `free` instead of optionally being part of the pooling instance allocator. Along the way this refactors the `InstanceAllocator` trait so the pooling and on-demand allocators can share more structure with this new property of the implementation. The main rationale for this commit is to reduce the RSS of long-lived programs which allocate instances with the pooling instance allocator and aren't using the "next available" allocation strategy. In this situation the memory for an instance is never decommitted until the end of the program, meaning that eventually all instance slots will become occupied and resident. This has the effect of Wasmtime slowly eating more and more memory over time as each slot gets an instance allocated. By switching to the system allocator this should reduce the current RSS workload from O(used slots) to O(active slots), which is more in line with expectations.
This commit is contained in:
@@ -646,11 +646,11 @@ fn instance_too_large() -> Result<()> {
|
||||
|
||||
let engine = Engine::new(&config)?;
|
||||
let expected = "\
|
||||
instance allocation for this module requires 224 bytes which exceeds the \
|
||||
instance allocation for this module requires 240 bytes which exceeds the \
|
||||
configured maximum of 16 bytes; breakdown of allocation requirement:
|
||||
|
||||
* 64.29% - 144 bytes - instance state management
|
||||
* 7.14% - 16 bytes - jit store state
|
||||
* 66.67% - 160 bytes - instance state management
|
||||
* 6.67% - 16 bytes - jit store state
|
||||
";
|
||||
match Module::new(&engine, "(module)") {
|
||||
Ok(_) => panic!("should have failed to compile"),
|
||||
@@ -664,11 +664,11 @@ configured maximum of 16 bytes; breakdown of allocation requirement:
|
||||
lots_of_globals.push_str(")");
|
||||
|
||||
let expected = "\
|
||||
instance allocation for this module requires 1824 bytes which exceeds the \
|
||||
instance allocation for this module requires 1840 bytes which exceeds the \
|
||||
configured maximum of 16 bytes; breakdown of allocation requirement:
|
||||
|
||||
* 7.89% - 144 bytes - instance state management
|
||||
* 87.72% - 1600 bytes - defined globals
|
||||
* 8.70% - 160 bytes - instance state management
|
||||
* 86.96% - 1600 bytes - defined globals
|
||||
";
|
||||
match Module::new(&engine, &lots_of_globals) {
|
||||
Ok(_) => panic!("should have failed to compile"),
|
||||
|
||||
Reference in New Issue
Block a user