Implement a setting for reserved dynamic memory growth (#3215)
* Implement a setting for reserved dynamic memory growth Dynamic memories aren't really that heavily used in Wasmtime right now because for most 32-bit memories they're classified as "static" which means they reserve 4gb of address space and never move. Growth of a static memory is simply making pages accessible, so it's quite fast. With the memory64 feature, however, this is no longer true since all memory64 memories are classified as "dynamic" at this time. Previous to this commit growth of a dynamic memory unconditionally moved the entire linear memory in the host's address space, always resulting in a new `Mmap` allocation. This behavior is causing fuzzers to time out when working with 64-bit memories because incrementally growing a memory by 1 page at a time can incur a quadratic time complexity as bytes are constantly moved. This commit implements a scheme where there is now a tunable setting for memory to be reserved at the end of a dynamic memory to grow into. This means that dynamic memory growth is ideally amortized as most calls to `memory.grow` will be able to grow into the pre-reserved space. Some calls, though, will still need to copy the memory around. This helps enable a commented out test for 64-bit memories now that it's fast enough to run in debug mode. This is because the growth of memory in the test no longer needs to copy 4gb of zeros. * Test fixes & review comments * More comments
This commit is contained in:
@@ -12,7 +12,10 @@ use wasmtime_types::*;
|
||||
#[derive(Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub enum MemoryStyle {
|
||||
/// The actual memory can be resized and moved.
|
||||
Dynamic,
|
||||
Dynamic {
|
||||
/// Extra space to reserve when a memory must be moved due to growth.
|
||||
reserve: u64,
|
||||
},
|
||||
/// Addresss space is allocated up front.
|
||||
Static {
|
||||
/// The number of mapped and unmapped pages.
|
||||
@@ -54,7 +57,12 @@ impl MemoryStyle {
|
||||
}
|
||||
|
||||
// Otherwise, make it dynamic.
|
||||
(Self::Dynamic, tunables.dynamic_memory_offset_guard_size)
|
||||
(
|
||||
Self::Dynamic {
|
||||
reserve: tunables.dynamic_memory_growth_reserve,
|
||||
},
|
||||
tunables.dynamic_memory_offset_guard_size,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user