memfd: make "dense image" heuristic limit configurable. (#3831)

In #3820 we see an issue with the new heuristics that control use of
memfd: it's entirely possible for a reasonable Wasm module produced by a
snapshotting system to have a relatively sparse heap (less than 50%
filled). A system that avoids memfd because of this would have an
undesirable performance reduction on such modules.

Ultimately we should try to implement a hybrid scheme where we support
outlier/leftover initializers, but for now this PR makes the "always
allow dense" limit configurable. This way, embedders that want to ensure
that memfd is used can do so, if they have other knowledge about the
maximum heap size allowed in their system.

(Partially addresses #3820 but let's leave it open to track the hybrid
idea)
This commit is contained in:
Chris Fallin
2022-02-22 10:40:43 -08:00
committed by GitHub
parent 4ed353a7e1
commit 43d31c5bf7
4 changed files with 79 additions and 10 deletions

View File

@@ -257,6 +257,7 @@ pub struct WasmtimeConfig {
pub memory_config: MemoryConfig,
force_jump_veneers: bool,
memfd: bool,
memfd_guaranteed_dense_image_size: u64,
use_precompiled_cwasm: bool,
/// Configuration for the instance allocation strategy to use.
pub strategy: InstanceAllocationStrategy,
@@ -440,6 +441,12 @@ impl Config {
.interruptable(self.wasmtime.interruptable)
.consume_fuel(self.wasmtime.consume_fuel)
.memfd(self.wasmtime.memfd)
.memfd_guaranteed_dense_image_size(std::cmp::min(
// Clamp this at 16MiB so we don't get huge in-memory
// images during fuzzing.
16 << 20,
self.wasmtime.memfd_guaranteed_dense_image_size,
))
.allocation_strategy(self.wasmtime.strategy.to_wasmtime());
self.wasmtime.codegen.configure(&mut cfg);