Skip to content

Memory pressure sheds against the host's deficit (compressor + swap), not RAM past a fraction - #5971

Merged
joelteply merged 2 commits into
canaryfrom
fable/host-pressure-counts-swap-and-compressor
Nov 13, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fable/host-pressure-counts-swap-and-compressor

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Serves the minds on the M5: when the OS compresses and swaps, every mind's prefill and decode slows. This is slice 1 of "one control for memory": one measured host pressure, and the existing shed path driven by it. Plan line: path step 1 (Fast), goal 7/9 (one budget, one control).

The incident (M5, 2026-11-13)

60 MB free, ~34 GB in the OS compressor, swap 8.6 / 10 GB, prefill at half speed, and nothing shed. The only shed amount was PressureSnapshot::over_gate, which is RAM "used" past a fixed fraction of total. A host that is compressing reads "used" under every gate, so the amount was 0. mind_results_reporter.rs said so in its own doc ("swap activity alone ... sheds nothing here").

What changed

  • continuum-host::host_memory (new, the OS seam): one HostMemoryReading holding free, reclaimable (file cache + purgeable), compressor-occupied bytes, cumulative swap in/out, and the kernel's own free target.
    • macOS: host_statistics64(HOST_VM_INFO64) + sysctl vm.vm_page_free_target. The accounting matches Activity Monitor: free = free − speculative, cached = external + purgeable.
    • Linux: /proc/meminfo (MemFree, MemAvailable, Zswap), /proc/vmstat (pswpin/pswpout), /proc/sys/vm/min_free_kbytes.
    • Both formats convert in pure functions (MachVmCounts::reading, from_proc_text). These compile and are tested on every host. macos.rs/linux.rs/other.rs hold only the calls.
  • memory_pressure::host_deficit (new): the one shed quantity.
    displaced = compressed + swap_used
    shortfall = max(0, free_target - (free + reclaimable))
    clean     = shortfall == 0 AND no swap-out AND compressor did not grow since the last poll
    clean -> baseline = displaced, deficit = 0
    else  -> deficit = (displaced - baseline) + shortfall     (no clean poll yet: baseline 0)
    
    • No literal thresholds: the free target is the kernel's own, and "grew" is a comparison with the previous reading. Inert swap left behind by an old build goes into the baseline at the next clean poll. A clean box gives 0 by construction.
    • deficit_at(priority) = max(RAM overrun past the gate, deficit − bytes held by lower priorities). Batch gives back first, then Background, then Interactive. Realtime never sheds for the deficit.
    • A positive deficit makes the level at least Warning. shed_due calls the shedders on every poll while the deficit lasts (after the 2-poll hysteresis), and each poll recomputes the shares from what is still held.
  • Shed path: ShedLru and mind_results now shed their share_of_deficit instead of share_of_overrun. The MemoryReporter interface is unchanged.
  • One reader: the swap-rate axis reads the same host reading. swap_activity::read_swap_traffic (with its cfg branches) and mach_ffi::read_swap_traffic_bytes are deleted. parse_proc_vmstat moved into the host adapter, and its test moved with it.
  • PressureSnapshot gains compressed_bytes and deficit_bytes. The TS binding was updated by hand to match ts-rs output.
  • The memory.pressure probe gains compressed_mb, host_available_mb, free_target_mb and deficit_mb. A new memory.pressure.shed probe fires on each shed fan-out. memory.shed_lru.shed and wm.results.shed already report the bytes freed.
  • Two unjustified unwrap_ors in the touched monitor file are fixed: one became total_cmp, the other got a justification.

