Repository navigation
Add opt-in cgroup-aware minion_memory_headroom / minion_memory_max (#69884) - #70038
Merged
dwoz merged 2 commits intoAug 18, 2026
Merged
Conversation
Adds opt-in minion_memory_headroom (accepts "5%" / "5G" / int bytes) and minion_memory_max (bytes / size string) config options with silent cgroup v1 / v2 detection. When either opt is set, the reference "total memory available" is resolved from config > cgroup-v2 > cgroup-v1 > psutil.virtual_memory().total, and used bytes come from the matching tier. When neither opt is set the check preserves the legacy psutil.virtual_memory().percent > 95 behavior byte-for-byte, so no minion changes behavior on upgrade. Refs saltstack#69884
Complements the unit-level matrix in tests/pytests/unit/test_minion_memory_headroom.py by booting a real minion daemon with each opt combination and driving the runtime check via a subprocess that loads the minion's on-disk config through salt.config.minion_config and calls Minion._has_memory_headroom. Four scenarios: * config round-trip via salt-call --local config.get * default preserved (no opts -> legacy True on any healthy host) * config override -> deterministic True (huge max, tiny reserve) * config override -> deterministic False (tiny max, full reserve) All scenarios use deterministic config values so no system-memory pressure is required. Refs saltstack#69884
twangboy
approved these changes
Aug 14, 2026
charzl
approved these changes
Aug 14, 2026
5 tasks
dwoz
added a commit
to dwoz/salt
that referenced
this pull request
Aug 15, 2026
Covers the new salt.utils.memory helpers and the two enforcement paths introduced in the preceding commit: * tests/pytests/unit/utils/test_memory.py (new): 51 cases spanning parse_size, parse_headroom, _read_cgroup_file, _parse_self_cgroup, _detect_cgroup_memory, resolve_memory_reference precedence chain, and the full has_memory_headroom matrix (both opts unset -> True; psutil missing -> True; over-limit -> False + WARNING log; bogus headroom -> 5% fallback; exceptions swallowed). Mirrors the fixture shape from saltstack#70038's tests/pytests/unit/test_minion_memory_headroom.py. * tests/pytests/unit/channel/test_server.py: 6 cases covering the MasterPubServerChannel._ep_memory_gate contract -- no-opt is a permit, set-from-start is a no-op, cleared blocks publish_payload, mid-await set releases it, and the PeriodicCallback closure toggles the gate based on has_memory_headroom's return value. * tests/pytests/unit/transport/test_zeromq.py: 7 cases covering MWorkerQueue -- the non-pooled zmq_device warning fires (and only fires) when an opt is set; pooled zmq_device_pooled skips ROUTER recv_multipart when has_memory_headroom is False, always drains DEALER responses (worker replies must flow), admits when headroom is OK, caches the check per event_publisher_memory_check_interval, and never calls the check on the default (unset-opts) path.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #69884.
salt/minion.py::_has_memory_headroomhard-codespsutil.virtual_memory().percent > 95— a system-wide check that reserves 100 GB on a 2 TB host and uses the wrong reference on cgroup-limited minions.Adds two opt-in minion config options:
minion_memory_headroom— required free headroom. Accepts either a percentage string ("5%") or an absolute size ("5G","500M", int bytes).minion_memory_max— explicit override for the reference "total memory available to this minion" (int bytes or size string).Reference-memory resolution precedence:
minion_memory_maxif set.memory.max(withmemory.currentfor used).memory.limit_in_bytes(withmemory.usage_in_bytes).psutil.virtual_memory().total(with.used).Cgroup detection is silent-fallback: missing / unreadable / malformed files log at DEBUG and drop to the next tier. No D-Bus / systemd dependency — the cgroup file the systemd unit writes to is already the source of truth.
When both new opts are unset the arithmetic reduces to
psutil.virtual_memory().percent > 95, so no minion changes behavior on upgrade (LTS opt-in only, per #69443 / #69597 precedent).New tests (40 cases) under
tests/pytests/unit/test_minion_memory_headroom.pycover the parser, cgroup v1/v2 detection with a synthetic tmp_path cgroupfs, and the full 12-case behavior matrix (legacy default, config-only, cgroup-only, cgroup+config precedence, unlimited sentinels, permission-denied fallback, no-psutil, bogus input).