From 8abb067862ac808deae41e9c1de17c487822b9e8 Mon Sep 17 00:00:00 2001 From: Michael Weigelt Date: Tue, 25 Aug 2026 12:09:59 +0000 Subject: [PATCH] cleanup --- .../src/wasm_utils/system_api_replacements.rs | 6 +- rs/embedders/src/wasmtime_embedder.rs | 2 - rs/embedders/tests/instrumentation.rs | 65 ++++--- .../tests/wasmtime_random_memory_writes.rs | 45 +++-- rs/execution_environment/EXECUTION_COST.md | 37 ++-- .../benches/lib/src/common.rs | 27 ++- .../system_api/execute_inspect_message.rs | 8 +- .../benches/system_api/execute_query.rs | 8 +- .../benches/system_api/execute_update.rs | 182 ++++++++---------- rs/execution_environment/tests/hypervisor.rs | 2 +- .../tests/subnet_size_test.rs | 24 +-- 11 files changed, 191 insertions(+), 215 deletions(-) diff --git a/rs/embedders/src/wasm_utils/system_api_replacements.rs b/rs/embedders/src/wasm_utils/system_api_replacements.rs index 8fda9b58d529..0ea23751cb00 100644 --- a/rs/embedders/src/wasm_utils/system_api_replacements.rs +++ b/rs/embedders/src/wasm_utils/system_api_replacements.rs @@ -7,9 +7,13 @@ //! //! - properly report errors in a backwards-compatible way //! - convert between integer types and check for overflows -//! - track accesses and dirty pages +//! - mark written pages in the bytemap and enforce the accessed/dirty page limits //! - charge for instructions //! +//! The accessed/dirty page counters only enforce the per-message limits; the +//! instructions for touching a page are charged by the deterministic memory +//! tracker from the SIGSEGV handler. +//! use crate::{ InternalErrorCode, WASM_PAGE_SIZE, diff --git a/rs/embedders/src/wasmtime_embedder.rs b/rs/embedders/src/wasmtime_embedder.rs index 5a3f8667a8b6..142382d93018 100644 --- a/rs/embedders/src/wasmtime_embedder.rs +++ b/rs/embedders/src/wasmtime_embedder.rs @@ -1181,8 +1181,6 @@ impl WasmtimeInstance { let access = self.page_accesses()?; self.set_instance_stats(&access); - // No need to charge for dirty wasm heap pages anymore: The DMT charges directly. - match result { Ok(_) => Ok(InstanceRunResult { exported_globals: self.get_exported_globals()?, diff --git a/rs/embedders/tests/instrumentation.rs b/rs/embedders/tests/instrumentation.rs index 85fea593fdb6..1fac006c537c 100644 --- a/rs/embedders/tests/instrumentation.rs +++ b/rs/embedders/tests/instrumentation.rs @@ -280,14 +280,15 @@ fn instr_used(instance: &mut WasmtimeInstance) -> u64 { .get() } -/// Returns the instruction overhead charged in-band by the deterministic memory -/// tracker for the first access to Wasm pages. +/// Returns the number of *OS pages* the deterministic memory tracker charges +/// for in-band when the given Wasm pages are first written. Multiply by +/// `page_overhead` to get instructions. /// -/// - `n_heap_wasm_pages`: pages first *written* on the heap. -/// Each triggers `mark_wasm_page_accessed` + `mark_wasm_page_dirty`: -/// 2 × (WASM_PAGE_SIZE / OS_PAGE_SIZE) = 2 × 16 = 32 instructions. -/// - `n_stable_wasm_pages`: same as for heap: 32 instructions per page. -fn deterministic_tracker_overhead(n_heap_wasm_pages: u64, n_stable_wasm_pages: u64) -> u64 { +/// A first write to a Wasm page triggers both `mark_wasm_page_accessed` and +/// `mark_wasm_page_dirty`, i.e. every OS page it covers is charged twice. The +/// number of OS pages per Wasm page varies by platform (16 for 4 KiB pages on +/// Linux, 4 for 16 KiB pages on arm64-darwin). +fn dmt_write_charged_os_pages(n_heap_wasm_pages: u64, n_stable_wasm_pages: u64) -> u64 { let os_pages_per_wasm_page = (WASM_PAGE_SIZE_IN_BYTES / PAGE_SIZE) as u64; n_heap_wasm_pages * 2 * os_pages_per_wasm_page + n_stable_wasm_pages * 2 * os_pages_per_wasm_page @@ -742,7 +743,7 @@ fn metering_loop() { ); } -fn run_charge_for_dirty_heap(wasm_memory_type: WasmMemoryType) { +fn run_charge_for_heap_pages(wasm_memory_type: WasmMemoryType) { let memory = match wasm_memory_type { WasmMemoryType::Wasm32 => r#"(memory (export "memory") 10)"#, WasmMemoryType::Wasm64 => r#"(memory (export "memory") i64 10)"#, @@ -804,32 +805,32 @@ fn run_charge_for_dirty_heap(wasm_memory_type: WasmMemoryType) { // Both stores target Wasm page 0 (bytes 0 and 4096 are within the 64KB page), // so only one heap page-first-write event occurs. - let overhead = deterministic_tracker_overhead(1, 0); + let dmt_pages = dmt_write_charged_os_pages(1, 0); let instructions_used = instr_used(&mut instance); // Function is 1 instruction. assert_eq!( instructions_used, - 1 + 5 * cc + cg + 2 * cs + cl + overhead * cd + 1 + 5 * cc + cg + 2 * cs + cl + dmt_pages * cd ); - // Now run the same with insufficient instructions - // We should still succeed (to avoid potentially failing pre-upgrades - // of canisters that did not adjust their code to new metering) + // Now run the same with insufficient instructions. We should still succeed + // (to avoid potentially failing pre-upgrades of canisters that did not + // adjust their code to new metering) let mut instance = new_instance(&wat, 100); instance.run(func_ref("test")).unwrap(); } #[test] -fn charge_for_dirty_heap() { - run_charge_for_dirty_heap(WasmMemoryType::Wasm32); +fn charge_for_heap_pages() { + run_charge_for_heap_pages(WasmMemoryType::Wasm32); } #[test] -fn charge_for_dirty_heap_wasm64() { - run_charge_for_dirty_heap(WasmMemoryType::Wasm64); +fn charge_for_heap_pages_wasm64() { + run_charge_for_heap_pages(WasmMemoryType::Wasm64); } -fn run_charge_for_dirty_stable64_test() { +fn run_charge_for_stable64_pages_test() { let wat = r#" (module (import "ic0" "stable64_grow" @@ -911,23 +912,23 @@ fn run_charge_for_dirty_stable64_test() { // Both i64.stores hit heap Wasm page 0; the first stable64_write hits stable // Wasm page 0 (bytes 0 and 4096 are both within the 64KB page). - let overhead = deterministic_tracker_overhead(1, 1); + let dmt_pages = dmt_write_charged_os_pages(1, 1); let instructions_used = instr_used(&mut instance); - // 2 dirty stable pages and one heap + // One heap and one stable Wasm page, each accessed and dirtied. assert_eq!( instructions_used, // Function is 1 instruction. - 1 + cdrop + ccall * 4 + csg + cc * 15 + cs * 2 + csw * 2 + csr + cl + cg + overhead * cd + 1 + cdrop + ccall * 4 + csg + cc * 15 + cs * 2 + csw * 2 + csr + cl + cg + dmt_pages * cd ); } #[test] -fn charge_for_dirty_stable64_native() { - run_charge_for_dirty_stable64_test(); +fn charge_for_stable64_pages_native() { + run_charge_for_stable64_pages_test(); } -fn run_charge_for_dirty_stable_test() { +fn run_charge_for_stable_pages_test() { let wat = r#" (module (import "ic0" "stable_grow" @@ -1009,20 +1010,20 @@ fn run_charge_for_dirty_stable_test() { // Both i32.stores hit heap Wasm page 0; the first stable_write hits stable // Wasm page 0 (bytes 0 and 4096 are both within the 64KB page). - let overhead = deterministic_tracker_overhead(1, 1); + let dmt_pages = dmt_write_charged_os_pages(1, 1); let instructions_used = instr_used(&mut instance); - // 2 dirty stable pages and one heap + // One heap and one stable Wasm page, each accessed and dirtied. assert_eq!( instructions_used, // Function is 1 instruction. - 1 + cdrop + ccall * 4 + csg + cc * 15 + cs * 2 + csw * 2 + csr + cl + cg + overhead * cd + 1 + cdrop + ccall * 4 + csg + cc * 15 + cs * 2 + csw * 2 + csr + cl + cg + dmt_pages * cd ); } #[test] -fn charge_for_dirty_stable_native() { - run_charge_for_dirty_stable_test(); +fn charge_for_stable_pages_native() { + run_charge_for_stable_pages_test(); } /// Helper method to generate a wasm module with tables in both @@ -1164,7 +1165,7 @@ fn metering_wasm64_load_store_canister() { let drop = instruction_to_cost(&wasmparser::Operator::Drop, WasmMemoryType::Wasm64); // Both stores hit Wasm page 0 (bytes 0 and 4096 are within the 64KB page), // so only one heap page-first-write event occurs. - let overhead = deterministic_tracker_overhead(1, 0); + let dmt_pages = dmt_write_charged_os_pages(1, 0); let total_cost = 1 + 2 * const_0 + const_17 @@ -1173,7 +1174,7 @@ fn metering_wasm64_load_store_canister() { + 2 * store + load + drop - + overhead * page_overhead.get(); + + dmt_pages * page_overhead.get(); assert_eq!(instr_used_wasm64, total_cost); // Compute cost in Wasm32 mode and compare. @@ -1243,7 +1244,7 @@ fn metering_wasm64_load_store_canister() { + 2 * store_wasm32 + load_wasm32 + drop_wasm32 - + overhead * page_overhead.get(); + + dmt_pages * page_overhead.get(); assert_eq!(wasm_32_instructions, total_cost_wasm32); // Check that the cost in Wasm64 mode is higher than in Wasm32 mode. diff --git a/rs/embedders/tests/wasmtime_random_memory_writes.rs b/rs/embedders/tests/wasmtime_random_memory_writes.rs index 04922d25d430..92ef3a9d207a 100644 --- a/rs/embedders/tests/wasmtime_random_memory_writes.rs +++ b/rs/embedders/tests/wasmtime_random_memory_writes.rs @@ -50,9 +50,10 @@ const TEST_DEFAULT_LOG_MEMORY_LIMIT: usize = 4 * 1024; // 4 KiB const OS_PAGES_PER_WASM_PAGE: usize = ic_replicated_state::canister_state::WASM_PAGE_SIZE_IN_BYTES / ic_sys::PAGE_SIZE; -/// Returns the per-Wasm-page instruction charge applied by the deterministic -/// memory tracker. -fn dsm_charge_per_wasm_page() -> u64 { +/// Returns the number of *instructions* the deterministic memory tracker +/// charges for a single Wasm page event (accessed or dirty): `page_overhead` +/// per OS page covered by the Wasm page. +fn dmt_instructions_per_wasm_page() -> u64 { OS_PAGES_PER_WASM_PAGE as u64 * DEFAULT_PAGE_OVERHEAD.get() } @@ -838,8 +839,8 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_READ .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -862,8 +863,8 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE64_READ .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -885,8 +886,8 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_READ .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -909,8 +910,9 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_WRITE .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -932,8 +934,9 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_WRITE .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -956,8 +959,9 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_WRITE .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } @@ -979,8 +983,9 @@ mod tests { + ic_embedders::wasmtime_embedder::system_api_complexity::overhead::STABLE_WRITE .get() + STABLE_OP_BYTES - + dsm_charge_per_wasm_page() - + dsm_charge_per_wasm_page() + dsm_charge_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() + + dmt_instructions_per_wasm_page() ); } } @@ -1005,10 +1010,12 @@ mod tests { // The deterministic memory tracker charges at 64 KiB Wasm page // granularity. Use InstanceStats to get the actual Wasm page // counts and compute the exact tracker charge. + let per_page = dmt_instructions_per_wasm_page(); let tracker_charge = |stats: &ic_interfaces::execution_environment::InstanceStats| -> u64 { - stats.wasm_accessed_wasm_pages_count as u64 * dsm_charge_per_wasm_page() - + stats.wasm_dirty_wasm_pages_count as u64 * dsm_charge_per_wasm_page() + (stats.wasm_accessed_wasm_pages_count as u64 + + stats.wasm_dirty_wasm_pages_count as u64) + * per_page }; let (instructions_consumed_without_data, _dry_run_stats, dry_run_instance_stats) = diff --git a/rs/execution_environment/EXECUTION_COST.md b/rs/execution_environment/EXECUTION_COST.md index ae2c1b482e0c..8dd7ae95632e 100644 --- a/rs/execution_environment/EXECUTION_COST.md +++ b/rs/execution_environment/EXECUTION_COST.md @@ -26,21 +26,6 @@ by `DEFAULT_COST_TO_COMPILE_WASM_INSTRUCTION` and other compilation limits. TODO(EXC-2040): There is no script to derive the cost based on benchmark results. -Heap Memory Overhead --------------------- - -Each Wasm heap memory page has an associated overhead defined -by `DEFAULT_PAGE_OVERHEAD` and other costs. - -1. ✅ Runs daily on CI. -2. ✅ Results are available in [Grafana](https://grafana.mainnet.dfinity.network/d/benchmarks-embedders-heap/benchmarks3a-embedders-heap). -3. ✅ Raw benchmark: - * `bazel run //rs/embedders:heap_bench` -4. ✅ Baseline comparison: - * `INCLUDE=heap ./rs/execution_environment/benches/run-all-benchmarks.sh` - -TODO(EXC-2040): There is no script to derive the cost based on benchmark results. - Management Canister Calls ------------------------- @@ -60,18 +45,24 @@ Scripts: `rs/execution_environment/benches/management_canister/*` 1. Run `run_snapshot_benchmarks_forever.sh` to generate the `MANAGEMENT_CANISTER.md` file. -Stable Memory Overhead ----------------------- +Memory Overhead +--------------- -Each Wasm stable memory page has an associated overhead defined -by `DEFAULT_PAGE_OVERHEAD` and other costs. +Heap and stable memory pages share the same overhead, defined by +`DEFAULT_PAGE_OVERHEAD` and other costs. It is charged per OS page by the +deterministic memory tracker, once when a page is first accessed and once more +when it is first dirtied. The two memories are benchmarked separately. 1. ✅ Runs daily on CI. -2. ✅ Results are available in [Grafana](https://grafana.mainnet.dfinity.network/d/benchmarks-embedders-stable-memory/benchmarks3a-embedders-stable-memory). -3. ✅ Raw benchmark: - * `bazel run //rs/embedders:stable_memory_bench` +2. ✅ Results are available in Grafana for: + * [heap](https://grafana.mainnet.dfinity.network/d/benchmarks-embedders-heap/benchmarks3a-embedders-heap) + * [stable memory](https://grafana.mainnet.dfinity.network/d/benchmarks-embedders-stable-memory/benchmarks3a-embedders-stable-memory) +3. ✅ Raw benchmarks: + * Heap: `bazel run //rs/embedders:heap_bench` + * Stable memory: `bazel run //rs/embedders:stable_memory_bench` 4. ✅ Baseline comparison: - * `INCLUDE=stable ./rs/execution_environment/benches/run-all-benchmarks.sh` + * Heap: `INCLUDE=heap ./rs/execution_environment/benches/run-all-benchmarks.sh` + * Stable memory: `INCLUDE=stable ./rs/execution_environment/benches/run-all-benchmarks.sh` TODO(EXC-2040): There is no script to derive the cost based on benchmark results. diff --git a/rs/execution_environment/benches/lib/src/common.rs b/rs/execution_environment/benches/lib/src/common.rs index 2b2a8d3cb05b..af251fda8a7d 100644 --- a/rs/execution_environment/benches/lib/src/common.rs +++ b/rs/execution_environment/benches/lib/src/common.rs @@ -70,28 +70,27 @@ lazy_static! { ); } -/// Returns the extra instruction overhead charged by the deterministic memory -/// tracker for `n_wasm_pages` Wasm pages first accessed without dirty tracking -/// (e.g. read-only accesses or non-replicated execution). +/// Returns the number of *instructions* the deterministic memory tracker +/// charges for first accessing `n_wasm_pages` Wasm pages without dirty tracking +/// (read-only accesses or non-replicated execution). /// /// Each first-accessed Wasm page (64 KiB) triggers `mark_wasm_page_accessed`, -/// which charges `page_overhead` instructions per OS page in-band via the -/// SIGSEGV handler. The number of OS pages per Wasm page varies by platform +/// which charges `DEFAULT_PAGE_OVERHEAD` instructions per OS page in-band via +/// the SIGSEGV handler. The number of OS pages per Wasm page varies by platform /// (4 KiB pages on Linux, 16 KiB on arm64-darwin). -pub fn deterministic_tracker_overhead(n_wasm_pages: u64) -> u64 { +pub fn dmt_access_instructions(n_wasm_pages: u64) -> u64 { const WASM_PAGE_SIZE: u64 = 65536; n_wasm_pages * (WASM_PAGE_SIZE / ic_sys::PAGE_SIZE as u64) * DEFAULT_PAGE_OVERHEAD.get() } -/// Returns the extra instruction overhead charged by the deterministic memory -/// tracker for `n_wasm_pages` Wasm heap pages first written in replicated -/// execution (DirtyPageTracking::Track). +/// Returns the number of *instructions* the deterministic memory tracker +/// charges for first writing `n_wasm_pages` Wasm pages with dirty tracking +/// (replicated execution, `DirtyPageTracking::Track`). /// -/// Each first-written Wasm page triggers both `mark_wasm_page_accessed` and -/// `mark_wasm_page_dirty` via the SIGSEGV handler, charging `page_overhead` -/// instructions twice per OS page. -pub fn deterministic_tracker_write_overhead(n_wasm_pages: u64) -> u64 { - 2 * deterministic_tracker_overhead(n_wasm_pages) +/// Each such page triggers both `mark_wasm_page_accessed` and +/// `mark_wasm_page_dirty`, i.e. it is charged twice per OS page. +pub fn dmt_write_instructions(n_wasm_pages: u64) -> u64 { + 2 * dmt_access_instructions(n_wasm_pages) } /// Pieces needed to execute a benchmark. diff --git a/rs/execution_environment/benches/system_api/execute_inspect_message.rs b/rs/execution_environment/benches/system_api/execute_inspect_message.rs index f01a79f03599..b5d3c14ad591 100644 --- a/rs/execution_environment/benches/system_api/execute_inspect_message.rs +++ b/rs/execution_environment/benches/system_api/execute_inspect_message.rs @@ -56,7 +56,7 @@ pub fn execute_inspect_message_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 520000511 + common::deterministic_tracker_overhead(1), + 520000511 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_method_name_copy()/1B".into(), @@ -66,7 +66,7 @@ pub fn execute_inspect_message_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 520000511 + common::deterministic_tracker_overhead(1), + 520000511 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_method_name_copy()/20B".into(), @@ -76,7 +76,7 @@ pub fn execute_inspect_message_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 539000511 + common::deterministic_tracker_overhead(1), + 539000511 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_method_name_copy()/20B".into(), @@ -86,7 +86,7 @@ pub fn execute_inspect_message_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 539000511 + common::deterministic_tracker_overhead(1), + 539000511 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_accept_message()*".into(), diff --git a/rs/execution_environment/benches/system_api/execute_query.rs b/rs/execution_environment/benches/system_api/execute_query.rs index 067ed7ca69a9..e76620c24adf 100644 --- a/rs/execution_environment/benches/system_api/execute_query.rs +++ b/rs/execution_environment/benches/system_api/execute_query.rs @@ -56,7 +56,7 @@ pub fn execute_query_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 520000006 + common::deterministic_tracker_overhead(1), + 520000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_data_certificate_copy()/1B".into(), @@ -66,7 +66,7 @@ pub fn execute_query_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 520000006 + common::deterministic_tracker_overhead(1), + 520000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_data_certificate_copy()/64B".into(), @@ -76,7 +76,7 @@ pub fn execute_query_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 583000006 + common::deterministic_tracker_overhead(1), + 583000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_data_certificate_copy()/64B".into(), @@ -86,7 +86,7 @@ pub fn execute_query_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 583000006 + common::deterministic_tracker_overhead(1), + 583000006 + common::dmt_access_instructions(1), ), ]; let sender = PrincipalId::new_node_test_id(common::REMOTE_CANISTER_ID); diff --git a/rs/execution_environment/benches/system_api/execute_update.rs b/rs/execution_environment/benches/system_api/execute_update.rs index e825b75f9374..14792be3a43d 100644 --- a/rs/execution_environment/benches/system_api/execute_update.rs +++ b/rs/execution_environment/benches/system_api/execute_update.rs @@ -117,7 +117,7 @@ pub fn execute_update_bench(c: &mut Criterion) { ), Wasm64::Disabled, ), - 16000006 + common::deterministic_tracker_overhead(1), + 16000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/baseline/adds".into(), @@ -134,7 +134,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Wasm64::Enabled, ), // Number of instructions is different in Wasm64 mode because charging is different, i.e., instructions have different weights. - 17000006 + common::deterministic_tracker_overhead(1), + 17000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_caller_size()".into(), @@ -154,7 +154,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_caller_copy()/1B".into(), @@ -164,7 +164,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_caller_copy()/10B".into(), @@ -174,7 +174,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 10B max - 529000006 + common::deterministic_tracker_write_overhead(1), + 529000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm364/ic0_msg_caller_copy()/10B".into(), @@ -184,7 +184,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 10B max - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_arg_data_size()".into(), @@ -204,7 +204,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_arg_data_copy()/1B".into(), @@ -214,7 +214,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_arg_data_copy()/1K".into(), @@ -224,7 +224,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 1_543_000_006 + common::deterministic_tracker_write_overhead(1), + 1_543_000_006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_arg_data_copy()/1K".into(), @@ -234,7 +234,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 1_543_000_006 + common::deterministic_tracker_write_overhead(1), + 1_543_000_006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_reply()*".into(), @@ -276,7 +276,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 2MiB max - 568000006 + common::deterministic_tracker_overhead(1), + 568000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_reply_data_append()/1B".into(), @@ -286,7 +286,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 2MiB max - 568000006 + common::deterministic_tracker_overhead(1), + 568000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_reply_data_append()/2B".into(), @@ -296,7 +296,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 2MiB max - 618000006 + common::deterministic_tracker_overhead(1), + 618000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_reply_data_append()/2B".into(), @@ -306,7 +306,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 2MiB max - 618000006 + common::deterministic_tracker_overhead(1), + 618000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_reject()*".into(), @@ -363,7 +363,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_canister_self_copy()/1B".into(), @@ -373,7 +373,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 520000006 + common::deterministic_tracker_write_overhead(1), + 520000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_canister_self_copy()/10B".into(), @@ -383,7 +383,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 10B max - 529000006 + common::deterministic_tracker_write_overhead(1), + 529000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_canister_self_copy()/10B".into(), @@ -393,12 +393,12 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 10B max - 529000006 + common::deterministic_tracker_write_overhead(1), + 529000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_debug_print()/1B".into(), Module::Test.from_ic0("debug_print", Params2(0, 1), Result::No, Wasm64::Disabled), - 170000006 + common::deterministic_tracker_overhead(1), + 170000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_debug_print()/1B".into(), @@ -408,7 +408,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 170000006 + common::deterministic_tracker_overhead(1), + 170000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_debug_print()/1K".into(), @@ -418,7 +418,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 47366018006 + common::deterministic_tracker_overhead(1), + 47366018006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_debug_print()/1K".into(), @@ -428,17 +428,17 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 47366018006 + common::deterministic_tracker_overhead(1), + 47366018006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_call_new()".into(), Module::CallNewLoop.from_sections(("", "", ""), Wasm64::Disabled), // call_new in a loop is rendered by default - 1552000006 + common::deterministic_tracker_overhead(1), + 1552000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_call_new()".into(), Module::CallNewLoop.from_sections(("", "", ""), Wasm64::Enabled), // call_new in a loop is rendered by default - 1552000006 + common::deterministic_tracker_overhead(1), + 1552000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_cycles_add()".into(), @@ -448,7 +448,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 2058000006 + common::deterministic_tracker_overhead(1), + 2058000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_data_append()/1B".into(), @@ -458,7 +458,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 2MiB max - 2109000006 + common::deterministic_tracker_overhead(1), + 2109000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_data_append()/1B".into(), @@ -468,7 +468,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 2MiB max - 2109000006 + common::deterministic_tracker_overhead(1), + 2109000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_data_append()/1K".into(), @@ -478,7 +478,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 53259000006 + common::deterministic_tracker_overhead(1), + 53259000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_data_append()/1K".into(), @@ -488,7 +488,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 53259000006 + common::deterministic_tracker_overhead(1), + 53259000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_on_cleanup()".into(), @@ -498,7 +498,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 2059000006 + common::deterministic_tracker_overhead(1), + 2059000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_on_cleanup()".into(), @@ -508,7 +508,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 2059000006 + common::deterministic_tracker_overhead(1), + 2059000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_cycles_add128()".into(), @@ -518,7 +518,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 2059000006 + common::deterministic_tracker_overhead(1), + 2059000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_cycles_add128()".into(), @@ -528,17 +528,17 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 2059000006 + common::deterministic_tracker_overhead(1), + 2059000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/call_new+ic0_call_perform()".into(), Module::CallNewLoop.from_ic0("call_perform", NoParams, Result::I32, Wasm64::Disabled), - 6558000006 + common::deterministic_tracker_overhead(1), + 6558000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_perform()".into(), Module::CallNewLoop.from_ic0("call_perform", NoParams, Result::I32, Wasm64::Enabled), - 6558000006 + common::deterministic_tracker_overhead(1), + 6558000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable64_size()".into(), @@ -558,7 +558,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 2058000006 + common::deterministic_tracker_overhead(1), + 2058000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/call_new+ic0_call_with_best_effort_response()".into(), @@ -568,7 +568,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 2058000006 + common::deterministic_tracker_overhead(1), + 2058000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable_size()".into(), @@ -604,9 +604,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Wasm64::Disabled, ), // stable_read writes to Wasm heap (+32) and reads from stable memory (+16) - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable64_read()/1B".into(), @@ -616,9 +614,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_stable64_read()/1B".into(), @@ -628,9 +624,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable_read()/1K".into(), @@ -640,9 +634,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable64_read()/1K".into(), @@ -652,9 +644,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_stable64_read()/1K".into(), @@ -664,9 +654,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable_write()/1B".into(), @@ -677,9 +665,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Wasm64::Disabled, ), // stable_write reads from Wasm heap (+16) and writes to stable memory (+32) - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable64_write()/1B".into(), @@ -689,9 +675,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_stable64_write()/1B".into(), @@ -701,9 +685,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 40000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 40000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable_write()/1K".into(), @@ -713,9 +695,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_stable64_write()/1K".into(), @@ -725,9 +705,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_stable64_write()/1K".into(), @@ -737,9 +715,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 1063000113 - + common::deterministic_tracker_write_overhead(1) - + common::deterministic_tracker_overhead(1), + 1063000113 + common::dmt_write_instructions(1) + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_time()".into(), @@ -809,7 +785,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_canister_cycle_balance128()".into(), @@ -819,7 +795,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_cycles_available()".into(), @@ -839,7 +815,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_cycles_available128()".into(), @@ -849,7 +825,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_cycles_accept()".into(), @@ -869,7 +845,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_msg_cycles_accept128()".into(), @@ -879,7 +855,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_data_certificate_present()".into(), @@ -909,7 +885,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 519000006 + common::deterministic_tracker_overhead(1), + 519000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_certified_data_set()/1B".into(), @@ -919,7 +895,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 519000006 + common::deterministic_tracker_overhead(1), + 519000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_certified_data_set()/32B".into(), @@ -929,7 +905,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), // 32B max - 550000006 + common::deterministic_tracker_overhead(1), + 550000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_certified_data_set()/32B".into(), @@ -939,7 +915,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), // 32B max - 550000006 + common::deterministic_tracker_overhead(1), + 550000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_canister_status()".into(), @@ -959,7 +935,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 19000006 + common::deterministic_tracker_write_overhead(1), + 19000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_mint_cycles128()".into(), @@ -969,7 +945,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 19000006 + common::deterministic_tracker_write_overhead(1), + 19000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_is_controller()".into(), @@ -979,7 +955,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Disabled, ), - 1048000006 + common::deterministic_tracker_overhead(1), + 1048000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_is_controller()".into(), @@ -989,7 +965,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Enabled, ), - 1048000006 + common::deterministic_tracker_overhead(1), + 1048000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_in_replicated_execution()".into(), @@ -1019,7 +995,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_cycles_burn128()".into(), @@ -1029,7 +1005,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_msg_deadline()".into(), @@ -1049,7 +1025,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_call()".into(), @@ -1059,7 +1035,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_cost_create_canister()".into(), @@ -1069,7 +1045,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_create_canister()".into(), @@ -1079,7 +1055,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 517000006 + common::deterministic_tracker_write_overhead(1), + 517000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm32/ic0_cost_http_request()".into(), @@ -1089,7 +1065,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Disabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_http_request()".into(), @@ -1099,7 +1075,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::No, Wasm64::Enabled, ), - 519000006 + common::deterministic_tracker_write_overhead(1), + 519000006 + common::dmt_write_instructions(1), ), { let serialized_params = candid::encode_one(COST_HTTP_REQUEST_V2_PARAMS).unwrap(); @@ -1121,7 +1097,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Wasm64::Disabled, ), // reads params from heap then writes result to heap (same page) → +32 - 10019000006 + common::deterministic_tracker_write_overhead(1), + 10019000006 + common::dmt_write_instructions(1), ) }, { @@ -1143,7 +1119,7 @@ pub fn execute_update_bench(c: &mut Criterion) { }, Wasm64::Enabled, ), - 10019000006 + common::deterministic_tracker_write_overhead(1), + 10019000006 + common::dmt_write_instructions(1), ) }, common::Benchmark( @@ -1155,7 +1131,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Wasm64::Disabled, ), // reads key name from heap (src=1, size=2); key not found → no write to dst - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_sign_with_ecdsa()".into(), @@ -1165,7 +1141,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Enabled, ), - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_cost_sign_with_schnorr()".into(), @@ -1175,7 +1151,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Disabled, ), - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_sign_with_schnorr()".into(), @@ -1185,7 +1161,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Enabled, ), - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm32/ic0_cost_vetkd_derive_key()".into(), @@ -1195,7 +1171,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Disabled, ), - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), common::Benchmark( "wasm64/ic0_cost_vetkd_derive_key()".into(), @@ -1205,7 +1181,7 @@ pub fn execute_update_bench(c: &mut Criterion) { Result::I32, Wasm64::Enabled, ), - 523000006 + common::deterministic_tracker_overhead(1), + 523000006 + common::dmt_access_instructions(1), ), ]; diff --git a/rs/execution_environment/tests/hypervisor.rs b/rs/execution_environment/tests/hypervisor.rs index 2a23ed3e5891..7cd24254e835 100644 --- a/rs/execution_environment/tests/hypervisor.rs +++ b/rs/execution_environment/tests/hypervisor.rs @@ -7879,7 +7879,7 @@ fn division_by_zero() { #[test] #[cfg(not(all(target_arch = "aarch64", target_vendor = "apple")))] -fn charge_for_dirty_pages() { +fn charge_for_accessed_and_dirty_pages() { let mut test = ExecutionTestBuilder::new() .with_instruction_limit(100_000_000) .with_metering_type(ic_config::embedders::MeteringType::New) diff --git a/rs/execution_environment/tests/subnet_size_test.rs b/rs/execution_environment/tests/subnet_size_test.rs index bed47a11f55a..e4647485377f 100644 --- a/rs/execution_environment/tests/subnet_size_test.rs +++ b/rs/execution_environment/tests/subnet_size_test.rs @@ -36,14 +36,15 @@ pub const VETKD_FEE: Cycles = Cycles::new(10 * B as u128); const DEFAULT_CYCLES_PER_NODE: Cycles = Cycles::new(100 * B as u128); const TEST_CANISTER_INSTALL_EXECUTION_INSTRUCTIONS: u64 = 0; -/// Returns the extra instruction overhead charged in-band by the deterministic -/// memory tracker for `n_wasm_pages` Wasm pages first written in replicated -/// mode (DirtyPageTracking::Track). Each such page triggers both -/// `mark_wasm_page_accessed` and `mark_wasm_page_dirty`, i.e. it is charged -/// twice per OS page. The result is a page count, to be multiplied by -/// `page_overhead`. The OS page size varies by platform (4 KiB on Linux, 16 KiB -/// on arm64-darwin). -fn deterministic_tracker_write_overhead(n_wasm_pages: u64) -> u64 { +/// Returns the number of *OS pages* the deterministic memory tracker charges +/// for in-band when `n_wasm_pages` Wasm pages are first written in replicated +/// mode (`DirtyPageTracking::Track`). Multiply by `page_overhead` to get +/// instructions. +/// +/// Each such page triggers both `mark_wasm_page_accessed` and +/// `mark_wasm_page_dirty`, i.e. every OS page it covers is charged twice. The +/// OS page size varies by platform (4 KiB on Linux, 16 KiB on arm64-darwin). +fn dmt_write_charged_os_pages(n_wasm_pages: u64) -> u64 { use ic_sys::PAGE_SIZE; const WASM_PAGE_SIZE: u64 = 65536; n_wasm_pages * 2 * (WASM_PAGE_SIZE / PAGE_SIZE as u64) @@ -1119,10 +1120,9 @@ fn test_subnet_size_execute_message_cost() { let config = get_cycles_account_manager_config(subnet_type); let reference_subnet_size = DEFAULT_REFERENCE_SUBNET_SIZE; // The `inc` method writes to the heap (first access), so the deterministic - // memory tracker charges an extra 32 instructions in-band (accessed + dirty - // for 1 Wasm page) when enabled. + // memory tracker charges in-band for one Wasm page, accessed and dirty. let reference_instructions_cost = inc_instruction_cost(HypervisorConfig::default()) - + page_overhead * deterministic_tracker_write_overhead(1); + + page_overhead * dmt_write_charged_os_pages(1); let reference_cost = calculate_execution_cost( &config, NumInstructions::from(reference_instructions_cost), @@ -1132,7 +1132,7 @@ fn test_subnet_size_execute_message_cost() { // Check default cost. assert_eq!( reference_instructions_cost, - 1019 + page_overhead * deterministic_tracker_write_overhead(1) + 1019 + page_overhead * dmt_write_charged_os_pages(1) ); let simulated_cost = simulate_execute_message_cost(subnet_type, reference_subnet_size); assert_eq!(