Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e0971b1
use dmt, disable direct stable page charging
michael-weigelt Jun 22, 2026
855f8fb
fix memory write tests
michael-weigelt Jun 22, 2026
b594447
wip
michael-weigelt Jun 22, 2026
afa958b
remove multiplier
michael-weigelt Jun 23, 2026
5def612
adjust costs
michael-weigelt Jun 23, 2026
0d9cab9
wip tests
michael-weigelt Jun 24, 2026
b09650a
Merge remote-tracking branch 'origin' into mwe/dmt_for_stable
michael-weigelt Jun 26, 2026
796faa6
fix instrumentation tests
michael-weigelt Jun 26, 2026
99afee8
remove unused args
michael-weigelt Jun 26, 2026
7708514
Merge remote-tracking branch 'origin' into mwe/dmt_for_stable
michael-weigelt Jun 29, 2026
be5c59c
fuzzers
michael-weigelt Jun 29, 2026
34e0591
fixes
michael-weigelt Jun 29, 2026
9a9b9e5
clippy
michael-weigelt Jun 29, 2026
357e439
Automatically fixing code for linting and formatting issues
Jun 29, 2026
1ce8267
clippy
michael-weigelt Jun 29, 2026
f5e5ad7
clippy
michael-weigelt Jun 29, 2026
63e59bf
Merge branch 'mwe/dmt_for_stable' of github.com:dfinity/ic into mwe/d…
michael-weigelt Jun 29, 2026
bc57908
wip
michael-weigelt Jun 16, 2026
2f15b2f
fixed dts test
michael-weigelt Jun 17, 2026
c5c8edd
wip exe tests
michael-weigelt Jul 2, 2026
7854dc2
fixed exe tests
michael-weigelt Jul 3, 2026
9f5df92
cleanup
michael-weigelt Jul 3, 2026
72bb73e
Merge remote-tracking branch 'origin' into mwe/dmt_for_stable
michael-weigelt Jul 3, 2026
3d833eb
fix hypervisor tests
michael-weigelt Jul 3, 2026
f548632
tests
michael-weigelt Jul 3, 2026
214bc09
simplify
michael-weigelt Jul 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rs/canister_sandbox/src/protocol/sbxsvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ mod tests {
CyclesAccountManagerConfig::application_subnet(),
),
std::sync::Arc::new(NetworkTopology::default()),
NumInstructions::new(42),
ComputeAllocation::zero(),
123,
RequestMetadata::new(0, Time::from_nanos_since_unix_epoch(10)),
Expand Down
5 changes: 1 addition & 4 deletions rs/canister_sandbox/src/sandbox_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ mod tests {
};
use ic_base_types::{NumSeconds, PrincipalId};
use ic_config::embedders::Config as EmbeddersConfig;
use ic_config::subnet_config::{
CyclesAccountManagerConfig, DEFAULT_REFERENCE_SUBNET_SIZE, SchedulerConfig,
};
use ic_config::subnet_config::{CyclesAccountManagerConfig, DEFAULT_REFERENCE_SUBNET_SIZE};
use ic_cycles_account_manager::{
CyclesAccountManager, CyclesAccountManagerSubnetConfig, ResourceSaturation,
};
Expand Down Expand Up @@ -222,7 +220,6 @@ mod tests {
CanisterCyclesCostSchedule::Normal,
DEFAULT_REFERENCE_SUBNET_SIZE,
),
SchedulerConfig::application_subnet().dirty_page_overhead,
CanisterTimer::Inactive,
0,
BTreeSet::from([controller]),
Expand Down
7 changes: 0 additions & 7 deletions rs/config/src/embedders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ pub(crate) const DEFAULT_MAX_DIRTY_PAGES_WITHOUT_OPTIMIZATION: usize = (GIB as u
/// Scheduling overhead for copying dirty pages, in instructions.
pub(crate) const DIRTY_PAGE_COPY_OVERHEAD: NumInstructions = NumInstructions::new(3_000);

/// The overhead for dirty pages in Wasm64.
pub const WASM64_DIRTY_PAGE_OVERHEAD_MULTIPLIER: u64 = 4;

const KIB: u64 = 1024;
const GIB: u64 = KIB * KIB * KIB;

Expand Down Expand Up @@ -245,9 +242,6 @@ pub struct Config {
/// The dirty page copying overhead, in instructions.
pub dirty_page_copy_overhead: NumInstructions,

/// The dirty page overhead factor for Wasm64.
pub wasm64_dirty_page_overhead_multiplier: u64,

/// The maximum allowed size for an uncompressed canister Wasm module.
pub wasm_max_size: NumBytes,

Expand Down Expand Up @@ -298,7 +292,6 @@ impl Config {
max_wasm_memory_size: NumBytes::new(MAX_WASM_MEMORY_IN_BYTES),
max_wasm64_memory_size: NumBytes::new(MAX_WASM64_MEMORY_IN_BYTES),
max_stable_memory_size: NumBytes::new(MAX_STABLE_MEMORY_IN_BYTES),
wasm64_dirty_page_overhead_multiplier: WASM64_DIRTY_PAGE_OVERHEAD_MULTIPLIER,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rs/config/src/subnet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub const DEFAULT_REFERENCE_SUBNET_SIZE: usize = 13;
pub const SEV_REFERENCE_SUBNET_SIZE: usize = 7;

/// Costs for each newly created dirty page in stable memory.
const DEFAULT_DIRTY_PAGE_OVERHEAD: NumInstructions = NumInstructions::new(1_000);
pub const DEFAULT_DIRTY_PAGE_OVERHEAD: NumInstructions = NumInstructions::new(5_000);

/// Accumulated priority reset interval, rounds.
///
Expand Down
1 change: 1 addition & 0 deletions rs/embedders/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ rust_test(
crate = ":embedders",
deps = [
# Keep sorted.
"//rs/config",
"//rs/interfaces",
"//rs/test_utilities",
"//rs/test_utilities/types",
Expand Down
1 change: 1 addition & 0 deletions rs/embedders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ assert_matches = { workspace = true }
canister-test = { path = "../rust_canisters/canister_test" }
criterion = { workspace = true }
embedders_bench = { path = "benches/embedders_bench" }
ic-config = {path = "../config"}
ic-registry-routing-table = { path = "../registry/routing_table" }
ic-test-utilities = { path = "../test_utilities" }
ic-test-utilities-embedders = { path = "../test_utilities/embedders" }
Expand Down
7 changes: 2 additions & 5 deletions rs/embedders/fuzz/src/wasm_executor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ic_wasm::{ICWasmModule, get_system_api_type_for_wasm_method};
use ic_config::{
embedders::Config as EmbeddersConfig,
execution_environment::Config as HypervisorConfig,
subnet_config::{DEFAULT_REFERENCE_SUBNET_SIZE, SchedulerConfig},
embedders::Config as EmbeddersConfig, execution_environment::Config as HypervisorConfig,
subnet_config::DEFAULT_REFERENCE_SUBNET_SIZE,
};
use ic_cycles_account_manager::{CyclesAccountManagerSubnetConfig, ResourceSaturation};
use ic_embedders::{
Expand Down Expand Up @@ -153,14 +152,12 @@ pub(crate) fn get_sandbox_safe_system_state(
api_type: ApiType,
) -> SandboxSafeSystemState {
let cycles_account_manager = CyclesAccountManagerBuilder::new().build();
let dirty_page_overhead = SchedulerConfig::application_subnet().dirty_page_overhead;
let network_topology = NetworkTopology::default();

SandboxSafeSystemState::new_for_testing(
system_state,
cycles_account_manager,
Arc::new(network_topology),
dirty_page_overhead,
ComputeAllocation::default(),
HypervisorConfig::default().subnet_callback_soft_limit as u64,
Default::default(),
Expand Down
1 change: 0 additions & 1 deletion rs/embedders/src/wasm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ fn validate_and_instrument(
module,
config.cost_to_compile_wasm_instruction,
config.metering_type,
config.dirty_page_overhead,
max_wasm_memory_size,
config.max_stable_memory_size,
)?;
Expand Down
4 changes: 0 additions & 4 deletions rs/embedders/src/wasm_utils/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,6 @@ fn replace_system_api_functions(
injected_functions: &InjectedFunctions,
injected_counters: &InjectedCounters,
stable_memory_index: u32,
dirty_page_overhead: NumInstructions,
main_memory_type: WasmMemoryType,
max_wasm_memory_size: NumBytes,
) {
Expand All @@ -1488,7 +1487,6 @@ fn replace_system_api_functions(
injected_functions,
injected_counters,
stable_memory_index,
dirty_page_overhead,
main_memory_type,
max_wasm_memory_size,
) {
Expand Down Expand Up @@ -1564,7 +1562,6 @@ pub(super) fn instrument(
mut module: wirm::Module<'_>,
cost_to_compile_wasm_instruction: NumInstructions,
metering_type: MeteringType,
dirty_page_overhead: NumInstructions,
max_wasm_memory_size: NumBytes,
max_stable_memory_size: NumBytes,
) -> Result<InstrumentationOutput, WasmInstrumentationError> {
Expand Down Expand Up @@ -1633,7 +1630,6 @@ pub(super) fn instrument(
&injected_functions,
&injected_counters,
stable_memory_index,
dirty_page_overhead,
main_memory_type,
max_wasm_memory_size,
);
Expand Down
32 changes: 0 additions & 32 deletions rs/embedders/src/wasm_utils/system_api_replacements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{
};
use ic_interfaces::execution_environment::StableMemoryApi;
use ic_sys::PAGE_SIZE;
use ic_types::NumInstructions;
use wirm::{DataType, ir::types::Instructions, wasmparser::BlockType};

use ic_types::NumBytes;
Expand Down Expand Up @@ -54,7 +53,6 @@ pub(super) fn replacement_functions(
injected_functions: &InjectedFunctions,
injected_counters: &InjectedCounters,
stable_memory_index: u32,
dirty_page_overhead: NumInstructions,
main_memory_type: WasmMemoryType,
max_wasm_memory_size: NumBytes,
) -> Vec<(SystemApiFunc, ReplacementFunction)> {
Expand Down Expand Up @@ -912,21 +910,6 @@ pub(super) fn replacement_functions(
function_index: injected_functions.internal_trap,
},
End,
// Decrement instruction counter to charge for dirty pages
LocalGet {
local_index: DIRTY_PAGE_COUNT,
},
I64ExtendI32U,
I64Const {
value: dirty_page_overhead.get().try_into().unwrap(),
},
I64Mul,
// Bounds check above should guarantee that we don't
// overflow as the over head is a small constant.
Call {
function_index: decr_instruction_counter_fn,
},
Drop,
// perform memory fill
LocalGet {
local_index: BYTEMAP_START,
Expand Down Expand Up @@ -1155,21 +1138,6 @@ pub(super) fn replacement_functions(
function_index: injected_functions.internal_trap,
},
End,
// Decrement instruction counter to charge for dirty pages
LocalGet {
local_index: DIRTY_PAGE_COUNT,
},
I64ExtendI32U,
I64Const {
value: dirty_page_overhead.get().try_into().unwrap(),
},
I64Mul,
// Bounds check above should guarantee that we don't
// overflow as the over head is a small constant.
Call {
function_index: decr_instruction_counter_fn,
},
Drop,
// perform memory fill
LocalGet {
local_index: BYTEMAP_START,
Expand Down
29 changes: 8 additions & 21 deletions rs/embedders/src/wasmtime_embedder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,12 @@ impl WasmtimeEmbedder {
bytemap_name: Some(STABLE_BYTEMAP_MEMORY_NAME),
memory: stable_memory.clone(),
memory_type: CanisterMemoryType::Stable,
// Wasm native stable memory will always be tracked by a
// bytemap within the wasm module.
dirty_page_tracking: DirtyPageTracking::Ignore,
// Wasm native stable memory is tracked by a
// bytemap within the wasm module, but that's used
// only for limiting the memory. The deterministic
// memory tracker accounts for page fault charging,
// same as for the heap pages.
dirty_page_tracking,
});

result
Expand Down Expand Up @@ -640,20 +643,12 @@ impl WasmtimeEmbedder {
main_memory_type = WasmMemoryType::Wasm64;
}

let dirty_page_overhead = match main_memory_type {
WasmMemoryType::Wasm32 => self.config.dirty_page_overhead,
WasmMemoryType::Wasm64 => NumInstructions::from(
self.config.dirty_page_overhead.get()
* self.config.wasm64_dirty_page_overhead_multiplier,
),
};

let memory_trackers = sigsegv_memory_tracker(
memories,
&mut *store,
self.log.clone(),
self.config.feature_flags.deterministic_memory_tracker,
/*dirty_page_overhead*/ NumInstructions::new(1),
self.config.dirty_page_overhead,
subtract_instruction_counter,
);

Expand All @@ -665,7 +660,6 @@ impl WasmtimeEmbedder {
instance_stats: InstanceStats::default(),
store,
modification_tracking,
dirty_page_overhead,
#[cfg(debug_assertions)]
stable_memory_dirty_page_limit: current_dirty_page_limit,
stable_memory_page_access_limit: current_accessed_limit,
Expand Down Expand Up @@ -946,7 +940,6 @@ pub struct WasmtimeInstance {
instance_stats: InstanceStats,
store: Pin<Box<wasmtime::Store<StoreData>>>,
modification_tracking: ModificationTracking,
dirty_page_overhead: NumInstructions,
#[cfg(debug_assertions)]
#[allow(dead_code)]
stable_memory_dirty_page_limit: ic_types::NumOsPages,
Expand Down Expand Up @@ -1217,13 +1210,7 @@ impl WasmtimeInstance {
let access = self.page_accesses()?;
self.set_instance_stats(&access);

// Charge for dirty wasm heap pages.
let x = self.instruction_counter().saturating_sub_unsigned(
self.dirty_page_overhead
.get()
.saturating_mul(access.wasm_dirty_pages.len() as u64),
);
self.set_instruction_counter(x);
// No need to charge for dirty wasm heap pages anymore: The DMT charges directly.

match result {
Ok(_) => Ok(InstanceRunResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
ApiType, CERTIFIED_DATA_MAX_LENGTH, cycles_balance_change::CyclesBalanceChange, routing,
routing::ResolveDestinationError,
};
use ic_base_types::{CanisterId, NumBytes, NumOsPages, NumSeconds, PrincipalId, SubnetId};
use ic_base_types::{CanisterId, NumBytes, NumSeconds, PrincipalId, SubnetId};
use ic_cycles_account_manager::{
CyclesAccountManager, CyclesAccountManagerError, ResourceSaturation,
};
Expand All @@ -26,7 +26,7 @@ use ic_replicated_state::{
};
use ic_types::canister_log::CanisterLogMetrics;
use ic_types::{
CanisterLog, CanisterTimer, ComputeAllocation, MemoryAllocation, NumInstructions, Time,
CanisterLog, CanisterTimer, ComputeAllocation, MemoryAllocation, Time,
messages::{CallContextId, NO_DEADLINE, RejectContext, RequestMetadata},
time::CoarseTime,
};
Expand Down Expand Up @@ -633,7 +633,6 @@ pub struct SandboxSafeSystemState {
pub(super) status: CanisterStatusView,
pub(super) subnet_type: SubnetType,
pub(super) subnet_cycles_config: CyclesAccountManagerSubnetConfig,
dirty_page_overhead: NumInstructions,
freeze_threshold: NumSeconds,
memory_allocation: MemoryAllocation,
wasm_memory_threshold: NumBytes,
Expand Down Expand Up @@ -686,7 +685,6 @@ impl SandboxSafeSystemState {
ic00_available_request_slots: usize,
ic00_aliases: BTreeSet<CanisterId>,
subnet_cycles_config: CyclesAccountManagerSubnetConfig,
dirty_page_overhead: NumInstructions,
global_timer: CanisterTimer,
canister_version: u64,
controllers: BTreeSet<PrincipalId>,
Expand All @@ -702,7 +700,6 @@ impl SandboxSafeSystemState {
status,
subnet_type: cycles_account_manager.subnet_type(),
subnet_cycles_config,
dirty_page_overhead,
freeze_threshold,
memory_allocation,
environment_variables,
Expand Down Expand Up @@ -742,7 +739,6 @@ impl SandboxSafeSystemState {
system_state: &SystemState,
cycles_account_manager: CyclesAccountManager,
network_topology: Arc<NetworkTopology>,
dirty_page_overhead: NumInstructions,
compute_allocation: ComputeAllocation,
available_callbacks: u64,
request_metadata: RequestMetadata,
Expand All @@ -754,7 +750,6 @@ impl SandboxSafeSystemState {
system_state,
cycles_account_manager,
network_topology,
dirty_page_overhead,
compute_allocation,
available_callbacks,
request_metadata,
Expand All @@ -770,7 +765,6 @@ impl SandboxSafeSystemState {
system_state: &SystemState,
cycles_account_manager: CyclesAccountManager,
network_topology: Arc<NetworkTopology>,
dirty_page_overhead: NumInstructions,
compute_allocation: ComputeAllocation,
available_callbacks: u64,
request_metadata: RequestMetadata,
Expand Down Expand Up @@ -847,7 +841,6 @@ impl SandboxSafeSystemState {
ic00_available_request_slots,
ic00_aliases,
subnet_cycles_config,
dirty_page_overhead,
system_state.global_timer,
system_state.canister_version(),
system_state.controllers.clone(),
Expand Down Expand Up @@ -1178,23 +1171,6 @@ impl SandboxSafeSystemState {
Ok(())
}

/// Calculate the cost for newly created dirty pages.
pub fn dirty_page_cost(&self, dirty_pages: NumOsPages) -> HypervisorResult<NumInstructions> {
let (inst, overflow) = dirty_pages
.get()
.overflowing_mul(self.dirty_page_overhead.get());
if overflow {
Err(HypervisorError::ToolchainContractViolation {
error: format!(
"Overflow calculating instruction cost for dirty pages - conversion rate: {}, dirty_pages: {}",
self.dirty_page_overhead, dirty_pages
),
})
} else {
Ok(NumInstructions::from(inst))
}
}

pub fn is_controller(&self, principal_id: &PrincipalId) -> bool {
self.controllers.contains(principal_id)
}
Expand Down Expand Up @@ -1453,7 +1429,7 @@ mod tests {
use std::collections::{BTreeMap, BTreeSet};

use ic_base_types::NumSeconds;
use ic_config::subnet_config::{CyclesAccountManagerConfig, SchedulerConfig};
use ic_config::subnet_config::CyclesAccountManagerConfig;
use ic_cycles_account_manager::{CyclesAccountManager, CyclesAccountManagerSubnetConfig};
use ic_limits::SMALL_APP_SUBNET_MAX_SIZE;
use ic_registry_subnet_type::SubnetType;
Expand Down Expand Up @@ -1593,7 +1569,6 @@ mod tests {
CanisterCyclesCostSchedule::Normal,
ic_config::subnet_config::DEFAULT_REFERENCE_SUBNET_SIZE,
),
SchedulerConfig::application_subnet().dirty_page_overhead,
CanisterTimer::Inactive,
0,
BTreeSet::new(),
Expand Down
Loading
Loading