Skip to content

Commit 402197f

Browse files
committed
chore: RUN-939: Propagate wasm_memory_limit through the execution layer
1 parent e091733 commit 402197f

File tree

12 files changed

+25
-0
lines changed

12 files changed

+25
-0
lines changed

rs/canister_sandbox/src/sandbox_server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ mod tests {
181181
NumInstructions::new(INSTRUCTION_LIMIT),
182182
),
183183
canister_memory_limit: NumBytes::new(4 << 30),
184+
wasm_memory_limit: None,
184185
memory_allocation: MemoryAllocation::default(),
185186
compute_allocation: ComputeAllocation::default(),
186187
subnet_type: SubnetType::Application,

rs/embedders/fuzz/fuzz_targets/execute_with_wasm_executor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ fn setup_wasm_execution_input(func_ref: FuncRef) -> WasmExecutionInput {
120120
DEFAULT_NUM_INSTRUCTIONS,
121121
),
122122
canister_memory_limit: NumBytes::from(4 << 30),
123+
wasm_memory_limit: None,
123124
memory_allocation: MemoryAllocation::default(),
124125
compute_allocation: ComputeAllocation::default(),
125126
subnet_type: SubnetType::Application,

rs/embedders/src/wasmtime_embedder/wasmtime_embedder_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn test_wasmtime_system_api() {
7171
MAX_NUM_INSTRUCTIONS,
7272
),
7373
canister_memory_limit,
74+
wasm_memory_limit: None,
7475
memory_allocation: MemoryAllocation::default(),
7576
compute_allocation: ComputeAllocation::default(),
7677
subnet_type: SubnetType::Application,

rs/embedders/tests/wasmtime_random_memory_writes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn test_api_for_update(
9393
instruction_limit,
9494
),
9595
canister_memory_limit,
96+
wasm_memory_limit: None,
9697
memory_allocation: MemoryAllocation::default(),
9798
compute_allocation: ComputeAllocation::default(),
9899
subnet_type: SubnetType::Application,

rs/execution_environment/benches/lib/src/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ where
152152
MAX_NUM_INSTRUCTIONS,
153153
),
154154
canister_memory_limit: canister_state.memory_limit(NumBytes::new(std::u64::MAX)),
155+
wasm_memory_limit: None,
155156
memory_allocation: canister_state.memory_allocation(),
156157
compute_allocation: canister_state.compute_allocation(),
157158
subnet_type: hypervisor.subnet_type(),

rs/execution_environment/src/canister_manager/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ lazy_static! {
108108
MAX_NUM_INSTRUCTIONS
109109
),
110110
canister_memory_limit: NumBytes::new(u64::MAX / 2),
111+
wasm_memory_limit: None,
111112
memory_allocation: MemoryAllocation::default(),
112113
compute_allocation: ComputeAllocation::default(),
113114
subnet_type: SubnetType::Application,

rs/execution_environment/src/execution_environment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ impl ExecutionEnvironment {
16091609
ExecutionParameters {
16101610
instruction_limits,
16111611
canister_memory_limit: canister.memory_limit(self.config.max_canister_memory_size),
1612+
wasm_memory_limit: canister.wasm_memory_limit(),
16121613
memory_allocation: canister.memory_allocation(),
16131614
compute_allocation: canister.compute_allocation(),
16141615
subnet_type: self.own_subnet_type,

rs/execution_environment/src/query_handler/query_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ impl<'a> QueryContext<'a> {
10591059
ExecutionParameters {
10601060
instruction_limits,
10611061
canister_memory_limit: canister.memory_limit(self.max_canister_memory_size),
1062+
wasm_memory_limit: canister.wasm_memory_limit(),
10621063
memory_allocation: canister.memory_allocation(),
10631064
compute_allocation: canister.compute_allocation(),
10641065
subnet_type: self.own_subnet_type,

rs/replicated_state/src/canister_state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ impl CanisterState {
464464
}
465465
}
466466

467+
/// Returns the Wasm memory limit from the canister settings.
468+
pub fn wasm_memory_limit(&self) -> Option<NumBytes> {
469+
self.system_state.wasm_memory_limit
470+
}
471+
467472
/// Returns the current compute allocation for the canister.
468473
pub fn compute_allocation(&self) -> ComputeAllocation {
469474
self.scheduler_state.compute_allocation

rs/system_api/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ impl InstructionLimits {
160160
pub struct ExecutionParameters {
161161
pub instruction_limits: InstructionLimits,
162162
pub canister_memory_limit: NumBytes,
163+
// The limit on the Wasm memory set by the developer in canister settings.
164+
pub wasm_memory_limit: Option<NumBytes>,
163165
pub memory_allocation: MemoryAllocation,
164166
pub compute_allocation: ComputeAllocation,
165167
pub subnet_type: SubnetType,
@@ -622,6 +624,11 @@ struct MemoryUsage {
622624
/// Upper limit on how much the memory the canister could use.
623625
limit: NumBytes,
624626

627+
/// The Wasm memory limit set by the developer in canister settings.
628+
/// TODO: Enforce this limit in `update_available_memory`.
629+
#[allow(dead_code)]
630+
wasm_memory_limit: Option<NumBytes>,
631+
625632
/// The current amount of execution memory that the canister is using.
626633
current_usage: NumBytes,
627634

@@ -648,6 +655,7 @@ impl MemoryUsage {
648655
log: ReplicaLogger,
649656
canister_id: CanisterId,
650657
limit: NumBytes,
658+
wasm_memory_limit: Option<NumBytes>,
651659
current_usage: NumBytes,
652660
current_message_usage: NumBytes,
653661
subnet_available_memory: SubnetAvailableMemory,
@@ -668,6 +676,7 @@ impl MemoryUsage {
668676
}
669677
Self {
670678
limit,
679+
wasm_memory_limit,
671680
current_usage,
672681
current_message_usage,
673682
subnet_available_memory,
@@ -895,6 +904,7 @@ impl SystemApiImpl {
895904
log.clone(),
896905
sandbox_safe_system_state.canister_id,
897906
execution_parameters.canister_memory_limit,
907+
execution_parameters.wasm_memory_limit,
898908
canister_current_memory_usage,
899909
canister_current_message_memory_usage,
900910
subnet_available_memory,

0 commit comments

Comments
 (0)