Page accounting for the RRT/HRRT profiler

For new Rust allocator investigations, a custom local PocketIC build exposes actual per-execution heap access/dirty ranges and their instruction charges. See the memory-access tracing guide for the local client, exact binary identity, viewer and measurement boundaries. The historical release calibrations below keep their original pins. Heavy16 is a workflow/transport workload with minimal scalar reducers; qualify business-map layout separately on populated collections.

Count 4 KiB logical accesses, but do not price each one at 5,000 instructions. The checked IC production source and both PocketIC releases track aligned 64 KiB regions. First access charges 16 OS pages × 5,000 = 80,000 instructions; first write adds another 80,000. This is a metering charge, not ordinary Wasm instructions or a cycle fee. Adjacent logical pages can share one charge. These numeric prices refer to the checked Linux target with 4 KiB OS pages; they are not a portable assertion for every host build. The tracker and price configuration are separate facts.

This estimates in-execution tracking surcharges, not total memory overhead. The pinned executor separately has a 3,000-instruction-per-OS-page dirty-copy scheduling allowance. It applies when DTS and more than 1 GiB of dirty heap trigger a dedicated copy slice. The executor adds it to the slice's scheduler budget after freezing the canister instruction balance; it is outside Counter0 and the instruction-cycle debit. Current Wasm64's 2× instruction-to-cycles price also does not double Counter0 or these modeled instruction fees. Historical dirty_page_overhead and Wasm64 dirty-page multiplier fields are absent from the checked current configurations. API copying, allocation, zeroing and ordinary Wasm work remain outside this page-transition model.

Checked identity Evidence and result
Existing benchmark PocketIC 16.0.0 Source fc21803c; executable SHA256 69e324bd…3792. Preserve this pin for existing matched measurements.
Latest official PocketIC 16.1.0, published 2026-10-08 Release identifies source e9e42a6d. Tracker, pricing/config, stable replacements, execution and DTS core match 16.0 byte for byte. Verified executable SHA256 b44e1ecc…e9db; no active pin change.
IC release 2026-10-16 Tag, commit 661a9806: same production tracker selection and 64 KiB policy.
Observed deployed version Dashboard API snapshot at 2026-10-19 15:04:43 UTC reports all 42 listed subnets at 4a0dbb92; its source also uses this policy. This is an observational API record, not independently certified registry evidence or an on-chain performance probe.
Master observed during review ee8086a9, committed 2026-10-19: same selection/granularity. The initial sibling checkout /srv/shared/ic was at historical 60344996; its older disabled feature default is not the current configuration. The later recheck uses exact Git objects, independently of the checkout's changing HEAD or working tree.

Full commits, source URLs/hashes and the observed deployment list are in source-pins.json and deployed-versions.json. Published release source identity and downloaded executable hash are recorded separately; this is not a claim of a locally reproduced release build. The official compressed asset digest, unpacked digest and version output are in latest-pocketic-binary.json.

Production and PocketIC take the same metering path. Production setup_ic_stack constructs SubnetConfig::new(subnet_type). PocketIC's state-machine builder does the same; its benchmarking mode changes limits, not page pricing. Both reach ExecutionServices::setup_execution, whose helper passes the scheduler's page price to Hypervisor. It overrides the raw embedder configuration's placeholder zero. The embedder constructs DeterministicMemoryTracker directly. There is no remaining runtime deterministic-versus-legacy tracker selector in these checked versions. No evidence supports changing PocketIC to 4 KiB charging to match production. No IC patch or source build was needed.

Actual calibration agrees. The same uninstrumented Wasm ran 11 cases twice on each server, producing 22 exactly equal result objects. These are body Counter0 spans, with argument copy, destination prewarm and reply outside the spans; they are not complete-entry totals.

Operation Observed extra instructions
First 1-byte heap read versus identical immediate repeat 80,000
First read of another 4 KiB page in the same 64 KiB region 0
First read in the next 64 KiB region 80,000
First heap write versus immediate repeat 160,000
First write after the region was already read 80,000
Copy 4 KiB between distinct cold source/destination regions 240,000
Wholly new stable read, then repeat; heap destination prewarmed 255, then 80,255 total body instructions

The last row is not a refund or a timing anomaly. Native stable-read replacement maintains a 4 KiB logical bytemap. When the whole requested range was unaccessed (neither read nor written), it invokes the first-access helper, which reads the saved PageMap buffer directly into the heap. That read bypasses stable-memory tracker faults; heap destination writes remain tracked. A repeated or mixed old/new range instead uses Wasm memory.copy from stable memory and can incur its first stable tracking charge then. Thus the profiler needs separate logical stable-bytemap and charged-region state. A plain stable logical first-touch set cannot reproduce fees.

The bytemap itself is a separate injected memory, not the application heap or stable payload. The embedder gives it read/write protection without registering a tracker. It therefore incurs no additional page-fault fee. Native stable replacements are installed after ordinary instruction-meter injection and explicitly charge their API overhead plus copy length. Counting the bytemap as another application heap touch would invent a charge.

The independent calibration review pins the unchanged Wasm, original sources, both binaries and raw results. It verifies cross-entry reset for two updates. It does not claim callback, DTS, query or high-address calibration from these 11 cases; those require source reasoning or the separate instrumenter fixtures.

