Skip to content

Commit

Permalink
Switch to using the on-demand allocator, instead of the pooling alloc…
Browse files Browse the repository at this point in the history
…ator.
  • Loading branch information
acw committed Jun 18, 2024
1 parent 7dca458 commit 29d4ec7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
40 changes: 2 additions & 38 deletions lib/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,7 @@ fn configure_wasmtime(
allow_components: bool,
profiling_strategy: ProfilingStrategy,
) -> wasmtime::Config {
use wasmtime::{
Config, InstanceAllocationStrategy, PoolingAllocationConfig, WasmBacktraceDetails,
};
use wasmtime::{Config, InstanceAllocationStrategy, WasmBacktraceDetails};

let mut config = Config::new();
config.debug_info(false); // Keep this disabled - wasmtime will hang if enabled
Expand All @@ -686,41 +684,7 @@ fn configure_wasmtime(
config.epoch_interruption(true);
config.profiler(profiling_strategy);

const MB: usize = 1 << 20;
let mut pooling_allocation_config = PoolingAllocationConfig::default();

// This number matches Compute production
pooling_allocation_config.max_core_instance_size(MB);

// Core wasm programs have 1 memory
pooling_allocation_config.total_memories(100);
pooling_allocation_config.max_memories_per_module(1);

// allow for up to 128MiB of linear memory. Wasm pages are 64k
pooling_allocation_config.memory_pages(128 * (MB as u64) / (64 * 1024));

// Core wasm programs have 1 table
pooling_allocation_config.max_tables_per_module(1);

// Some applications create a large number of functions, in particular
// when compiled in debug mode or applications written in swift. Every
// function can end up in the table
pooling_allocation_config.table_elements(98765);

// Maximum number of slots in the pooling allocator to keep "warm", or those
// to keep around to possibly satisfy an affine allocation request or an
// instantiation of a module previously instantiated within the pool.
pooling_allocation_config.max_unused_warm_slots(10);

// Use a large pool, but one smaller than the default of 1000 to avoid runnign out of virtual
// memory space if multiple engines are spun up in a single process. We'll likely want to move
// to the on-demand allocator eventually for most purposes; see
// https://github.com/fastly/Viceroy/issues/255
pooling_allocation_config.total_core_instances(100);

config.allocation_strategy(InstanceAllocationStrategy::Pooling(
pooling_allocation_config,
));
config.allocation_strategy(InstanceAllocationStrategy::OnDemand);

if allow_components {
config.wasm_component_model(true);
Expand Down
5 changes: 4 additions & 1 deletion lib/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ impl wasmtime::ResourceLimiter for Limiter {
// gradually resize, this will track the total allocations throughout the lifetime of the
// instance.
self.memory_allocated += desired - current;
Ok(true)
// limit the amount of memory that an instance can use to (roughly) 128MB, erring on
// the side of letting things run that might get killed on Compute, because we are not
// tracking some runtime factors in this count.
Ok(self.memory_allocated < (128 * 1024 * 1024))
}

fn table_growing(
Expand Down

0 comments on commit 29d4ec7

Please sign in to comment.