Skip to content

Commit

Permalink
Implement the pooling instance allocator.
Browse files Browse the repository at this point in the history
This commit implements the pooling instance allocator.

The allocation strategy can be set with `Config::with_allocation_strategy`.

The pooling strategy uses the pooling instance allocator to preallocate a
contiguous region of memory for instantiating modules that adhere to various
limits.

The intention of the pooling instance allocator is to reserve as much of the
host address space needed for instantiating modules ahead of time and to reuse
committed memory pages wherever possible.
  • Loading branch information
peterhuene committed Feb 5, 2021
1 parent 3107349 commit 404812e
Show file tree
Hide file tree
Showing 16 changed files with 1,955 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/environ/src/vmoffsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn align(offset: u32, width: u32) -> u32 {

/// This class computes offsets to fields within `VMContext` and other
/// related structs that JIT code accesses directly.
#[derive(Debug, Clone, Copy)]
pub struct VMOffsets {
/// The size in bytes of a pointer on the target.
pub pointer_size: u8,
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cfg-if = "1.0"
backtrace = "0.3.55"
lazy_static = "1.3.0"
psm = "0.1.11"
rand = "0.7.3"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.7", features = ["winbase", "memoryapi", "errhandlingapi"] }
Expand Down
15 changes: 14 additions & 1 deletion crates/runtime/src/instance/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use wasmtime_environ::{
ir, Module, ModuleTranslation, ModuleType, OwnedDataInitializer, TableElements, VMOffsets,
};

mod pooling;

pub use self::pooling::{
InstanceLimits, ModuleLimits, PoolingAllocationStrategy, PoolingInstanceAllocator,
};

/// Represents a request for a new runtime instance.
pub struct InstanceAllocationRequest<'a> {
/// The module being instantiated.
Expand Down Expand Up @@ -72,11 +78,18 @@ pub enum InstantiationError {
/// A trap ocurred during instantiation, after linking.
#[error("Trap occurred during instantiation")]
Trap(Trap),

/// A limit on how many instances are supported has been reached.
#[error("Limit of {0} concurrent instances has been reached")]
Limit(u32),
}
/// An error while creating a fiber stack.
#[cfg(feature = "async")]
#[derive(Error, Debug)]
pub enum FiberStackError {
/// Insufficient resources available for the request.
#[error("Insufficient resources: {0}")]
Resource(String),
/// An error for when the allocator doesn't support custom fiber stacks.
#[error("Custom fiber stacks are not supported by the allocator")]
NotSupported,
Expand Down Expand Up @@ -220,7 +233,7 @@ unsafe fn initialize_vmcontext(
globals.len(),
);

// Initialize the defined functions
// Initialize the functions
for (index, sig) in instance.module.functions.iter() {
let type_index = lookup_shared_signature(*sig);

Expand Down
Loading

0 comments on commit 404812e

Please sign in to comment.