Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
memory guard: unusable cgroup files without --memory-limit-mib fall back to MemAvailable with one warning; with the flag the sample stays unknown
Niko1221c9680eeff6f5
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex f66c17a10..f88b6a083 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -958,7 +958,8 @@ room afterwards):minus `memory.current`; cgroup v1 `memory.limit_in_bytes` minus`memory.usage_in_bytes` (both less the clean inactive file cache, below). `max` and v1's "unlimited" count as no limit; a file that isabsent (no memory controller at that level) is skipped; a file that is there but- cannot be read or parsed makes the sample unknown, and unknown skips parking.+ cannot be read or parsed makes the cgroup terms unusable: without `--memory-limit-mib` the guard then uses+ `MemAvailable` alone, as 0.1.41 did, and prints one warning per process; with the flag the sample is unknown, and unknown skips parking.3. `--memory-limit-mib N` (or `STRATA_MEMORY_LIMIT_MIB=N`; the flag wins, `0` = none):N MiB is the total this engine's container or cgroup may use, minus what thatcontainer uses now. Use it when the container cannot see its own limit. The usage@@ -1001,7 +1002,7 @@ is checked against the cgroup-aware `host_available_memory`) keep their own prob#1250), and `--memory-limit-mib` does not reach them. This figure is for what runs after the start: parking aconversation and saving or restoring a session file, which read `MemAvailable` alone. `host_available_memory`(expert_source.cpp) and this figure both read the cgroup limits; this one also reads `memory.high` and the operator's-cap, and an unreadable cgroup file makes it unknown.+cap; an unreadable cgroup file makes it fall back to `MemAvailable` (one warning), or unknown when a cap is set.Earlier measurement on a Proxmox LXC where the engine's container cannot see its limit (a 100 GiB cap on the parentcgroup, outside the container's namespace; the container's own `memory.max` and `memory.high` read `max`):diff --git a/src/core/conversation_memory.cpp b/src/core/conversation_memory.cppindex 5c234fee3..ec7b9bb4c 100644--- a/src/core/conversation_memory.cpp+++ b/src/core/conversation_memory.cpp@@ -2,6 +2,7 @@#include <algorithm>#include <atomic>+#include <cstdio>#include <charconv>#include <filesystem>#include <fstream>@@ -263,7 +264,16 @@ std::optional<HostMemoryReading> sample_host_memory(const MemoryProbePaths& pathstd::optional<uint64_t> total;if (total_file) total = meminfo_kb_bytes(total_file, "MemTotal:");CgroupScan cg;- if (!scan_cgroups(paths, cg)) return {};+ if (!scan_cgroups(paths, cg)) {+ // Without an operator cap the cgroup files are only an extra: the guard falls back to MemAvailable alone (what+ // 0.1.41 used), once-warned. With a cap the usage cannot be told, so the sample stays unknown.+ if (explicit_limit != 0) return {};+ static std::atomic<bool> warned{false};+ if (!warned.exchange(true))+ std::fprintf(stderr, "[strata] memory guard: the cgroup memory files could not be read or parsed, using "+ "MemAvailable; set --memory-limit-mib to the container's limit\n");+ cg = CgroupScan{};+ }return combine(available, total, cg, explicit_limit);}diff --git a/tests/core/memory_guard_test.cpp b/tests/core/memory_guard_test.cppindex c7abc665f..25aa4ba4e 100644--- a/tests/core/memory_guard_test.cpp+++ b/tests/core/memory_guard_test.cpp@@ -144,7 +144,8 @@ int main() {check(!f.sample(100 * GiB), "cap with unknown usage is unknown");check(f.sample().has_value(), "no cap, no usage needed");}- // malformed or unusable files: the sample is unknown (admission refuses), never a guess+ // malformed or unusable files: without a cap the guard falls back to MemAvailable alone (meminfo source, once-warned);+ // with a cap the sample is unknown (admission refuses), never a guess{const char* bad_values[] = {"garbage\n", "", "\n", "-5\n", "+5\n", "12x\n", "1 2\n", "18446744073709551616\n","0x10\n", "MAX\n"};@@ -156,7 +157,11 @@ int main() {f.put("cgroup/g/memory.max", 100 * GiB); f.put("cgroup/g/memory.high", "max\n");f.put("cgroup/g/memory.current", 50 * GiB);f.put(std::string("cgroup/g/") + file, text);- check(!f.sample(), "malformed cgroup file is unknown");+ {+ const auto r = f.sample();+ check(r && r->available == 25 * GiB && r->source == MemorySource::meminfo,+ "malformed cgroup file without a cap: MemAvailable alone");+ }check(!f.sample(100 * GiB), "malformed cgroup file is unknown with the cap too");}}@@ -166,7 +171,9 @@ int main() {f.meminfo(120 * GiB, 25 * GiB);check(f.sample() && f.sample()->available == 25 * GiB, "the fixture itself is sound");fs::remove(f.dir / "cgroup/g/memory.current");- check(!f.sample(), "a finite limit with no usage beside it is unknown");+ check(f.sample() && f.sample()->available == 25 * GiB && f.sample()->source == MemorySource::meminfo,+ "a finite limit with no usage beside it, no cap: MemAvailable alone");+ check(!f.sample(100 * GiB), "... and with the cap it is unknown");f.put("cgroup/g/memory.max", "max\n");check(f.sample() && f.sample()->available == 25 * GiB, "no finite limit and no usage: the level is skipped");f.put("cgroup/g/memory.current", "max\n");@@ -227,7 +234,8 @@ int main() {r = f.sample(92 * GiB);check(r && r->available == 2 * GiB && r->source == MemorySource::flag && r->current == 90 * GiB, "v1 with a tighter cap: the v1 root's usage");f.put("cgroup/memory/m/memory.limit_in_bytes", "junk\n");- check(!f.sample(), "v1 malformed limit is unknown");+ check(f.sample() && f.sample()->source == MemorySource::meminfo, "v1 malformed limit, no cap: MemAvailable alone");+ check(!f.sample(100 * GiB), "v1 malformed limit with the cap is unknown");}// hybrid: a v2 line, but the memory controller lives in the v1 tree{