Add a configuration option to force "static" memories (#3503)
* Add a configuration option to force "static" memories In poking around at some things earlier today I realized that one configuration option for memories we haven't exposed from embeddings like the CLI is to forcibly limit the size of memory growth and force using a static memory style. This means that the CLI, for example, can't limit memory growth by default and memories are only limited in size by what the OS can give and the wasm's own memory type. This configuration option means that the CLI can artificially limit the size of wasm linear memories. Additionally another motivation for this is for testing out various codegen ramifications of static/dynamic memories. This is the only way to force a static memory, by default, for wasm64 memories with no maximum size listed for example. * Review feedback
This commit is contained in:
@@ -90,7 +90,7 @@ pub struct MmapMemory {
|
||||
|
||||
impl MmapMemory {
|
||||
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
|
||||
pub fn new(plan: &MemoryPlan, minimum: usize, maximum: Option<usize>) -> Result<Self> {
|
||||
pub fn new(plan: &MemoryPlan, minimum: usize, mut maximum: Option<usize>) -> Result<Self> {
|
||||
// It's a programmer error for these two configuration values to exceed
|
||||
// the host available address space, so panic if such a configuration is
|
||||
// found (mostly an issue for hypothetical 32-bit hosts).
|
||||
@@ -98,13 +98,21 @@ impl MmapMemory {
|
||||
let pre_guard_bytes = usize::try_from(plan.pre_guard_size).unwrap();
|
||||
|
||||
let (alloc_bytes, extra_to_reserve_on_growth) = match plan.style {
|
||||
// Dynamic memories start with the minimum size plus the `reserve`
|
||||
// amount specified to grow into.
|
||||
MemoryStyle::Dynamic { reserve } => (minimum, 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.
|
||||
// Note that the `maximum` is adjusted here to whatever the smaller
|
||||
// of the two is, the `maximum` given or the `bound` specified for
|
||||
// this memory.
|
||||
MemoryStyle::Static { bound } => {
|
||||
assert_ge!(bound, plan.memory.minimum);
|
||||
(
|
||||
usize::try_from(bound.checked_mul(WASM_PAGE_SIZE_U64).unwrap()).unwrap(),
|
||||
0,
|
||||
)
|
||||
let bound_bytes =
|
||||
usize::try_from(bound.checked_mul(WASM_PAGE_SIZE_U64).unwrap()).unwrap();
|
||||
maximum = Some(bound_bytes.min(maximum.unwrap_or(usize::MAX)));
|
||||
(bound_bytes, 0)
|
||||
}
|
||||
};
|
||||
let request_bytes = pre_guard_bytes
|
||||
|
||||
Reference in New Issue
Block a user