memfd: Some minor follow-ups (#3759)
* Tweak memfd-related features crates This commit changes the `memfd` feature for the `wasmtime-cli` crate from an always-on feature to a default-on feature which can be disabled at compile time. Additionally the `pooling-allocator` feature is also given similar treatment. Additionally some documentation was added for the `memfd` feature on the `wasmtime` crate. * Don't store `Arc<T>` in `InstanceAllocationRequest` Instead store `&Arc<T>` to avoid having the clone that lives in `InstanceAllocationRequest` not actually going anywhere. Otherwise all instance allocation requires an extra clone to create it for the request and an extra decrement when the request goes away. Internally clones are made as necessary when creating instances. * Enable the pooling allocator by default for `wasmtime-cli` While perhaps not the most useful option since the CLI doesn't have a great way to take advantage of this it probably makes sense to at least match the features of `wasmtime` itself. * Fix some lints and issues * More compile fixes
This commit is contained in:
@@ -90,4 +90,10 @@ all-arch = ["wasmtime-cranelift/all-arch"]
|
||||
# need portable signal handling.
|
||||
posix-signals-on-macos = ["wasmtime-runtime/posix-signals-on-macos"]
|
||||
|
||||
# Enables, on Linux, the usage of memfd mappings to enable instantiation to use
|
||||
# copy-on-write to initialize linear memory for wasm modules which have
|
||||
# compatible linear memories.
|
||||
#
|
||||
# Enabling this feature has no effect on non-Linux platforms or when the `uffd`
|
||||
# feature is enabled.
|
||||
memfd = ["wasmtime-runtime/memfd"]
|
||||
|
||||
@@ -706,9 +706,9 @@ impl<'a> Instantiator<'a> {
|
||||
.engine()
|
||||
.allocator()
|
||||
.allocate(InstanceAllocationRequest {
|
||||
module: compiled_module.module().clone(),
|
||||
module: compiled_module.module(),
|
||||
unique_id: Some(compiled_module.unique_id()),
|
||||
memfds: self.cur.module.memfds().clone(),
|
||||
memfds: self.cur.module.memfds(),
|
||||
image_base: compiled_module.code().as_ptr() as usize,
|
||||
functions: compiled_module.functions(),
|
||||
imports: self.cur.build(),
|
||||
|
||||
@@ -723,8 +723,8 @@ impl Module {
|
||||
&self.inner.signatures
|
||||
}
|
||||
|
||||
pub(crate) fn memfds(&self) -> &Option<Arc<ModuleMemFds>> {
|
||||
&self.inner.memfds
|
||||
pub(crate) fn memfds(&self) -> Option<&Arc<ModuleMemFds>> {
|
||||
self.inner.memfds.as_ref()
|
||||
}
|
||||
|
||||
/// Looks up the module upvar value at the `index` specified.
|
||||
|
||||
@@ -418,6 +418,7 @@ impl<T> Store<T> {
|
||||
// part of `Func::call` to guarantee that the `callee: *mut VMContext`
|
||||
// is never null.
|
||||
let default_callee = unsafe {
|
||||
let module = Arc::new(wasmtime_environ::Module::default());
|
||||
OnDemandInstanceAllocator::default()
|
||||
.allocate(InstanceAllocationRequest {
|
||||
host_state: Box::new(()),
|
||||
@@ -425,7 +426,7 @@ impl<T> Store<T> {
|
||||
functions,
|
||||
shared_signatures: None.into(),
|
||||
imports: Default::default(),
|
||||
module: Arc::new(wasmtime_environ::Module::default()),
|
||||
module: &module,
|
||||
unique_id: None,
|
||||
memfds: None,
|
||||
store: StorePtr::empty(),
|
||||
|
||||
@@ -38,9 +38,10 @@ fn create_handle(
|
||||
// Use the on-demand allocator when creating handles associated with host objects
|
||||
// The configured instance allocator should only be used when creating module instances
|
||||
// as we don't want host objects to count towards instance limits.
|
||||
let module = Arc::new(module);
|
||||
let handle = OnDemandInstanceAllocator::new(config.mem_creator.clone(), 0).allocate(
|
||||
InstanceAllocationRequest {
|
||||
module: Arc::new(module),
|
||||
module: &module,
|
||||
unique_id: None,
|
||||
memfds: None,
|
||||
functions,
|
||||
|
||||
@@ -157,10 +157,11 @@ pub unsafe fn create_raw_function(
|
||||
module
|
||||
.exports
|
||||
.insert(String::new(), EntityIndex::Function(func_id));
|
||||
let module = Arc::new(module);
|
||||
|
||||
Ok(
|
||||
OnDemandInstanceAllocator::default().allocate(InstanceAllocationRequest {
|
||||
module: Arc::new(module),
|
||||
module: &module,
|
||||
unique_id: None,
|
||||
memfds: None,
|
||||
functions: &functions,
|
||||
|
||||
Reference in New Issue
Block a user