Skip to content

feat: Further limit message memory on small nodes#10757

Open
schneiderstefan wants to merge 1 commit into
masterfrom
stschnei/smaller-message-memory
Open

feat: Further limit message memory on small nodes#10757
schneiderstefan wants to merge 1 commit into
masterfrom
stschnei/smaller-message-memory

Conversation

@schneiderstefan

Copy link
Copy Markdown
Contributor

This PR addresses an issue when running a subnet with nodes that have limited RAM. The message memory, i.e. the storage required by messages in queues, used to be bound only by a constant of 20 GB. This is however not safe as they are currently kept fully in RAM, and some newer nano nodes will have as little as 8 GB of RAM.

Those subnets however already limit the heap delta using a parameter in the registry, as the heap delta is also stored in RAM. This commit simply reuses the heap delta limit to also give an upper bound on the message memory. Both bounded and unbounded wait messages are now limited to min(heap_delta/3, old_constant). On large nodes, this commit makes no difference at all.

Most code changes are due to the fact that message memory is no longer a fixed value that can be set at replica startup, and accompanying necessary changes to the test framework.

This PR addresses an issue when running a subnet with nodes that have
limited RAM. The message memory, i.e. the storage required by messages
in queues, used to be bound only by a constant of 20 GB. This is however
not safe as they are currently kept fully in RAM, and some newer nano
nodes will have as little as 8 GB of RAM.

Those subnets however already limit the heap delta using a parameter in
the registry, as the heap delta is also stored in RAM. This commit
simply reuses the heap delta limit to also give an upper bound on the
message memory. Both bounded and unbounded wait messages are now limited
to min(heap_delta/3, old_constant). On large nodes, this commit makes no
difference at all.

Most code changes are due to the fact that message memory is no longer a
fixed value that can be set at replica startup, and accompanying
necessary changes to the test framework.
@schneiderstefan schneiderstefan requested review from a team as code owners July 13, 2026 13:52
@github-actions github-actions Bot added the feat label Jul 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request changes code owned by the Governance team. Therefore, make sure that
you have considered the following (for Governance-owned code):

  1. Update unreleased_changelog.md (if there are behavior changes, even if they are
    non-breaking).

  2. Are there BREAKING changes?

  3. Is a data migration needed?

  4. Security review?

How to Satisfy This Automatic Review

  1. Go to the bottom of the pull request page.

  2. Look for where it says this bot is requesting changes.

  3. Click the three dots to the right.

  4. Select "Dismiss review".

  5. In the text entry box, respond to each of the numbered items in the previous
    section, declare one of the following:

  • Done.

  • $REASON_WHY_NO_NEED. E.g. for unreleased_changelog.md, "No
    canister behavior changes.", or for item 2, "Existing APIs
    behave as before.".

Brief Guide to "Externally Visible" Changes

"Externally visible behavior change" is very often due to some NEW canister API.

Changes to EXISTING APIs are more likely to be "breaking".

If these changes are breaking, make sure that clients know how to migrate, how to
maintain their continuity of operations.

If your changes are behind a feature flag, then, do NOT add entrie(s) to
unreleased_changelog.md in this PR! But rather, add entrie(s) later, in the PR
that enables these changes in production.

Reference(s)

For a more comprehensive checklist, see here.

GOVERNANCE_CHECKLIST_REMINDER_DEDUP

@zeropath-ai

zeropath-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 2af38e7.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/config/src/execution_environment.rs
    Convert SUBNET_HEAP_DELTA_CAPACITY from crate-private to public; add helper functions for message memory capacities and heap delta capacity calculations; add heap_delta_capacity_for_message_memory helper; implement message_memory_capacity logic; expose capacity fields in Config and tests updates to use new helpers and state metadata
Enhancement ► rs/execution_environment/src/execution_environment.rs
    Use guaranteed_response_message_memory_capacity via state.metadata instead of config field; rely on heap delta capacity and new functions to determine capacity
Enhancement ► rs/execution_environment/src/scheduler/test_utilities.rs
    Update test builder and defaults to use maximum_state_delta (heap delta capacity) rather than direct guaranteed/best-effort memory fields; propagate maximum_state_delta into test state setup
Enhancement ► rs/messaging/BUILD.bazel
    Add dependency on registry/resource_limits in test suite
Enhancement ► rs/messaging/src/message_routing.rs
    Adjust StreamHandlerImpl creation to remove direct hypervisor_config usage; rely on metadata-based capacities
Enhancement ► rs/messaging/src/routing/stream_handler.rs
    Remove direct guaranteed_response_message_memory_capacity field from StreamHandlerImpl; stop passing hypervisor_config; use metadata-based capacity
