Skip to content

Server, app: SSD prompt cache spillover (--cache-disk) and settings UI - #101

Open
Banan412 wants to merge 1 commit into
cobanov:mainfrom
Banan412:split/3-disk-cache
Open

Banan412 wants to merge 1 commit into
cobanov:mainfrom
Banan412:split/3-disk-cache

Conversation

@Banan412

@Banan412 Banan412 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

SSD prompt cache spillover (--cache-disk) and Settings/Dashboard UI split out of #89.

Related: #89 (tracking index); see also the memory-safety patch PR (#100) and the follow-up tight-VRAM planner PR (#102).

Patch Numbering

  • Uses patches/0020-server-cache-disk-spillover.patch (verified 100644 file modes; zero 100755 git apply warnings).
  • Checked against cobanov/PS5LM:main (fa0fc59) and ready for llama.cpp moves to d2bceda3d (after b12602) for Inkling 2 Mini, with every patch carried over #103: a ported 0020 targeting #103 (llama.cpp@d2bceda3d, updated for server-slot-sched.{h,cpp}, shared_ptr<const common_prompt_checkpoint>, lora_new, and the 27B checkpoint clear fix) is already compile-verified locally via scripts/apply-patches.sh + host llama-server build.

Changes

  • Server & Core Disk Spillover (patches/0020-server-cache-disk-spillover.patch):
    • Adds --cache-disk DIR (LLAMA_ARG_CACHE_DISK) and --cache-disk-mib N (LLAMA_ARG_CACHE_DISK_MIB) to llama-server (common/arg.cpp, common/common.h), and adds streaming state callbacks llama_state_seq_save_stream / llama_state_seq_load_stream (include/llama.h, src/llama-context.*).
    • Spills prompt cache entries to SSD (PCK1 blobs when --cache-ram is bounded, or streaming .seq + .chk checkpoint files when -cram 0) via 8 MiB buffered writes and 4 MiB buffered reads (tools/server/server-task.cpp, tools/server/server-task.h, tools/server/server-context.cpp).
    • Clears prompt.checkpoints on disk load before reading the incoming .chk file (preventing a 2x checkpoint RAM peak on large recurrent models like 27B where one .chk is 149.6 MiB), reports out_oom distinctly from integrity failures, and reports actual loaded checkpoint bytes.
    • Verifies integrity on every load with streaming FNV-1a checksums, writes atomically via .part + rename, sweeps stale ps5lm_ckpt_* files on startup, evicts the oldest disk entry when exceeding --cache-disk-mib, and falls back cleanly to prefill on corrupted/unwritable paths.
  • Dedicated ftpsrv Writer (ps5/app/prompt_cache_writer.cpp, scripts/build-app.sh):
    • Implements ps5lm_prompt_cache_write with its own FtpWriter + mutex so prompt spillover avoids PS5's ~2.2 GB title POSIX write slowdown cliff (#41) without contending with model downloads or fleet parking, falling back to POSIX writes when ftpsrv is unavailable.
  • Settings UI & Opt-in Off Default (ps5/app/settings.*, ps5/app/dashboard.cpp, ps5/app/main.cpp, ps5/app/model_plan.*):
    • Adds Disk cache spillover (Off (default, opt-in) / Auto (when near full) / Always on, with Off listed first in the picker) and Disk cache limit (2 GB–32 GB, default 4096 MiB) under Settings -> Model, persisted in settings.json.
    • Clears any ps5lm_ckpt_* files in /data/PS5LM/cache/prompts both on startup (main.cpp after load_settings) and on idle settings save (models.running.empty()) when disk_cache == "off".
    • Passes --cache-disk and --cache-disk-mib from plan_model when disk_cache is on or auto with < 0.75 GiB headroom.

Verification

Opt-in Off Default & /data/PS5LM/cache/prompts Cleanup (Live PS5)

  • Startup cleanup (disk_cache omitted -> defaults to "off"): Planted ps5lm_ckpt_99.seq and ps5lm_ckpt_99.chk; startup logged prompt-cache: cleared 2 cached files (disk cache off) and emptied /data/PS5LM/cache/prompts ([]).
  • Idle UI toggle cleanup (Auto -> Off): Planted ps5lm_ckpt_88.seq while Auto was active, switched back to Off in the idle UI; app.log logged prompt-cache: cleared 1 cached file (disk cache off) and emptied /data/PS5LM/cache/prompts ([]).