Tests (in the new files' single test mods)

  • the_m5_incident_has_a_deficit_and_the_reporters_shed: free 60 MB, compressor 34 GB, swap 8.6 GB, RAM used 75% (under the 0.80 gate). The deficit is positive both after a clean baseline and after a restart straight into the pressure. The level is Warning, the shed path runs on every poll, and mind_results' share is ≥ everything it holds. The old RAM-only figure is 0.
  • a_clean_box_has_no_deficit_and_sheds_nothing: a small, steady compressor, inert swap and free memory above target give deficit 0, Normal level and no shed.
  • lower_priorities_give_back_first and one_deficit_is_shared_across_a_priority_not_repeated (moved from shed_lru).
  • mach_counts_and_proc_text_convert_to_the_same_reading: one host state written as Mach page counts and as /proc text gives an identical reading. an_m5_vm_stat_reads_as_activity_monitor_accounts_it uses the fixture from this M5's vm_stat on 2026-11-13. proc_text_is_read_in_bytes_and_a_missing_counter_is_no_reading. a_live_mac_reads_and_the_count_matches_the_struct checks the struct-size count and makes a live call.
  • Dyno: continuum-engine/src/capacity/dyno has no host-memory scenario library (its scenarios cover serving batches and knees), so the incident lives as the kernel test above.

Not compiled locally

The M5 is serving live minds, so no cargo build, check, test or clippy was run. CI is the compiler for this PR.

Not in this slice (later slices)

  • The other pressure reactors are not merged yet: Bevy and others shed on level only; SQLite open_connection; GpuMemoryManager; the ResourceDaemon/Consumer authority; the broker's sys-memory pool, which still frees 0 bytes.
  • mach_ffi::read_system_free_bytes (the Metal monitor's unified free bytes, free + speculative + inactive) still has its own vm_statistics64 copy. Moving it onto host_memory changes the GPU governor's free figure on the serving node, so it gets its own change and live read. Follow-up owner: Fable.
  • Swap occupancy still comes from sysinfo, which reads vm.swapusage on macOS. The monitor already made that read, so no second probe was added.

Live receipt to take after deploy (M5, 15 minutes, compared against canary)

From memory.pressure probes: avail_mb, host_available_mb, compressed_mb, swap_mb, swap_rate_kib_s, deficit_mb, level. From memory.pressure.shed, memory.shed_lru.shed (freed) and wm.results.shed (before/after): bytes shed per tick. Prefill and decode tok/s from the engine. Expected: deficit_mb is 0 on a clean box. Under compression or swap growth it goes positive, the shedders free bytes, and it returns to 0 at the next clean poll. Worse than canary means the node goes back to canary.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…sed and swapped, not RAM past a fraction

On the M5 on 2026-11-13 the box had 60 MB free, ~34 GB in the compressor and swap at
8.6 of 10 GB, prefill ran at half speed, and nothing was shed: the only shed amount was
RAM "used" past a fixed fraction of total, which a compressing host keeps under every gate.

- continuum-host::host_memory: one host reading (free, reclaimable cache, compressor,
  cumulative swap in/out, the kernel's own free target). macOS: host_statistics64 +
  vm.vm_page_free_target; Linux: /proc/meminfo, /proc/vmstat, min_free_kbytes. The two
  formats convert in pure functions tested on every host.
- memory_pressure::host_deficit: deficit = (compressed + swap_used - baseline at the last
  clean poll) + max(0, free_target - (free + reclaimable)); clean = no shortfall, no
  swap-out, compressor not grown. A positive deficit is at least Warning, and the shed path
  runs every poll while it lasts. deficit_at(priority) = max(RAM overrun past the gate,
  deficit minus what lower priorities hold); Realtime never sheds for it.
- ShedLru and mind_results shed their share of the deficit (share_of_deficit).
- The swap axis reads the same host reading: swap_activity's own cfg'd reader and
  mach_ffi::read_swap_traffic_bytes are deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…life, not past a fixed 0.90

The self_sized ratchet holds a touched file to no sized literal; SWAP_FULL_FRACTION was one.
The swap axis already measures the paging rate, so "nowhere left to page" is now free swap
against what that rate moves in one SWAP_RATE_HALF_LIFE. A full but idle swap file reads
Normal (inert pages cost nothing; the host deficit counts what the OS displaced).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 2b17c41 into canary Nov 13, 2026
45 checks passed
@joelteply
joelteply deleted the fable/host-pressure-counts-swap-and-compressor branch November 13, 2026 20:42
joelteply added a commit that referenced this pull request Nov 13, 2026
… boot plan, a settle gate, and one retirement for a floor-sized engine (card 8569b03d) (#5976)

The M5, 2026-11-13: at 19:36Z the boot plan read 16 GB usable while the stopped engine's memory was
still coming back, launched -c 2045, and the plan 15 s later (2 x 134,690 at 25 GB) was never
applied; at 22:16Z an engine launched at 49,408 for 5 sequences and did not grow in 10 minutes.
Every mind needed 68-110k and was dark until the engine was killed by hand.

- cognition: WorkingSetRegistry::remembered_residents, the newest minds a held turn measured.
- serving demand: before the persona registry exists, the requirements are the remembered
  residents', so the boot plan goes through the allocator and the launch floor (seated needs,
  capped at the proven pool on a gap reading) holds them.
- settle: the host's compressor shrinking between readings (continuum_host::host_memory, #5971)
  holds a launch below the seated needs until the host stops returning memory; read before every
  reconcile, off the runtime. No reading never waits.
- floor_sized: a ready engine whose pool holds fewer seated minds' needs than a launch at the live
  budget would is retired once (per engine process); the next reconcile launches the grown pool.
  The fork has no live pool resize route (checked cd2e16d87 tools/server/server.cpp routes).
- dyno 9 (boot during memory settle) before/after; dyno 10 (leased-in mind) known-red on the grid
  seam (MissingSeam::LeasedInRequirement).


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant