[PR #2962] [Engine] conversation cache: parked dialogs give RAM back when available RAM falls below --conversation-cache-min-free-mib #4362

Open
opened 2026-11-07 15:35:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2962
Author: @sergqwer
Created: 10/17/2026
Status: 🔄 Open

Base: main ← Head: pr/conv-pressure


📝 Commits (1)

  • 5df5db2 conversation cache: parked dialogs give RAM back when available RAM falls below --conversation-cache-min-free-mib

📊 Changes

5 files changed (+405 additions, -2 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 docs/DETAILS.md (+11 -0)
➕ include/strata/core/conversation_pressure.hpp (+85 -0)
➕ src/core/conversation_pressure_test.cpp (+194 -0)
📝 src/program/generate.cpp (+111 -2)

📄 Description

Problem and result

--conversation-cache-min-free-mib (default 2560) is checked when a conversation is parked, saved or restored. Once parked, a conversation stays in RAM until a later park or restore evicts it, also when the host runs short in between (another program opened, or the engine's own memory grew).

  • Before: below the floor, parked conversations keep their RAM until the next park or restore.
  • After: with the conversation cache on, the floor holds after a park too. Below it the cache gives RAM back, oldest first, and says so in one line. Above the floor nothing changes. With the cache off (the default) nothing runs.

None beyond this PR. It was #2962 before the 0.2.0-beta tracker reset, unchanged except for the rebase. It changes no default: the cache is off unless --conversation-cache-mib is set (setup only prints it as a tip), and the floor's default is unchanged.

Approach

  • When. Only with the conversation cache on: before every request, every STRATA_CONV_PRESSURE_MS (2000 ms; 0 = off) while the engine is idle (the stdin wait wakes in 2 s slices for it), and between batch windows.
  • The reading is the park gate's own (sample_host_memory(): on Windows the smaller of available physical memory and commit room; on Linux MemAvailable, the cgroup limits and --memory-limit-mib). An unknown reading releases nothing, as the park gate fails closed.
  • What goes, oldest first, until the floor + STRATA_CONV_PRESSURE_HYST_MIB (1024) is available: the retained K/V; then the parked conversations, least recently active first, through the cache's own evict_oldest() (pinned shared prefixes and a guarded donor stay; a client that comes back has its prompt read again); then the idle --batch slots' host checkpoints (their K/V and ids in VRAM stay; a partial read keeps its own). After each step it reads again; glibc gets malloc_trim first.
  • One stderr line per event, e.g. conversation cache: RAM below the floor: released 2 dialogs, 2180 MiB (dropped) in 84 ms; idle: 29694 -> 31899 MiB available, floor 30720 MiB + 1024; parked=1. An event with nothing left to release is said once.
  • The policy is a header (include/strata/core/conversation_pressure.hpp), tested without a GPU; generate.cpp only wires it in.

Validation

Revision: this branch, one commit 5df5db29 on main e88ee39d (v0.2.0-beta + 12 commits), against a build of main e88ee39d. RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (-DSTRATA_PORTABLE=ON, 75-real;86-real;89-real;120-real, ggml at the pinned 3cf03257). Model: the NVFP4 GPTQ pack (Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's --family nvfp4 --model NVFP4 files).

Passed:

  • Identity. strata --serve with setup's model files plus --expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, env STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each:

    run 2K logits 32K logits greedy tokens
    main e88ee39d 1e9c612c... f5b2872c... 4 / 20
    this branch identical identical identical
    this branch, --conversation-cache-mib 8192 --conversation-cache-slots 4 (the 2K dialog parked when the 32K one came, no pressure) identical identical identical
  • Under pressure (one server run, 78 s). Config: --expert-cache auto --spec 4 --spec-min-p 0.5 --max-context 262144 --kv int8 --kv-resident 32768 plus --conversation-cache-mib 8192 --conversation-cache-slots 4 --conversation-cache-min-free-mib 30720. The floor is set high so that a small ballast crosses it (this PC's RAM is shared with other work).

    • Three dialogs with a shared 3K system prompt, one turn each: B 32K, A 48K, E 64K, then a short side dialog Q, so E parked too. Parked: 3, 3,974 MB; 38,323 MiB available; engine private bytes 107,532 MiB.
    • 6 s idle: no release line.
    • A ballast program took 8,192 MiB: 29,752 MiB available, under the floor.
    • 0.5 s later: conversation cache: RAM below the floor: released 2 dialogs, 2180 MiB (dropped) in 84 ms; idle: 29694 -> 31899 MiB available, floor 30720 MiB + 1024; parked=1. The oldest two went (B, A); E stayed. Engine private bytes 107,532 -> 105,383 MiB (-2,149) at once. One line only while the ballast was held.
    • After the ballast: B (released) 32092 tokens = 2998 reused + 29094 read, TTFT 5.5 s, its own codename in the answer. E (still parked) 64047 reused + 46 read, restored in 75 ms, TTFT 0.49 s, its own codename. 4 s idle after: no release line.
  • Unit tests (CPU, from the repo root). conversation_pressure_test (new, 63 checks: nothing at or above the floor or inside the band; below it the oldest go until floor + hysteresis; settle-only recovery; retained K/V first; pinned prefixes stay; unknown readings; the bound; and one real 256 MiB release that leaves the process):

    • MSVC 19.44 /std:c++20 /W4: 0 warnings, 63 passed (Windows private bytes 257 -> 0 MiB, twice).
    • MinGW g++ 16.1 -std=c++20 -Wall -Wextra: 0 warnings, 63 passed.
    • Ubuntu 24.04, g++ 13.3 / glibc 2.39, -Wall -Wextra: 0 warnings, 63 passed (RSS 299 -> 3 MiB and 259 -> 3 MiB).
    • The standalone conversation tests with MSVC: conversation_cache_test 4,772 checks, conversation_file_test 183, conversation_memory_test 25, conversation_split_failure_test 16 cases, session_save_reclaim_test 119, all passed (conversation_cache_test also on the Linux box).

Failed: none observed.

Not run:

  • HIP and Metal builds: both compile this generate.cpp; no ROCm or Mac here.
  • SYCL: its own sycl/src/program/generate.cpp is not changed, so a SYCL engine keeps the old behaviour.
  • --batch under pressure on this revision (the slots' checkpoints): measured only on our fork's 0.1.44 code, where with --batch 2 the parked images went first and then the slots' checkpoints (2,180 MiB together), and the slots still reused 32K/48K tokens afterwards.

Limits

  • Not covered: the live session's own checkpoint chain (--prompt-cache, ~118 MB each), which is the active conversation, and STRATA_CKPT_POOL's at most two kept checkpoints.
  • The Monitor's parked count (serve's ConvCacheLog) reads park, restore and "dropped ... superseded" lines; the release line is not parsed there, so the Monitor shows the old count until the next park or restore.

🤖 Generated with Claude Code


🔄 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/2962 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/conv-pressure` --- ### 📝 Commits (1) - [`5df5db2`](https://github.com/Niko1221/Strata/commit/5df5db29a2e9a2d5e50e9329e37ea69e3d37dc99) conversation cache: parked dialogs give RAM back when available RAM falls below --conversation-cache-min-free-mib ### 📊 Changes **5 files changed** (+405 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `docs/DETAILS.md` (+11 -0) ➕ `include/strata/core/conversation_pressure.hpp` (+85 -0) ➕ `src/core/conversation_pressure_test.cpp` (+194 -0) 📝 `src/program/generate.cpp` (+111 -2) </details> ### 📄 Description ## Problem and result `--conversation-cache-min-free-mib` (default 2560) is checked when a conversation is parked, saved or restored. Once parked, a conversation stays in RAM until a later park or restore evicts it, also when the host runs short in between (another program opened, or the engine's own memory grew). - Before: below the floor, parked conversations keep their RAM until the next park or restore. - After: with the conversation cache on, the floor holds after a park too. Below it the cache gives RAM back, oldest first, and says so in one line. Above the floor nothing changes. With the cache off (the default) nothing runs. ## Related discussion None beyond this PR. It was #2962 before the 0.2.0-beta tracker reset, unchanged except for the rebase. It changes no default: the cache is off unless `--conversation-cache-mib` is set (setup only prints it as a tip), and the floor's default is unchanged. ## Approach - **When.** Only with the conversation cache on: before every request, every `STRATA_CONV_PRESSURE_MS` (2000 ms; 0 = off) while the engine is idle (the stdin wait wakes in 2 s slices for it), and between batch windows. - **The reading** is the park gate's own (`sample_host_memory()`: on Windows the smaller of available physical memory and commit room; on Linux MemAvailable, the cgroup limits and `--memory-limit-mib`). An unknown reading releases nothing, as the park gate fails closed. - **What goes, oldest first, until the floor + `STRATA_CONV_PRESSURE_HYST_MIB` (1024) is available:** the retained K/V; then the parked conversations, least recently active first, through the cache's own `evict_oldest()` (pinned shared prefixes and a guarded donor stay; a client that comes back has its prompt read again); then the idle `--batch` slots' host checkpoints (their K/V and ids in VRAM stay; a partial read keeps its own). After each step it reads again; glibc gets `malloc_trim` first. - **One stderr line per event**, e.g. `conversation cache: RAM below the floor: released 2 dialogs, 2180 MiB (dropped) in 84 ms; idle: 29694 -> 31899 MiB available, floor 30720 MiB + 1024; parked=1`. An event with nothing left to release is said once. - The policy is a header (`include/strata/core/conversation_pressure.hpp`), tested without a GPU; `generate.cpp` only wires it in. ## Validation Revision: this branch, one commit 5df5db29 on `main` **e88ee39d** (v0.2.0-beta + 12 commits), against a build of `main` e88ee39d. RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (`-DSTRATA_PORTABLE=ON`, `75-real;86-real;89-real;120-real`, ggml at the pinned 3cf03257). Model: the NVFP4 GPTQ pack (`Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata`, upstream setup's `--family nvfp4 --model NVFP4` files). **Passed:** - **Identity.** `strata --serve` with setup's model files plus `--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000`, env `STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>`; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each: | run | 2K logits | 32K logits | greedy tokens | | --- | --- | --- | --- | | `main` e88ee39d | `1e9c612c...` | `f5b2872c...` | 4 / 20 | | this branch | identical | identical | identical | | this branch, `--conversation-cache-mib 8192 --conversation-cache-slots 4` (the 2K dialog parked when the 32K one came, no pressure) | identical | identical | identical | - **Under pressure** (one server run, 78 s). Config: `--expert-cache auto --spec 4 --spec-min-p 0.5 --max-context 262144 --kv int8 --kv-resident 32768` plus `--conversation-cache-mib 8192 --conversation-cache-slots 4 --conversation-cache-min-free-mib 30720`. The floor is set high so that a small ballast crosses it (this PC's RAM is shared with other work). - Three dialogs with a shared 3K system prompt, one turn each: B 32K, A 48K, E 64K, then a short side dialog Q, so E parked too. Parked: 3, 3,974 MB; 38,323 MiB available; engine private bytes 107,532 MiB. - 6 s idle: no release line. - A ballast program took 8,192 MiB: 29,752 MiB available, under the floor. - 0.5 s later: `conversation cache: RAM below the floor: released 2 dialogs, 2180 MiB (dropped) in 84 ms; idle: 29694 -> 31899 MiB available, floor 30720 MiB + 1024; parked=1`. The oldest two went (B, A); E stayed. Engine private bytes 107,532 -> 105,383 MiB (-2,149) at once. One line only while the ballast was held. - After the ballast: B (released) `32092 tokens = 2998 reused + 29094 read`, TTFT 5.5 s, its own codename in the answer. E (still parked) `64047 reused + 46 read`, restored in 75 ms, TTFT 0.49 s, its own codename. 4 s idle after: no release line. - **Unit tests** (CPU, from the repo root). `conversation_pressure_test` (new, 63 checks: nothing at or above the floor or inside the band; below it the oldest go until floor + hysteresis; settle-only recovery; retained K/V first; pinned prefixes stay; unknown readings; the bound; and one real 256 MiB release that leaves the process): - MSVC 19.44 `/std:c++20 /W4`: 0 warnings, 63 passed (Windows private bytes 257 -> 0 MiB, twice). - MinGW g++ 16.1 `-std=c++20 -Wall -Wextra`: 0 warnings, 63 passed. - Ubuntu 24.04, g++ 13.3 / glibc 2.39, `-Wall -Wextra`: 0 warnings, 63 passed (RSS 299 -> 3 MiB and 259 -> 3 MiB). - The standalone conversation tests with MSVC: `conversation_cache_test` 4,772 checks, `conversation_file_test` 183, `conversation_memory_test` 25, `conversation_split_failure_test` 16 cases, `session_save_reclaim_test` 119, all passed (`conversation_cache_test` also on the Linux box). **Failed:** none observed. **Not run:** - HIP and Metal builds: both compile this `generate.cpp`; no ROCm or Mac here. - SYCL: its own `sycl/src/program/generate.cpp` is not changed, so a SYCL engine keeps the old behaviour. - `--batch` under pressure on this revision (the slots' checkpoints): measured only on our fork's 0.1.44 code, where with `--batch 2` the parked images went first and then the slots' checkpoints (2,180 MiB together), and the slots still reused 32K/48K tokens afterwards. ## Limits - Not covered: the live session's own checkpoint chain (`--prompt-cache`, ~118 MB each), which is the active conversation, and `STRATA_CKPT_POOL`'s at most two kept checkpoints. - The Monitor's parked count (serve's `ConvCacheLog`) reads park, restore and "dropped ... superseded" lines; the release line is not parsed there, so the Monitor shows the old count until the next park or restore. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4362
No description provided.