Multi-Model Live PS5 Switched-Chat SSD Restore Benchmark (192.168.10.6, -ctxcp 1 -cram 0, 8192 MiB)

Model Mode / Config Min pool free Intra-Chat Follow-Up Med Switched-Chat Restore (Chat N -> Chat 1) SSD Load (MiB, Speed, Hash)
Qwen3.5-9B Q6_K On (64k q8_0) 2.01 GiB 247.6 ms (1,618.7 tok) 1,810.1 ms (1,702 cached) 78.9 + 50.3 MiB chk in 0.28 s (487 MB/s, ok)
Qwen3.6-12B IQ-Q5_K_M On (64k q8_0) 2.46 GiB 202.8 ms (1,680.6 tok) 1,974.7 ms (1,727 cached) 77.7 + 56.1 MiB chk in 0.29 s (486 MB/s, ok)
qwen3.5-14b-a3b Q4_K_M On (64k q8_0) 2.05 GiB 169.7 ms (1,676.3 tok) 1,959.7 ms (1,849 cached) 82.0 + 62.8 MiB chk in 0.31 s (493 MB/s, ok)
qwen3.5-18b-a3b Q4_K_M Auto (16k q8_0) 0.10 GiB 297.9 ms (2,216.1 tok) 2,163.1 ms (2,360 cached) 87.8 + 62.8 MiB chk in 0.31 s (516 MB/s, ok)
Qwen3.8-27B IQ2_M Auto (32k q8_0) 0.12 GiB 502.6 ms (1,676.1 tok) 4,901.8 ms (1,813 cached) -> 498.1 ms post-restore 209.9 + 149.6 MiB chk in 0.73 s (520 MB/s, ok)
Qwen3.8-27B IQ2_M On (64k q4_0) 0.12 GiB 513.7 ms (1,681.2 tok) 4,640.0 ms (1,710 cached) -> 487.5 ms post-restore 179.7 + 149.6 MiB chk in 0.62 s (556 MB/s, ok)
  • Qwen3.5-2B-...-THINKING.Q8_0 (On, 64k q8_0, 8.51 GiB free): Saved/restored 30.0 MiB (+ 19.3 MiB chk) cleanly (0.11 s @ 452 MB/s, hash ok); follow-up turns report cached_tokens = 0 identically in Off, Auto, and On because its custom THINKING Jinja template alters earlier turns past -ctxcp 1.
  • 27B double-allocation fix verified: Before clearing prompt.checkpoints prior to reading .chk, loading a 149.6 MiB .chk while holding the previous chat's 149.6 MiB checkpoint hit std::bad_alloc (read_checkpo) on 27B; after prompt.checkpoints.clear(), both 32k q8_0 and 64k q4_0 restored (+ 149.6 MiB chk) with zero warnings and 487.5–498.1 ms post-restore follow-up TTFT.

Console Long-Chat Benchmark (14B MoE, -c 65536 -ctk q8_0, alternating ~7k-token chats A1 -> B1 -> A2)

Mode Switched Chat A2 TTFT cached_tokens Lowest pool free (app.log) Lowest flexible free Sustained Spillover
Without --cache-disk (Off) 22,013.7 ms (22.01 s) 0 1.85 GiB 303 / 448 MiB None
With --cache-disk (On, 8192 MiB) 2,296.5 ms (2.30 s, 9.58x faster) 6,868 1.85 GiB 303 / 448 MiB 2,773.9 MiB over 12 switches at 103–115 MB/s

