[Performance]: macOS planner trusts `free + inactive`, but the kernel compresses the expert cache — 32 GiB budget is slower than 16 GiB on a 48 GB Mac
Commit
a8f2ca623ffe9de9df11d56f34d11d2d501493d3 (main). The code in question (c/deepseek_v4.c L1061–1071, available-memory probe used by coli_v4_resource_plan_compute) is byte-identical on dev @ 91a8c8e.
Summary
On a 48 GB MacBook Pro the deepseek_v4 planner accepts any RAM_GB budget below free + inactive. macOS does hand out that memory, but from roughly 24–28 GiB upwards it moves a large part of the anonymous expert cache into the memory compressor instead of keeping it resident. Cache hits then need decompression, and decode throughput drops below the 16 GiB tier (0.96 vs 1.31 tok/s). Nothing is swapped (swap Δ ≤ 1 MiB), so swap-based checks do not catch it, and the engine logs the tier as fully effective.
Hardware and storage
MacBook Pro, Apple M5 Pro, 48 GB unified memory, internal SSD (APFS), AC power, no other foreground apps.
Software environment
macOS 26 (Darwin 25.6.0), Apple clang, static libomp 19, arm64 native build, CPU backend, 15 compute + 3 loader threads (engine default).
SERVE=1 CTX=2048 NGEN=128 COLI_V4_AUTOPIN=0 COLI_V4_SAVE_USAGE=0 COLI_V4_PREWARM=0 V4_PREFIX_CKPT=0 V4_DRAFT=0 DSV4_CUDA=0
Build and benchmark commands
make -C c -f Makefile.deepseek-v4 deepseek-v4 OMPDIR=<static libomp> -j8
# one fresh engine process per tier, RAM_GB = 16 / 24 / 28 / 32
SERVE=1 SNAP=<model dir> CTX=2048 NGEN=128 RAM_GB=<tier> ./deepseek_v4
# client: 1 first request + 3 x same 20-token prompt (warm) + 3 topic changes,
# greedy, 128 new tokens; vm_stat + proc_pid_rusage sampled once per secondResults
Warm-up policy: first request after process start reported separately; table = median of the 3 warm repetitions (spread < 2 %). free + inactive before each tier: 29.7 / 32.2 / 36.0 / 37.1 GiB, i.e. every budget was accepted as-is (ram_tiers available= ≥ requested).
DeepSeek-V4-Flash REAP 150B (puwaer/DeepSeek-V4-Flash-0731-reap-150b, rev 7c76db2, 85 GB)
RAM_GB |
slots / target cache | decode tok/s | expert hit % | physical reads / request | engine RSS (median) | in macOS compressor (median / max) |
|---|---|---|---|---|---|---|
| 16 | 14 / 7.5 GiB | 1.31 | 52 % | 148 GiB | 14.8 of 14.9 GiB | 0.8 / 1.5 GiB |
| 24 | 29 / 15.5 GiB | 1.41 | 69 % | 100 GiB | 22.9 of 23.0 GiB | 2.2 / 10.9 GiB |
| 28 | 37 / 19.8 GiB | 1.27 | 73 % | 91 GiB | 22.8 of 27.3 GiB | 7.4 / 14.2 GiB |
| 32 | 44 / 23.6 GiB | 0.96 | 77 % | 85 GiB | 17.6 of 31.0 GiB | 16.0 / 18.3 GiB |
DeepSeek-V4-Flash, full (deepseek-ai/DeepSeek-V4-Flash-0731, rev 7872f01, 167 GB), same machine and protocol:
16 → 24 → 28 → 32 GiB = 1.34 → 1.43 → 1.46 → 1.44 tok/s, compressor 2.1 / 2.3 / 2.8 / 5.8 GiB.
So hit rate and physical reads improve monotonically with the budget, but throughput does not. The collapse is much stronger for the REAP checkpoint (likely reason: its buffered fallback reads, reported separately), but the planner criterion is the same in both cases: it reports the tier as effective while the kernel is compressing up to 16 GiB of it.
Why free + inactive is not enough on macOS
inactivepages are largely file-backed cache that the kernel can reclaim, but under pressure it prefers to compress anonymous pages rather than drop file cache aggressively.- The compressor is invisible to
free/inactive/ swap counters; onlyvm_stat"Pages occupied by compressor" (compressor_page_countinhost_statistics64) shows it. kern.memorystatus_vm_pressure_levelstayed at 1 (normal) during the 32 GiB run, so it is not a usable signal either.
Suggestions
- On Darwin, subtract a safety margin from
free + inactive(e.g. cap the expert cache at ~50 % of physical RAM, orfree + inactive − max(4 GiB, 15 %)), and document that the budget is a planner target, not a residency guarantee. - Log
compressor_page_countnext toram_tiers available=at startup and periodically; warn when it grows while the engine runs (one cheaphost_statistics64call). - Possibly
mlock/madvisethe expert-cache slabs so the kernel does not compress them — untested.
Limits of this report
One machine, one pass per tier in fixed order 16 → 24 → 28 → 32, n = 3 only for the warm runs. Why macOS compresses so much earlier with the REAP checkpoint is a hypothesis, not proven.
Side observation, in case it is unexpected: prefill ran at only 1.3–1.75 prompt tok/s here, i.e. decode speed (189-token prompt → 108–142 s TTFT, 577 tokens → 360 s, 24 GiB, both models). #905 was closed as completed, so this may be specific to the macOS CPU path (cf. #1309) or to my settings above (V4_PREFIX_CKPT=0, V4_DRAFT=0). Happy to file it separately with logs if useful.
Disclosure: the benchmark harness, runs and this write-up were produced with the help of an AI coding agent (Claude Code); all numbers come from logged runs, and the per-request CSV plus per-second samples are available.
Source: JustVugg/colibri