docs(memory): job 914 results, CRM session analysis, leak jobs

This commit is contained in:
Pavlo Ratushnyi
2026-10-23 16:20:54 +02:00
parent 904ac58d3a
commit e70a05b9d1
6 changed files with 81 additions and 9 deletions
+36 -8
View File
@@ -219,16 +219,19 @@ The server profile: `auto`, 4096/2048/1024 MiB, lock `try`, heal on. The laptop
soft floor at the second request (`normal -> shed: available 61543 MiB below the soft floor 61596 MiB`); the next request found the cache evicted from **702 MiB to 351 MiB, `MemAvailable` 61,471 -> 61,885 MiB and RSS -305 MiB**
(the freed blocks went back to the OS: `malloc_trim` after an eviction); the ballast then crossed the hard floor (`shed -> reject`), `admit` answered `503 memory_pressure`, `retry_after=15s`, and the next request found the cache emptied.
The recovery phase of that smoke compared against a baseline that had drifted (file-mapped expert pages warmed up during the test) and never reached the 1 GiB hysteresis margin, so the smoke reported `failed` on its own expectation, not on the
governor (`reject -> shed` happened after the ballast was freed, as designed). The smoke now re-centres the floors before the recovery phase; the re-run is job 914 (section 5.5).
governor (`reject -> shed` happened after the ballast was freed, as designed). The smoke now re-centres the floors before the recovery phase; the re-run is in section 5.5.
* **Job 917 (reader), first attempt, not a result.** The request decoded one token (the filler prompt ends in EOS) and the reader thread only ran for ~4 s (0 GiB through the cache), so decode speed 6.9 / 7.9 / 8.0 tok/s (A/B/C) says nothing;
the memfd stayed at 0 swapped MiB and `pswpin/out` at 0 throughout. The scenario now decodes a fixed 64 tokens without stopping at EOS and lasts until the reader has streamed its 40 GiB; the re-run is job 914 (section 5.5).
the memfd stayed at 0 swapped MiB and `pswpin/out` at 0 throughout. The scenario now decodes a fixed 64 tokens without stopping at EOS and lasts until the reader has streamed its 40 GiB; the re-run is in section 5.5.
### 5.5 Queued, not yet run (holder queue FIFO: roughly ten other agents' jobs were ahead)
### 5.5 Job 914 (binary a7): shed with recovery, and decode speed next to a 40 GiB competing reader
Job `914-mem-shed2` (binary `mem-a7`, `scripts/memory/jobs/914-mem-shed2.sh`, already in `holder2/jobs`): (1) the shed smoke again with the recovery phase fixed: it must end `MEM-RESULT scenario=shed failed=[]`,
including `MEM-SHED recovered` and `prefix_budget_mib` restored; (2) the reader scenario with a fixed 64 decoded tokens and a reader that streams 40 GiB of the KAR file through the page cache: it prints `MEM-READER phase=A/B/C`
lines with decode tok/s, `memfd_swapped_mib` and `pswpin/pswpout` per request and the B/A ratio. Until it has run, the claim "decode speed does not drop next to a competing reader, memfd stays resident" rests on job 910 (memfd 0 MiB swapped for 75 s next
to a 40 GiB reader, no swap traffic) and on the WSL2 A/B (5.3); there is no 5090 decode-speed number for it. Read the logs in `~/work/gpu-runs/holder2/jobs/914-mem-shed2.log`.
* **Shed path, complete.** Floors 1.5 / 3 GiB below the memory the host had (63,350 MiB), prefix budget 6 GiB, ballast 2.3 GiB: `normal -> shed` at the soft floor, the next request found the cache evicted 351 -> 0 MiB with `MemAvailable` 62,089 -> 62,442 MiB
and RSS -312 MiB; the ballast crossed the hard floor (`shed -> reject`), `admit` answered 503 `memory_pressure`, `retry_after=15s`; with the ballast freed and the floors re-centred the level went `reject -> shed -> normal` in 4 samples, the request after it was
served and the **prefix budget was back at 6,144 MiB**. `MEM-RESULT scenario=shed failed=[]`. `MemAvailable` never below 58 GiB.
* **Reader, decode speed.** 6 requests without the reader (A), 54 requests while a thread streamed 40 GiB of the KAR file through the page cache (B), 6 after (C); 64 decoded tokens each, no EOS stop:
A **18.12** tok/s, B **19.30** tok/s (B/A 1.07: no drop while the reader ran), C 15.95 (the first two requests after the reader ran at 11 tok/s, the following four at 17.1-19.6: the 40 GiB of KAR file evicted part of the *file-mapped expert pages*
from the page cache and they were read back once; that is the mapped bank, not the memfd). `memfd_swapped_mib` = 0 on every request, `pswpin/out` 0 (one page of swap-in in B), `MemAvailable` 62.0-62.3 GiB throughout. Same conclusion as job 910: with the host not short of memory a
page-cache reader does not move the memfd; the conditions that do are in 5.3.
### 5.3 Swap A/B under real pressure (WSL2 laptop, cgroup v1 memory controller, 9 GiB limit; sealed memfd 6 GiB, anonymous hog 5 GiB, a reader streaming a 12 GiB file; kernel 5.15)
@@ -311,7 +314,32 @@ copy site, Miri and clippy results, residual risks). Summary:
(340), `leleka-runtime` (166) and `native-cpu-expert` (153) were not cleaned up wholesale.
## 8. Open
## 8. The real Codex CRM session (e2e job 945): what the memory did, and what changed in the budget
Session: `--prefix-cache-mib auto`, resident expert bank, sealed memfd from the holder, 84 requests, context 10k -> 123k tokens, 25 minutes (`~/work/leleka-e2e/runs/945-codex-crm/env.tsv`, `inference.log`).
**That build (`leleka-e2e/bin-sm120`) predates this branch: no governor ran.** What the numbers say:
| time | VmRSS | RssAnon | RssShmem | RssFile | MemAvailable |
| --- | ---: | ---: | ---: | ---: | ---: |
| 0 s (after load) | 53,723 MiB | 49,690 | 3,836 | 0 | 13,991 MiB |
| 592 s (ctx 55k) | 58,152 | 54,106 | 3,836 | 0 | 9,710 |
| 1194 s (ctx 95k) | 60,360 | 56,314 | 3,836 | 0 | 7,474 |
| 1395 s (ctx 115k) | 60,383 | 56,337 | 3,836 | 0 | 7,459 |
* **Real, not reclaimable.** The growth is `RssAnon` (+6,647 MiB); `RssShmem` is constant (the pinned K/V image and head, 3,836 MiB), `RssFile` is 0 (the resident bank is anonymous), and the 51 GB memfd is outside the process RSS *and* outside
`MemAvailable` (shmem is not counted there). `MemAvailable` fell by 6,532 MiB: one for one with the anonymous growth. There was no reclaimable page cache to give back (the shard cache had been dropped after the load); the dip was the prefix store
filling its budget (582 MiB at the first request, 7,330 of 7,476 MiB at the end, 58 admitted, 23 evicted) and it plateaued exactly when the store reached the budget. That also answers "does the RSS leak" for this run: RSS growth (6,647 MiB) = store growth (6,748 MiB) within 1.5%; the
soak in section 5.6 tests the plateau itself.
* **Why nothing shed or refused.** (1) No governor in that build. (2) With it, the old rule would not have shed either: the budget was 75% of (14,064 - 4,096) = 7,476 MiB, which leaves 6.9 GiB available with the cache full (observed 7.46 GiB) against floors of 4 GiB (shed) and 2 GiB (reject). The
plan *designed* a minimum of 7 GiB available, and the operator's 15 GiB cannot hold in resident mode at all (idle is already 14 GiB).
* **Was the startup plan using the real post-load footprint?** Partly. The plan subtracts a predicted footprint from the available memory *before* the load. Real: 68,762 -> 13,991 MiB = **54,771 MiB**; predicted (bank 46.85 GiB + K/V 3.09 GiB + 2.5 GiB other) = 53,700 MiB: 1.1 GiB short, because the "other" constant had been measured
with the file-mapped bank (2.19 GiB); with the resident bank it is 3.55 GiB. The cache budget itself was never taken from the prediction: it is recomputed at open from the real `MemAvailable` (so the 1.1 GiB error did not enter it), but the *refusal* decision and the logged plan used the optimistic number.
* **Changes.** `OTHER_FIXED_ESTIMATE_RESIDENT` = 3.6 GiB for the resident bank (2.5 GiB stays for the mapped one); `Policy::reserve` 1 -> **2 GiB** (the first long request plus the store's own overhead grew the process ~1 GiB beyond the plan); the caches stop *admitting* at
`soft_floor + reserve` (6 GiB) instead of at a 3 GiB insertion floor, i.e. before a shed is needed; and after the stack opens `note_post_load` compares the plan with the measured availability, logs a WARNING above 512 MiB error and publishes it as `plan_check`
in the report. For the CRM host state the `auto` budget becomes **6.0 GiB** (was 7.3) and ~8 GiB stay available with the cache full (was 7.4); a 180k session (2.6 GB of blocks + 127 MiB per node) still fits. The file-mapped bank was already accounted
since section 2.2 (hot half of RAM kept out of the elastic memory); the resident bank is a fixed item of the plan.
## 9. Open
* The `OTHER_FIXED_ESTIMATE` (rings, staging, pool scratch, empty checkpoints) in `memory_governor.rs` is a measured constant, not a formula; re-measure when those owners change.
* A hard guarantee that the memfd is never swapped needs `LimitMEMLOCK=infinity` (the deploy unit sets it) or `CAP_IPC_LOCK`; without it the guard detects and heals but cannot prevent.
+11
View File
@@ -0,0 +1,11 @@
set -uo pipefail
# claude/memory-safety: RSS slope / leak question (arm: default). Mixed requests for 11000 s (8k..180k prompts, shared and unshared sessions, prefix-cache churn under an auto budget,
# cancels, over-long refusals), sampled every 30 s: RSS anon/file/shmem, swap, meminfo, VRAM, prefix store, glibc heap; OLS + Theil-Sen slope per 1000 requests after a 25% warm-up.
# File-mapped experts (MemAvailable stays ~58 GiB; the 15 GiB rule): an anon/shmem leak shows the same as with the resident bank.
source ~/work/mem-jobs/mem-common.sh
cd $HOME/work/leleka-mem-bin
preflight 45
watch_start
run_mem leak-919-check backend::original_serve_memory_smoke::original_serve_memory_smoke LELEKA_MEM_SCENARIO=leak LELEKA_MEM_LEAK_SECS=420 LELEKA_MEM_LEAK_SAMPLE_S=10 LELEKA_MEM_BIG_EVERY=1000 LELEKA_MEM_PREFIX_MIB=auto LELEKA_MEM_LEAK_TSV=$RAWDIR/919-check.tsv LELEKA_MEM_SESSIONS=8 LELEKA_MEM_SESSION_CAP=40000 LELEKA_MEM_BIG=100000,180000 LELEKA_MEM_BIG_EVERY=120
watch_stop
holder_state
+11
View File
@@ -0,0 +1,11 @@
set -uo pipefail
# claude/memory-safety: RSS slope / leak question (arm: default). Mixed requests for 11000 s (8k..180k prompts, shared and unshared sessions, prefix-cache churn under an auto budget,
# cancels, over-long refusals), sampled every 30 s: RSS anon/file/shmem, swap, meminfo, VRAM, prefix store, glibc heap; OLS + Theil-Sen slope per 1000 requests after a 25% warm-up.
# File-mapped experts (MemAvailable stays ~58 GiB; the 15 GiB rule): an anon/shmem leak shows the same as with the resident bank.
source ~/work/mem-jobs/mem-common.sh
cd $HOME/work/leleka-mem-bin
preflight 45
watch_start
run_mem leak-920-mem-leak-3h backend::original_serve_memory_smoke::original_serve_memory_smoke LELEKA_MEM_SCENARIO=leak LELEKA_MEM_LEAK_SECS=11000 LELEKA_MEM_PREFIX_MIB=auto LELEKA_MEM_LEAK_TSV=$RAWDIR/920-mem-leak-3h.tsv LELEKA_MEM_SESSIONS=8 LELEKA_MEM_SESSION_CAP=40000 LELEKA_MEM_BIG=100000,180000 LELEKA_MEM_BIG_EVERY=120
watch_stop
holder_state
@@ -0,0 +1,11 @@
set -uo pipefail
# claude/memory-safety: RSS slope / leak question (arm: MALLOC_ARENA_MAX=2). Mixed requests for 2700 s (8k..180k prompts, shared and unshared sessions, prefix-cache churn under an auto budget,
# cancels, over-long refusals), sampled every 30 s: RSS anon/file/shmem, swap, meminfo, VRAM, prefix store, glibc heap; OLS + Theil-Sen slope per 1000 requests after a 25% warm-up.
# File-mapped experts (MemAvailable stays ~58 GiB; the 15 GiB rule): an anon/shmem leak shows the same as with the resident bank.
source ~/work/mem-jobs/mem-common.sh
cd $HOME/work/leleka-mem-bin
preflight 45
watch_start
run_mem leak-921-mem-leak-arena2 backend::original_serve_memory_smoke::original_serve_memory_smoke MALLOC_ARENA_MAX=2 LELEKA_MEM_SCENARIO=leak LELEKA_MEM_LEAK_SECS=2700 LELEKA_MEM_PREFIX_MIB=auto LELEKA_MEM_LEAK_TSV=$RAWDIR/921-mem-leak-arena2.tsv LELEKA_MEM_SESSIONS=8 LELEKA_MEM_SESSION_CAP=40000 LELEKA_MEM_BIG=100000,180000 LELEKA_MEM_BIG_EVERY=120
watch_stop
holder_state
@@ -0,0 +1,11 @@
set -uo pipefail
# claude/memory-safety: RSS slope / leak question (arm: LELEKA_MEMORY_NO_TRIM=1). Mixed requests for 2700 s (8k..180k prompts, shared and unshared sessions, prefix-cache churn under an auto budget,
# cancels, over-long refusals), sampled every 30 s: RSS anon/file/shmem, swap, meminfo, VRAM, prefix store, glibc heap; OLS + Theil-Sen slope per 1000 requests after a 25% warm-up.
# File-mapped experts (MemAvailable stays ~58 GiB; the 15 GiB rule): an anon/shmem leak shows the same as with the resident bank.
source ~/work/mem-jobs/mem-common.sh
cd $HOME/work/leleka-mem-bin
preflight 45
watch_start
run_mem leak-922-mem-leak-notrim backend::original_serve_memory_smoke::original_serve_memory_smoke LELEKA_MEMORY_NO_TRIM=1 LELEKA_MEM_SCENARIO=leak LELEKA_MEM_LEAK_SECS=2700 LELEKA_MEM_PREFIX_MIB=auto LELEKA_MEM_LEAK_TSV=$RAWDIR/922-mem-leak-notrim.tsv LELEKA_MEM_SESSIONS=8 LELEKA_MEM_SESSION_CAP=40000 LELEKA_MEM_BIG=100000,180000 LELEKA_MEM_BIG_EVERY=120
watch_stop
holder_state
+1 -1
View File
@@ -12,7 +12,7 @@ export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=2048 LELEKA_ORIGINAL_SERVE_EXPERT_PER_
export LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=0
export LELEKA_ORIGINAL_SERVE_CAPACITY=${LELEKA_ORIGINAL_SERVE_CAPACITY:-8192} LELEKA_ORIGINAL_SERVE_KV_RESIDENT=20480 LELEKA_ORIGINAL_SERVE_MAX_CONTEXT=262144
export LELEKA_MEM_SMOKE=yes LELEKA_SERVE_PROFILE=1
BIN=${BIN:-$HOME/work/leleka-mem-bin/mem-a4}
BIN=${BIN:-$HOME/work/leleka-mem-bin/mem-a8}
RAWDIR=$G/mem-logs
avail_gib() { awk '/MemAvailable/{printf "%d", $2/1048576}' /proc/meminfo; }
swap_used_mib() { awk '/SwapTotal/{t=$2} /SwapFree/{f=$2} END{printf "%d", (t-f)/1024}' /proc/meminfo; }