Hardened 5-Point Deep Console Verification (14B MoE, ~7,154 prompt tokens, 256 MiB flex)

  1. Cold vs. VFS-evicted SSD & restart:
    • Off A2 cold prefill: 23,003.8 ms (cached_tokens: 0); On warm SSD restore: 2,717.9 ms (cached_tokens: 7,130, 8.46x faster, disk load 0.36 s @ 581 MB/s).
    • Cold VFS-evicted SSD restore (after 7 distinct ~7k-token flush chats wrote 1,640.4 MiB across 16 files): 2,601.1 ms (cached_tokens: 7,150, disk load 0.41 s @ 511 MB/s).
    • Post-restart cold check: startup sweep cleared /data/PS5LM/cache/prompts to 0 files and A4 ran cold prefill in 22,973.3 ms (cached_tokens: 0).
  2. Integrity & truncation injection:
    • 1-byte bit-flip in .seq, 50%-truncated .seq, and 50%-truncated .chk were all caught by FNV-1a / stream validation, discarded without crashing, and fell back to prefill -> HTTP 200 (cached_tokens: 0).
  3. Interrupted writes, limits & failure modes:
    • Startup orphan sweep removed 4 planted .seq/.chk/.part files cleanly (0 left).
    • --cache-disk-mib 300 evicted the oldest 207.570 MiB entry, keeping disk usage at 207.6 MiB <= 300 MiB.
    • Unwritable --cache-disk /app0/nope logged a warning gracefully and served HTTP 200; host test_disk_enospc verified /dev/full ENOSPC (errno=28), 128 MiB free-space guard, and RLIMIT_FSIZE (errno=27) aborting and unlinking .part.
  4. Memory & SSD overhead:
    • 0.00 GiB VRAM overhead (min_pool_free 2.04 vs 2.04 GiB), 0 MiB flex overhead (111 vs 111 MiB), +0.08 GiB transient heap peak (0.78 vs 0.86 GiB), and 1.000x write amplification (single-pass ftpsrv stream to .part + atomic rename).
  5. Repeatability (7 consecutive B -> A trials, cached_tokens = 7,114..7,134, all HTTP 200):
    • Min 2,502.1 ms | Median 2,604.2 ms | Mean 2,587.6 ms | Worst 2,644.2 ms (98–104 MB/s saves, 564–581 MB/s loads).

Refs #89.

Console Screenshots

Live PS5 TV Settings -> Model showing Disk cache spillover defaulting to Off
Live PS5 TV Settings → Model showing Disk cache spillover defaulting to Off (Disk cache limit: 8 GB).

Disk cache spillover picker opened with Off first
Opening Disk cache spillover lists Off first above Auto (when near full) and Always on.

Disk cache limit picker opened showing 2 GB to 32 GB capacity choices
Opening Disk cache limit presents the SSD cache cap choices (2 GB, 4 GB, 8 GB, 16 GB, 32 GB).


Generated with Google's Antigravity

@cobanov cobanov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the measurements are great: 22 s down to 2.3 s on a switched chat is a real win.

Because it changes what the server does for everyone with a tight model, I'd like it opt-in at first: please change the new disk_cache = "auto" default in ps5/app/settings.hpp to "off". If you'd rather keep Auto as the default, I'd need the long-chat test on a tight model in Auto (your 18B at about 0.14 GiB free), with the lowest pool free during saves.

It also needs a re-roll on b12600 once #103 lands. Clearing /data/PS5LM/cache/prompts when the setting is Off would be nice too.

@Banan412

Copy link
Copy Markdown
Contributor Author

