[PR #1601] [CLOSED] memory guard: parking and session save/restore check the container's real RAM (--memory-limit-mib) #3557

Closed
opened 2026-11-07 14:42:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1601
Author: @noon-at-cgn
Created: 10/8/2026
Status: ❌ Closed

Base: main ← Head: pr/memory-guard


📝 Commits (2)

  • 2a2f4e9 memory guard: parking and session save/restore read the RAM the engine really has (--memory-limit-mib)
  • dcb9fdd docs: replace the evidence placeholder in the memory guard section with the measured result

📊 Changes

8 files changed (+806 additions, -34 deletions)

View changed files

📝 CMakeLists.txt (+9 -0)
📝 docs/DETAILS.md (+81 -4)
📝 include/strata/core/conversation_memory.hpp (+58 -3)
📝 src/core/conversation_memory.cpp (+246 -8)
📝 src/core/conversation_memory_test.cpp (+1 -1)
📝 src/program/generate.cpp (+68 -14)
📝 sycl/src/program/generate.cpp (+4 -4)
➕ tests/core/memory_guard_test.cpp (+339 -0)

📄 Description

Title

Issue: Related: #1250 (host OOM while page-locking the expert copy; its STRATA_PIN_GUARD covers 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 MemAvailable alone. 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, MemAvailable read 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 of MemAvailable, 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 is MemAvailable, 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.

90 GiB container, resident RAM mode --memory-limit-mib 101376 --memory-limit-mib 78000
parking attempts that parked every one (135 parks, 0 skips in one 308-request run) 0 of 8
log line parked N tokens in ... ms skip parking (... 0 MiB available, source flag)
requests served normal normal (decode 79.6 tok/s)

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() becomes available_host_bytes() / sample_host_memory(). The cgroup term reads memory.max and memory.high (v2) or memory.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/meminfo and 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_GUARD decides 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.cpp also 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) and conversation_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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1601 **Author:** [@noon-at-cgn](https://github.com/noon-at-cgn) **Created:** 10/8/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/memory-guard` --- ### 📝 Commits (2) - [`2a2f4e9`](https://github.com/Niko1221/Strata/commit/2a2f4e9ae8a011fc888686620e93322a26af103f) memory guard: parking and session save/restore read the RAM the engine really has (--memory-limit-mib) - [`dcb9fdd`](https://github.com/Niko1221/Strata/commit/dcb9fddde345dc36011065f90d4dfaaceac1cfa9) docs: replace the evidence placeholder in the memory guard section with the measured result ### 📊 Changes **8 files changed** (+806 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -0) 📝 `docs/DETAILS.md` (+81 -4) 📝 `include/strata/core/conversation_memory.hpp` (+58 -3) 📝 `src/core/conversation_memory.cpp` (+246 -8) 📝 `src/core/conversation_memory_test.cpp` (+1 -1) 📝 `src/program/generate.cpp` (+68 -14) 📝 `sycl/src/program/generate.cpp` (+4 -4) ➕ `tests/core/memory_guard_test.cpp` (+339 -0) </details> ### 📄 Description ## Title Issue: Related: #1250 (host OOM while page-locking the expert copy; its `STRATA_PIN_GUARD` covers 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 `MemAvailable` alone. 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, `MemAvailable` read 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 of `MemAvailable`, 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 is `MemAvailable`, 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. | 90 GiB container, resident RAM mode | `--memory-limit-mib 101376` | `--memory-limit-mib 78000` | |---|---|---| | parking attempts that parked | every one (135 parks, 0 skips in one 308-request run) | 0 of 8 | | log line | `parked N tokens in ... ms` | `skip parking (... 0 MiB available, source flag)` | | requests served | normal | normal (decode 79.6 tok/s) | 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()` becomes `available_host_bytes()` / `sample_host_memory()`. The cgroup term reads `memory.max` and `memory.high` (v2) or `memory.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/meminfo` and 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_GUARD` decides 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.cpp` also 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) and `conversation_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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:42:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3557
No description provided.