@@ -2950,16 +2950,17 @@ pub enum WasmBacktraceDetails {
29502950 Environment ,
29512951}
29522952
2953- /// Describe the tri-state configuration of memory protection keys ( MPK) .
2953+ /// Describe the tri-state configuration of keys such as MPK or PAGEMAP_SCAN .
29542954#[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
2955- pub enum MpkEnabled {
2956- /// Use MPK if supported by the current system; fall back to guard regions
2957- /// otherwise .
2955+ pub enum Enabled {
2956+ /// Enable this feature if it's detected on the host system, otherwise leave
2957+ /// it disabled .
29582958 Auto ,
2959- /// Use MPK or fail if not supported.
2960- Enable ,
2961- /// Do not use MPK.
2962- Disable ,
2959+ /// Enable this feature and fail configuration if the feature is not
2960+ /// detected on the host system.
2961+ Yes ,
2962+ /// Do not enable this feature, even if the host system supports it.
2963+ No ,
29632964}
29642965
29652966/// Configuration options used with [`InstanceAllocationStrategy::Pooling`] to
@@ -3482,19 +3483,19 @@ impl PoolingAllocationConfig {
34823483 ///
34833484 /// - `auto`: if MPK support is available the guard regions are removed; if
34843485 /// not, the guard regions remain
3485- /// - `enable `: use MPK to eliminate guard regions; fail if MPK is not
3486+ /// - `yes `: use MPK to eliminate guard regions; fail if MPK is not
34863487 /// supported
3487- /// - `disable `: never use MPK
3488+ /// - `no `: never use MPK
34883489 ///
3489- /// By default this value is `disabled `, but may become `auto` in future
3490+ /// By default this value is `no `, but may become `auto` in future
34903491 /// releases.
34913492 ///
34923493 /// __WARNING__: this configuration options is still experimental--use at
34933494 /// your own risk! MPK uses kernel and CPU features to protect memory
34943495 /// regions; you may observe segmentation faults if anything is
34953496 /// misconfigured.
34963497 #[ cfg( feature = "memory-protection-keys" ) ]
3497- pub fn memory_protection_keys ( & mut self , enable : MpkEnabled ) -> & mut Self {
3498+ pub fn memory_protection_keys ( & mut self , enable : Enabled ) -> & mut Self {
34983499 self . config . memory_protection_keys = enable;
34993500 self
35003501 }
@@ -3520,7 +3521,7 @@ impl PoolingAllocationConfig {
35203521 /// Check if memory protection keys (MPK) are available on the current host.
35213522 ///
35223523 /// This is a convenience method for determining MPK availability using the
3523- /// same method that [`MpkEnabled ::Auto`] does. See
3524+ /// same method that [`Enabled ::Auto`] does. See
35243525 /// [`PoolingAllocationConfig::memory_protection_keys`] for more
35253526 /// information.
35263527 #[ cfg( feature = "memory-protection-keys" ) ]
@@ -3541,6 +3542,45 @@ impl PoolingAllocationConfig {
35413542 self . config . limits . total_gc_heaps = count;
35423543 self
35433544 }
3545+
3546+ /// Configures whether the Linux-specific [`PAGEMAP_SCAN` ioctl][ioctl] is
3547+ /// used to help reset linear memory.
3548+ ///
3549+ /// When [`Self::linear_memory_keep_resident`] or
3550+ /// [`Self::table_keep_resident`] options are configured to nonzero values
3551+ /// the default behavior is to `memset` the lowest addresses of a table or
3552+ /// memory back to their original contents. With the `PAGEMAP_SCAN` ioctl on
3553+ /// Linux this can be done to more intelligently scan for resident pages in
3554+ /// the region and only reset those pages back to their original contents
3555+ /// with `memset` rather than assuming the low addresses are all resident.
3556+ ///
3557+ /// This ioctl has the potential to provide a number of performance benefits
3558+ /// in high-reuse and high concurrency scenarios. Notably this enables
3559+ /// Wasmtime to scan the entire region of WebAssembly linear memory and
3560+ /// manually reset memory back to its original contents, up to
3561+ /// [`Self::linear_memory_keep_resident`] bytes, possibly skipping an
3562+ /// `madvise` entirely. This can be more efficient by avoiding removing
3563+ /// pages from the address space entirely and additionally ensuring that
3564+ /// future use of the linear memory doesn't incur page faults as the pages
3565+ /// remain resident.
3566+ ///
3567+ /// At this time this configuration option is still being evaluated as to
3568+ /// how appropriate it is for all use cases. It currently defaults to
3569+ /// `no` or disabled but may change to `auto`, enable if supported, in the
3570+ /// future. This option is only supported on Linux and requires a kernel
3571+ /// version of 6.7 or higher.
3572+ ///
3573+ /// [ioctl]: https://www.man7.org/linux/man-pages/man2/PAGEMAP_SCAN.2const.html
3574+ pub fn pagemap_scan ( & mut self , enable : Enabled ) -> & mut Self {
3575+ self . config . pagemap_scan = enable;
3576+ self
3577+ }
3578+
3579+ /// Tests whether [`Self::pagemap_scan`] is available or not on the host
3580+ /// system.
3581+ pub fn is_pagemap_scan_available ( ) -> bool {
3582+ crate :: runtime:: vm:: PoolingInstanceAllocatorConfig :: is_pagemap_scan_available ( )
3583+ }
35443584}
35453585
35463586#[ cfg( feature = "std" ) ]
0 commit comments