Enhancement ► rs/messaging/src/routing/stream_handler/tests.rs
    Refactor tests to supply memory limits via heap_delta_capacity_for_message_memory and maximum_state_delta; adapt test setup helpers accordingly
Enhancement ► rs/messaging/src/state_machine.rs
    Shed messages using capacity from state.metadata.best_effort_message_memory_capacity() instead of a fixed field; align with new metadata-based capacity
Enhancement ► rs/messaging/src/state_machine/tests.rs
    Update tests to accommodate removal of direct hypervisor_config fields; rely on metadata-based capacities and test scaffolding changes
Enhancement ► rs/messaging/tests/common/mod.rs
    Update test subnet config to use ResourceLimits for maximum_state_delta via heap_delta_capacity_for_message_memory; simplify hypervisor config initialization
Enhancement ► rs/registry/resource_limits/src/lib.rs
    Add maximum_state_delta_or(default) helper to choose registry override or default heap delta capacity
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Expose guaranteed_response_message_memory_capacity and best_effort_message_memory_capacity methods; add heap_delta_capacity helper and compute capacities from heap delta capacity; use maximum_state_delta_or for effective capacity
Enhancement ► rs/state_machine_tests/src/lib.rs
Introduce resource_limits field in StateMachineConfig; add with_resource_limits builder; propagate resource_limits into StateMachine initialization
Enhancement ► rs/state_machine_tests/src/lib.rs
Thread resource_limits into multi-subnet setup and state creation for tests
Enhancement ► rs/test_utilities/execution_environment/src/lib.rs
Use heap_delta_capacity_for_message_memory to configure maximum_state_delta for tests; propagate resource limits into execution test builder setup

@zeropath-ai

zeropath-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 2af38e7.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/config/src/execution_environment.rs
    Convert SUBNET_HEAP_DELTA_CAPACITY from crate-private to public; add helper functions for message memory capacities and heap delta capacity calculations; add heap_delta_capacity_for_message_memory helper; implement message_memory_capacity logic; expose capacity fields in Config and tests updates to use new helpers and state metadata
Enhancement ► rs/execution_environment/src/execution_environment.rs
    Use guaranteed_response_message_memory_capacity via state.metadata instead of config field; rely on heap delta capacity and new functions to determine capacity
Enhancement ► rs/execution_environment/src/scheduler/test_utilities.rs
    Update test builder and defaults to use maximum_state_delta (heap delta capacity) rather than direct guaranteed/best-effort memory fields; propagate maximum_state_delta into test state setup
Enhancement ► rs/messaging/BUILD.bazel
    Add dependency on registry/resource_limits in test suite
Enhancement ► rs/messaging/src/message_routing.rs
    Adjust StreamHandlerImpl creation to remove direct hypervisor_config usage; rely on metadata-based capacities
Enhancement ► rs/messaging/src/routing/stream_handler.rs
    Remove direct guaranteed_response_message_memory_capacity field from StreamHandlerImpl; stop passing hypervisor_config; use metadata-based capacity
Enhancement ► rs/messaging/src/routing/stream_handler/tests.rs
    Refactor tests to supply memory limits via heap_delta_capacity_for_message_memory and maximum_state_delta; adapt test setup helpers accordingly
Enhancement ► rs/messaging/src/state_machine.rs
    Shed messages using capacity from state.metadata.best_effort_message_memory_capacity() instead of a fixed field; align with new metadata-based capacity
Enhancement ► rs/messaging/src/state_machine/tests.rs
    Update tests to accommodate removal of direct hypervisor_config fields; rely on metadata-based capacities and test scaffolding changes
Enhancement ► rs/messaging/tests/common/mod.rs
    Update test subnet config to use ResourceLimits for maximum_state_delta via heap_delta_capacity_for_message_memory; simplify hypervisor config initialization
Enhancement ► rs/registry/resource_limits/src/lib.rs
    Add maximum_state_delta_or(default) helper to choose registry override or default heap delta capacity
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Expose guaranteed_response_message_memory_capacity and best_effort_message_memory_capacity methods; add heap_delta_capacity helper and compute capacities from heap delta capacity; use maximum_state_delta_or for effective capacity
Enhancement ► rs/state_machine_tests/src/lib.rs
Introduce resource_limits field in StateMachineConfig; add with_resource_limits builder; propagate resource_limits into StateMachine initialization
Enhancement ► rs/state_machine_tests/src/lib.rs
Thread resource_limits into multi-subnet setup and state creation for tests
Enhancement ► rs/test_utilities/execution_environment/src/lib.rs
Use heap_delta_capacity_for_message_memory to configure maximum_state_delta for tests; propagate resource limits into execution test builder setup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving tiny change in Governance-owned code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants