MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / build_engine

Function build_engine

examples/mpk.rs:185–215  ·  view source on GitHub ↗

Build a pool-allocated engine with `num_memories` slots.

(args: &Args, num_memories: u32, enable_mpk: Enabled)

Source from the content-addressed store, hash-verified

183
184/// Build a pool-allocated engine with `num_memories` slots.
185fn build_engine(args: &Args, num_memories: u32, enable_mpk: Enabled) -> Result<usize> {
186 // Configure the memory pool.
187 let mut pool = PoolingAllocationConfig::default();
188 let max_memory_size =
189 usize::try_from(args.memory_size).expect("memory size should fit in `usize`");
190 pool.max_memory_size(max_memory_size)
191 .total_memories(num_memories)
192 .memory_protection_keys(enable_mpk);
193
194 // Configure the engine itself.
195 let mut config = Config::new();
196 if let Some(memory_reservation) = args.memory_reservation {
197 config.memory_reservation(memory_reservation);
198 }
199 if let Some(memory_guard_size) = args.memory_guard_size {
200 config.memory_guard_size(memory_guard_size);
201 }
202 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
203
204 // Measure memory use before and after the engine is built.
205 let mapped_bytes_before = num_bytes_mapped()?;
206 let engine = Engine::new(&config)?;
207 let mapped_bytes_after = num_bytes_mapped()?;
208
209 // Ensure we actually use the engine somehow.
210 engine.increment_epoch();
211
212 let mapped_bytes = mapped_bytes_after - mapped_bytes_before;
213 info!("{num_memories}-slot pool ({enable_mpk:?}): {mapped_bytes} bytes mapped");
214 Ok(mapped_bytes)
215}
216
217/// Add up the sizes of all the mapped virtual memory regions for the current
218/// Linux process.

Callers 1

probe_engine_sizeFunction · 0.70

Calls 11

num_bytes_mappedFunction · 0.85
OkFunction · 0.85
allocation_strategyMethod · 0.80
newFunction · 0.50
expectMethod · 0.45
total_memoriesMethod · 0.45
max_memory_sizeMethod · 0.45
memory_reservationMethod · 0.45
memory_guard_sizeMethod · 0.45
increment_epochMethod · 0.45

Tested by

no test coverage detected