Skip to content

Commit 58aab85

Browse files
author
Peter Huene
committed
Add the pooling-allocator feature.
This commit adds the `pooling-allocator` feature to both the `wasmtime` and `wasmtime-runtime` crates. The feature controls whether or not the pooling allocator implementation is built into the runtime and exposed as a supported instance allocation strategy in the wasmtime API. The feature is on by default for the `wasmtime` crate. Closes #3513.
1 parent 00feefe commit 58aab85

9 files changed

Lines changed: 302 additions & 280 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ jobs:
136136
- run: cargo check -p wasmtime --no-default-features --features cache
137137
- run: cargo check -p wasmtime --no-default-features --features async
138138
- run: cargo check -p wasmtime --no-default-features --features uffd
139+
- run: cargo check -p wasmtime --no-default-features --features pooling-allocator
139140
- run: cargo check -p wasmtime --no-default-features --features cranelift
140141
- run: cargo check -p wasmtime --no-default-features --features cranelift,wat,async,cache
141142

crates/runtime/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ default = []
4949

5050
async = ["wasmtime-fiber"]
5151

52+
# Enables support for the pooling instance allocator
53+
pooling-allocator = []
54+
5255
# Enables support for userfaultfd in the pooling allocator when building on Linux
53-
uffd = ["userfaultfd"]
56+
uffd = ["userfaultfd", "pooling-allocator"]
5457

5558
# Enables trap handling using POSIX signals instead of Mach exceptions on MacOS.
5659
# It is useful for applications that do not bind their own exception ports and

crates/runtime/src/instance/allocator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ use wasmtime_environ::{
2323
SignatureIndex, TableInitializer, TrapCode, VMOffsets, WasmType, WASM_PAGE_SIZE,
2424
};
2525

26+
#[cfg(feature = "pooling-allocator")]
2627
mod pooling;
2728

29+
#[cfg(feature = "pooling-allocator")]
2830
pub use self::pooling::{
2931
InstanceLimits, ModuleLimits, PoolingAllocationStrategy, PoolingInstanceAllocator,
3032
};

crates/runtime/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ pub use crate::export::*;
4040
pub use crate::externref::*;
4141
pub use crate::imports::Imports;
4242
pub use crate::instance::{
43-
InstanceAllocationRequest, InstanceAllocator, InstanceHandle, InstanceLimits,
44-
InstantiationError, LinkError, ModuleLimits, OnDemandInstanceAllocator,
45-
PoolingAllocationStrategy, PoolingInstanceAllocator, StorePtr,
43+
InstanceAllocationRequest, InstanceAllocator, InstanceHandle, InstantiationError, LinkError,
44+
OnDemandInstanceAllocator, StorePtr,
45+
};
46+
#[cfg(feature = "pooling-allocator")]
47+
pub use crate::instance::{
48+
InstanceLimits, ModuleLimits, PoolingAllocationStrategy, PoolingInstanceAllocator,
4649
};
4750
pub use crate::jit_int::GdbJitImageRegistration;
4851
pub use crate::memory::{Memory, RuntimeLinearMemory, RuntimeMemoryCreator};

crates/runtime/src/memory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ impl Memory {
364364
}
365365

366366
/// Returns whether or not the underlying storage of the memory is "static".
367+
#[cfg(feature = "pooling-allocator")]
367368
pub(crate) fn is_static(&self) -> bool {
368369
if let Memory::Static { .. } = self {
369370
true

crates/runtime/src/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ impl Table {
186186
}
187187

188188
/// Returns whether or not the underlying storage of the table is "static".
189+
#[cfg(feature = "pooling-allocator")]
189190
pub(crate) fn is_static(&self) -> bool {
190191
if let Table::Static { .. } = self {
191192
true

crates/wasmtime/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" }
5252
maintenance = { status = "actively-developed" }
5353

5454
[features]
55-
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift']
55+
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift', 'pooling-allocator']
5656

5757
# An on-by-default feature enabling runtime compilation of WebAssembly modules
5858
# with the Cranelift compiler. Cranelift is the default compilation backend of
@@ -76,8 +76,11 @@ cache = ["wasmtime-cache"]
7676
# `async fn` and calling functions asynchronously.
7777
async = ["wasmtime-fiber", "wasmtime-runtime/async", "async-trait"]
7878

79+
# Enables support for the pooling instance allocation strategy
80+
pooling-allocator = ["wasmtime-runtime/pooling-allocator"]
81+
7982
# Enables userfaultfd support in the runtime's pooling allocator when building on Linux
80-
uffd = ["wasmtime-runtime/uffd"]
83+
uffd = ["wasmtime-runtime/uffd", "pooling-allocator"]
8184

8285
# Enables support for all architectures in Cranelift, allowing
8386
# cross-compilation using the `wasmtime` crate's API, notably the

0 commit comments

Comments
 (0)