Repository navigation
memory guard: parking and session save/restore check the container's real RAM (--memory-limit-mib) - #1601
Closed
noon-at-cgn wants to merge 2 commits into
Closed
memory guard: parking and session save/restore check the container's real RAM (--memory-limit-mib)#1601noon-at-cgn wants to merge 2 commits into
--memory-limit-mib)#1601noon-at-cgn wants to merge 2 commits into
Conversation
…e really has (--memory-limit-mib) available_host_bytes() = min(MemAvailable, the room under every cgroup limit above the engine, the operator's cap). Parking and session save/restore read MemAvailable alone: in a container whose real limit sits on a parent cgroup it cannot see, MemAvailable is stale (about 25 GiB shown when about 1 GiB was left) and the engine was OOM-killed. conversation_available_memory() is replaced by available_host_bytes() / sample_host_memory() (the SYCL port's generate.cpp too). The cgroup term covers memory.max and memory.high (v2) and memory.limit_in_bytes (v1) of the process's group and every visible ancestor, with clean inactive file cache credited; an unparsable cgroup file makes the sample unknown (fail closed). --memory-limit-mib / STRATA_MEMORY_LIMIT_MIB names the total RAM the container or cgroup may use. Refusals say how much was available and from which source; one start-up line reports the limit. tests/core/memory_guard_test.cpp runs on fixture directories (CPU only). Docs: DETAILS.md.
noon-at-cgn
marked this pull request as ready for review
October 8, 2026 17:00
…th the measured result
noon-at-cgn
force-pushed
the
pr/memory-guard
branch
from
October 8, 2026 18:53
a59ce5e to
dcb9fdd
Compare
--memory-limit-mib)--memory-limit-mib)
Owner
|
Ported into v0.1.42 with your commits (one conflict with --conversation-cache-min-tokens and the renamed RAM probe of #1573, resolved by keeping both). Tested under a systemd cgroup with MemoryMax on an RTX 3060 box: the start-up line reports the cgroup as the source (limit 41.0 GiB while MemAvailable said 44 GiB), and a SAVE that /proc/meminfo alone would have admitted is refused with 'source cgroup'. Thank you. One change from the PR: when the cgroup files cannot be read or parsed and no --memory-limit-mib is given, the guard falls back to MemAvailable alone (as 0.1.41) with one warning, instead of refusing parking and SAVE; with the flag set it still refuses. |
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.
Title
Issue: Related: #1250 (host OOM while page-locking the expert copy; its
STRATA_PIN_GUARDcovers the start-up copy), #1572 / #1573 (SAVE admission, open draft).Summary
Why it matters: parking a conversation (about 240 MB to 750 MB per park) and saving or restoring a session file decide with
MemAvailablealone. Inside a container that figure ignores the container's own limit, so the engine can start a copy it has no room for. In our log from a bad day,MemAvailableread 21.8, 25.4 and 3.7 GiB just before three kills while the container's cgroup was at 98.6, 94.9 and 96.6 GiB of a ~100 GiB limit.available_host_bytes()now returns the smallest ofMemAvailable, the room under every cgroup limit above the engine, and an operator cap (--memory-limit-mib N, the total RAM the container may use). With no cgroup limit and no flag it isMemAvailable, as before. Those kills were host-wide OOMs (the host was over-committed), so the PR does not claim to prevent them; it makes the engine's own admission decisions use the real headroom.--memory-limit-mib 101376--memory-limit-mib 78000parked N tokens in ... msskip parking (... 0 MiB available, source flag)The engine held 89.7-89.9 GiB, above a 76.2 GiB cap, so headroom is 0: the intended refusal, and the request goes on.
What changed
conversation_memory.hpp/.cpp:conversation_available_memory()becomesavailable_host_bytes()/sample_host_memory(). The cgroup term readsmemory.maxandmemory.high(v2) ormemory.limit_in_bytes(v1) of the process's group and each visible ancestor; clean inactive file cache is credited. An unparsable cgroup file makes the sample unknown, and unknown refuses.src/program/generate.cpp: flag and variable, one start-up line (limit, source, usage, credit); parking (before and after capture), save and restore read the new figure; a refusal says how much was available and from which source. The eviction loop is unchanged.sycl/src/program/generate.cpp: four callers renamed.tests/core/memory_guard_test.cpp(new, CPU, fixture directories for/proc/meminfoand the cgroup tree) +CMakeLists.txt;docs/DETAILS.md.Extra Notes
Measured on engine 0.1.40.3 (d5ea713) plus this change; the branch itself is cut from main fb58e0d.
Relation to #1250: not duplicated, not touched.
STRATA_PIN_GUARDdecides at start whether to page-lock in steps; this covers parking, SAVE and RESTORE after the start. Both read cgroup limits, in separate code (conversation_memory.cppalso builds standalone for the conversation tests); a shared reader can follow if you prefer one. #1573 edits the same SAVE lines, so one of the two needs a rebase.Machine: 2x RTX 3080, 90 GiB container, UD-Q4_K_XL. Checked:
memory_guard_test(130 checks; an existing binary, the rebuild was blocked by the build lock) andconversation_memory_test, CUDA build. Not built: HIP, SYCL, Windows. Not measured: a cap between 78000 and 101376, any run without the flag, any throughput effect.Context: this change is part of the setup measured in the community benchmark #1640.