Skip to content

Commit

Permalink
Optionally increase the allocation size for dynamic memories
Browse files Browse the repository at this point in the history
This code will be short-lived due to scheduled future refactorings but
the idea is that when a "dynamic" memory is chosen the minimum size of
the allocation needs to be at least `tunables.memory_reservation` to fit
the constraints of the rest of the system, so be sure to factor that
in.
  • Loading branch information
alexcrichton committed Nov 6, 2024
1 parent cb16230 commit 29e0875
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions crates/wasmtime/src/runtime/vm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,23 @@ impl MmapMemory {
let pre_guard_bytes = round_usize_up_to_host_pages(pre_guard_bytes)?;

let (alloc_bytes, extra_to_reserve_on_growth) = match style {
// Dynamic memories start with the minimum size plus the `reserve`
// amount specified to grow into.
MemoryStyle::Dynamic { reserve } => (
round_usize_up_to_host_pages(minimum)?,
round_usize_up_to_host_pages(usize::try_from(reserve).unwrap())?,
),
// Dynamic memories start with the larger of the minimum size of
// memory or the configured memory reservation. This ensures that
// the allocation fits the constraints in `tunables` where it must
// be as large as the specified reservation.
//
// Then `reserve` amount is added extra to the virtual memory
// allocation for memory to grow into.
MemoryStyle::Dynamic { reserve } => {
let minimum = round_usize_up_to_host_pages(minimum)?;
let reservation = usize::try_from(tunables.memory_reservation).unwrap();
let reservation = round_usize_up_to_host_pages(reservation)?;

(
minimum.max(reservation),
round_usize_up_to_host_pages(usize::try_from(reserve).unwrap())?,
)
}

// Static memories will never move in memory and consequently get
// their entire allocation up-front with no extra room to grow into.
Expand Down

0 comments on commit 29e0875

Please sign in to comment.