Logical coverage is not an exact fee oracle even for heap copies. A separate four-entry probe measured a cold memory.copy(a, a, 4096) at 84,415 instructions versus 4,415 on immediate repeat: an 80,000 surcharge. Copying to a + 1 instead added 160,000. Both ranges have logical read/write semantics, but the identical-address case avoided the real dirty charge. Thus 80000 × (accessed + dirty) remains a model; subtracting it from Counter0 does not isolate ordinary code. Dirty means write-touched, including unchanged stores, rather than a count of final persisted page differences.

The heap source recheck and stable source recheck independently test the scope of these rules. A tiny heap access incurs the region's surcharge; it does not require the application to copy all 64 KiB. Repeated touches in the same tracked execution incur no additional transition fee once the relevant access/dirty state is set, but ordinary load/store and copy instructions still cost work. Stable reads require the separate helper/mapping state described above.

The tracker subtracts charges from the execution's instruction balance. The fault handler itself is not an immediate out-of-instructions trap: metering checkpoints and final accounting handle the resulting balance. Exact counter clamping differs across the checked revisions; this does not make the surcharge free. Also, reviewed master ee8086a9 moves stable64's explicit API/copy debit after its zero-length return and preliminary bounds checks; the pinned PocketIC 16.0/16.1 and observed deployed source 4a0dbb92 debit before them. The ordinary nonzero fee and 64 KiB tracker policy are unchanged. See the source rechecks for these edge cases; do not silently apply newer master behavior to pinned results.

Reset and rollback boundaries matter. New updates, queries, timer entries, self-calls and reply/reject callbacks start new Wasmtime executions and new tracker state. Cleanup is another explicit execution. Internal function calls or future polls are not new boundaries. DTS waits and resumes the same suspended worker/instance, so seen sets must survive slices; an aborted/restarted attempt begins again. Ordinary query API executions use access tracking without dirty tracking. Stateful/composite query executions and their callbacks use both; even an ordinary query endpoint can run in that stateful context inside a composite call graph. Intermediate state is preserved for that graph before external query-state discard. The source recheck distinguishes these modes; the existing calibration did not measure composite-query fees. Traps roll back profiler state too. In-canister committed counters cannot recover the work of trapped or abandoned attempts. Keep snapshot-query hooks excluded, and label successful committed-entry coverage explicitly.

Available metrics are not an exact fee API. The sandbox controller collects access/dirty histograms, labeled by API and memory type, without method, canister or source section. Stable access/dirty counts come from the logical bytemap; they include helper-exempt accesses. Heap counts include the complete tracked regions. Stock 16.0/16.1 routes do not expose a MetricsRegistry scrape or per-section tracker events. get_subnet_metrics and performance_counter do not return exact page addresses or first-touch owners. Exporting existing histograms would therefore not solve scoped charging by itself.

The implemented artifact profiler exposes these separate results:

  1. Logical coverage: aligned 4 KiB read, write and union sets by memory; supported scalar/SIMD/bulk operations plus host API copy/read/write ranges. A write implies access. Growth preserves the application's memory geometry; it is not itself a logical touch. Trapped attempts cannot be recovered from committed counters.
  2. Pinned cost model: independent 64 KiB access/dirty sets and stable-helper selection, with explicit server/config identity. Attribute the first modeled transition to the deepest active scope; inclusive ancestor attribution totals overlap and must not be summed. These are globally first-event attributions, not independent per-scope unique-use sets. Keep wrapper, allocator, codec and teardown work under an unscoped owner when no named scope is active.
  3. Measured totals: ordinary/outer complete instructions, cycles, actual workload and publication tail. Modeled page fees are neither extra charges added to Counter0 nor direct measurements of isolated original code cost.

Host ic0 functions can touch heap bytes without executing user load/store instructions: argument/caller/reject copies write, reply/debug/call-building functions read, and stable calls access both spaces. Missing imports, callback roots, bulk operations or bounds cases must be explicit coverage failures. The host buffer review records conditional output writes and the logging exception; requested buffer lengths alone do not establish touches. Profiler storage must not overlap the app allocator or silently shift heap layout. The implementation uses an aligned private 2 MiB + 64 KiB reservation for shadows, epochs, counters and a bounded scope stack. Globals hold the current depth, label and ancestor mask; prior stack frames live in scratch. Its own memory accesses are excluded from logical application counts but incur real instructions/tracking costs; HRRT BSS/layout movement must be reported. The actual PocketIC calibration validates first-owner arithmetic, representative boundaries, host effects, callbacks and rollback. The promoted artifact tool produces the identical qualified Wasm; it is part of cdk-rsx-wasm, with no second instrumenter runtime. Use the current build commands for new runs; the calibration packet retains its original producer commands and pins. Full-workload profiles must still be judged against matched ordinary execution and observer perturbation. First-owner attribution is not a savings estimate: later work may need the same region. A runtime charge hook would be needed for an independently exact per-section fee oracle, including failed attempts; it remains a separate proposed IC build, not an implemented capability.

The RRT/HRRT heavy16 report provides full-workload qualification and the compact raw evidence packet. With profiling disabled, HRRT matches its selected control exactly and RRT's complete instruction total changes by −0.0003%, with unchanged rounds, latency, aggregate batch totals and memory. With profiling enabled, instructions reach 4.35× the HRRT control and 8.64× the RRT control; instruction-budgeted scheduling and batch packing change too. The resulting page totals therefore describe the diagnostic workload. Read them with entry counts and per-entry means, not as an exact production fee decomposition. Store read/write scopes include their application callbacks; their attributed pages are not solely internal Store overhead.