@cobanov Updated split/3-disk-cache (9df6910) and PR #101 with your review changes:

  • Default changed to "off" (opt-in): Updated Settings::disk_cache default to "off" in ps5/app/settings.hpp, moved Off first in the picker (kDiskCacheSteps = {"off", "auto", "on"}), and normalized unknown values to "Off".
  • Cache cleanup when Off: Added clear_prompt_cache_dir() in ps5/app/main.cpp to remove ps5lm_ckpt_* files in /data/PS5LM/cache/prompts both on startup and on idle settings save when disk_cache == "off". Verified on live PS5:
    • Startup with disk_cache omitted from settings.json cleared 2 planted files (prompt-cache: cleared 2 cached files (disk cache off) -> []).
    • Toggling Auto -> Off in the idle Settings UI cleared 1 planted file (prompt-cache: cleared 1 cached file (disk cache off) -> []).
    • Updated screenshots (settings_off_default.png, settings_picker_off_first.png).
  • 18B MoE tight-VRAM check (Auto + -c 16384 -ctk q8_0 -ctxcp 1 -cram 0 --cache-disk): Over 3 × 10-turn chats + switched-chat Chat 3 -> Chat 1 SSD restore, saves streamed 87.8–89.4 MiB + 62.8 MiB chk at 94–103 MB/s, restored Chat 1 (2,360 / 2,421 cached tokens) in 0.31 s @ 516 MB/s, and stayed clean with lowest pool free = 0.10 GiB (vs 0.12 GiB in Off).
  • PR llama.cpp moves to d2bceda3d (after b12602) for Inkling 2 Mini, with every patch carried over #103 (llama.cpp@d2bceda3d) readiness: Pre-ported 0020 onto #103's d2bceda3d locally (adapting server_prompt_cache in server-slot-sched.{h,cpp}, shared_ptr<const common_prompt_checkpoint>, and lora_new), and verified clean apply-patches.sh (100644, zero warnings) + full host llama-server build ([197/197]) ready for rebase as soon as llama.cpp moves to d2bceda3d (after b12602) for Inkling 2 Mini, with every patch carried over #103 merges.

@Banan412

Copy link
Copy Markdown
Contributor Author

@cobanov Follow-up from testing all 6 installed models (2B, 9B, 12B, 14B-A3B, 18B-A3B, 27B) live on PS5 (192.168.10.6), pushed to split/3-disk-cache (7d1375a):

  • Fixed 27B checkpoint bad_alloc spike in 0020: On Qwen3.8-27B (0.12 GiB free pool, 149.6 MiB .chk), server_prompt_cache::load() previously read the incoming .chk before releasing the outgoing slot's prompt.checkpoints, briefly requiring 2 × 149.6 MiB (std::bad_alloc discarding checkpoints). Calling prompt.checkpoints.clear(); first (plus reporting out_oom vs integrity failure and actual restored checkpoint bytes) eliminates the spike — both 27B-auto (32k q8_0) and 27B-on (64k q4_0) now restore (+ 149.6 MiB chk) with zero warnings (520–556 MB/s) and follow up at 487.5–498.1 ms TTFT. Also synced into the local #103 (d2bceda3d) pre-port.
  • Additional live switched-chat SSD restore numbers (8192 MiB, -ctxcp 1 -cram 0):
    • 9B Q6_K (64k q8_0, 2.01 GiB free): 1,810.1 ms (1,702 cached, 0.28 s @ 487 MB/s)
    • 12B IQ-Q5_K_M (64k q8_0, 2.46 GiB free): 1,974.7 ms (1,727 cached, 0.29 s @ 486 MB/s)
    • 14B-A3B Q4_K_M (64k q8_0, 2.05 GiB free): 1,959.7 ms (1,849 cached, 0.31 s @ 493 MB/s)
    • 27B IQ2_M (32k q8_0 Auto, 0.12 GiB free): 4,901.8 ms (1,813 cached, 209.9 + 149.6 MiB chk in 0.73 s @ 520 MB/s) -> 498.1 ms next turn
    • 27B IQ2_M (64k q4_0 On, 0.12 GiB free): 4,640.0 ms (1,710 cached, 179.7 + 149.6 MiB chk in 0.62 s @ 556 MB/s) -> 487.5 ms next turn

@cobanov

cobanov commented Nov 25, 2026

Copy link
Copy Markdown
Owner

@Banan412 #103 is in (ead7971), so please push the 0020 you re-rolled on d2bceda3d. The Off default, the cleanup when Off, and the tight-model numbers in Auto cover what I asked for. Once CI is green on the new pin, I'll approve it.

@Banan412

Banan412 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@cobanov Pushed the d2bceda3d re-roll rebased onto main (5e96235, including #103 ead7971, #109 dcb5254, #110 5e96235, and #112 0022) to split/3-disk-cache (36fc8af), keeping 0020 (100644 headers, Off default, clear_prompt_cache_dir(), and the 27B prompt.checkpoints.clear() fix).

…ftpsrv writer and settings UI

# Conflicts:
#	scripts/build-app.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants