[PR #236] GLM conversation slots: park them in RAM (STRATA_GLM_SLOT_RAM_GB) #414

Closed
opened 2026-10-29 21:25:09 +07:00 by bsakaguchi · 0 comments
Owner

Original Pull Request: https://github.com/mw00/project-maya/pull/236

State: closed
Merged: Yes


What

\STRATA_GLM_SLOT_RAM_GB\ (0, the default = today's behavior) moves the conversation slots off the disk: \slot_save\ gains a \std::vector<uint8_t>\ overload that holds the exact bytes the file version writes, and \slot_load\ takes such a buffer back as the live state. The driver-side \Slot\ gains a shared buffer; nothing in the file paths changes, the disk mode stays byte-for-byte identical when the new env is unset.

  • Nothing reaches the disk in RAM mode: no files, no .meta\ (identity + tokens already live in the \Slot\ struct), no folder scan, nothing wiped at start — the states naturally die with the run, so \SLOT_DIR, \SLOT_GB, \SLOT_KEEP\ and \SLOT_DAYS\ do not apply and a state can never be dropped by the age cutoff.
  • The byte budget simply moves: the LRU now keeps total (bytes under \STRATA_GLM_SLOT_RAM_GB\ using the same eviction + \slot_drop\ (the buffer dies with the slot).
  • Save sizes the buffer exactly once before any copy (\slot_dsa_runs\ is read-only, so the layout is taken up front); the payload then streams device → host directly into the buffer with no \std::vector<uint8_t>\ bounce or geometric growth. An out-of-RAM resize is caught, reports, and the caller falls back to the disk path for that conversation.
  • A boot line announces the mode: \glm slots: slots parked in RAM (6.44 GB max) - nothing is written to disk, the states die with the run.

Why

The disk slots exist to keep memory lean with one resident state, but on machines with spare host RAM the disk round-trip (NVMe write on every conversation hand-off) is both the slow part and the sobering part. A RAM buffer is the same trade llama-class servers make with host-backed caches. The user-visible win measured below: a parked 100k-token conversation comes back in 0.1 s instead of the file round-trip.

Measured (single 4090 D, IQ2_XXS GLM-5.3-Flash, 128 GB host RAM, --glm-ram-resident\ + --kv-streaming on, daily pins untouched)

\\
glm slots: slots parked in RAM (6.44 GB max) - nothing is written to disk, the states die with the run
glm slots: saved a 46091-token conversation (0.74 GB in RAM in 0.3 s); 1 kept, 0.74 GB
glm slots: saved a 75691-token conversation (1.11 GB in RAM in 0.3 s); 2 kept, 1.85 GB
glm slots: took back a 46091-token conversation from RAM (0.1 s); 1 new tokens to read [was 25 s as a full prefill]
glm slots: took back a 75691-token conversation from RAM (0.1 s); 1 new tokens to read [was 41 s]
\\

Engine RSS grew 65.2 → 67.7 GB (+2.5 GB for the two parked payloads + the KV frames); the slots folder kept its 10 pre-existing file count through the whole run (RAM mode neither reads it, grows it nor wipes it). The un-used 46k state was superseded and dropped through the same LRU path — no leak across 6 park/take cycles.

Notes for review

  • The byte stream is unchanged from the file version (same \kSlotMagic\ header, per-half layout blocks and payload order), so a disk slot could in principle be loaded from RAM and vice versa; the driver never does that today.
  • With --glm-ram-resident, the expert tier is pinned at boot before slots allocate, so a late multi-GB save allocates from what is left over — the alloc-failure fallback covers the tightrun-out; deployments running that flag may want to budget \SLOT_RAM_GB\ accordingly.
  • Not exercised yet: the RAM cap eviction path (test peak 1.85 GB vs a 6.44 GB cap), the out-of-RAM fallback, split-halves (single-half run tested) and a 262k-token park.

Build: same flags as the daily (CUDA, arch 89, ggml pin \3cf03257).

**Original Pull Request:** https://github.com/mw00/project-maya/pull/236 **State:** closed **Merged:** Yes --- ## What \STRATA_GLM_SLOT_RAM_GB\ (0, the default = today's behavior) moves the conversation slots off the disk: \slot_save\ gains a \std::vector<uint8_t>\ overload that holds **the exact bytes the file version writes**, and \slot_load\ takes such a buffer back as the live state. The driver-side \Slot\ gains a shared buffer; nothing in the file paths changes, the disk mode stays byte-for-byte identical when the new env is unset. - Nothing reaches the disk in RAM mode: no files, no \.meta\ (identity + tokens already live in the \Slot\ struct), no folder scan, nothing wiped at start — the states naturally die with the run, so \SLOT_DIR\, \SLOT_GB\, \SLOT_KEEP\ and \SLOT_DAYS\ do not apply and a state can never be dropped by the age cutoff. - The byte budget simply moves: the LRU now keeps total \(bytes under \STRATA_GLM_SLOT_RAM_GB\ using the same eviction + \slot_drop\ (the buffer dies with the slot). - Save sizes the buffer **exactly once before any copy** (\slot_dsa_runs\ is read-only, so the layout is taken up front); the payload then streams device → host directly into the buffer with no \std::vector<uint8_t>\ bounce or geometric growth. An out-of-RAM resize is caught, reports, and the caller falls back to the disk path for that conversation. - A boot line announces the mode: \glm slots: slots parked in RAM (6.44 GB max) - nothing is written to disk, the states die with the run\. ## Why The disk slots exist to keep memory lean with one resident state, but on machines with spare host RAM the disk round-trip (NVMe write on every conversation hand-off) is both the slow part and the sobering part. A RAM buffer is the same trade llama-class servers make with host-backed caches. The user-visible win measured below: a parked 100k-token conversation comes back in **0.1 s** instead of the file round-trip. ## Measured (single 4090 D, IQ2_XXS GLM-5.3-Flash, 128 GB host RAM, \--glm-ram-resident\ + \--kv-streaming on\, daily pins untouched) \\\ glm slots: slots parked in RAM (6.44 GB max) - nothing is written to disk, the states die with the run glm slots: saved a 46091-token conversation (0.74 GB in RAM in 0.3 s); 1 kept, 0.74 GB glm slots: saved a 75691-token conversation (1.11 GB in RAM in 0.3 s); 2 kept, 1.85 GB glm slots: took back a 46091-token conversation from RAM (0.1 s); 1 new tokens to read [was 25 s as a full prefill] glm slots: took back a 75691-token conversation from RAM (0.1 s); 1 new tokens to read [was 41 s] \\\ Engine RSS grew 65.2 → 67.7 GB (+2.5 GB for the two parked payloads + the KV frames); the slots folder kept its 10 pre-existing file count through the whole run (RAM mode neither reads it, grows it nor wipes it). The un-used 46k state was superseded and dropped through the same LRU path — no leak across 6 park/take cycles. ## Notes for review - The byte stream is unchanged from the file version (same \kSlotMagic\ header, per-half layout blocks and payload order), so a disk slot could in principle be loaded from RAM and vice versa; the driver never does that today. - With \--glm-ram-resident\, the expert tier is pinned at boot before slots allocate, so a late multi-GB save allocates from what is left over — the alloc-failure fallback covers the tightrun-out; deployments running that flag may want to budget \SLOT_RAM_GB\ accordingly. - Not exercised yet: the RAM **cap** eviction path (test peak 1.85 GB vs a 6.44 GB cap), the out-of-RAM fallback, split-halves (single-half run tested) and a 262k-token park. Build: same flags as the daily (CUDA, arch 89, ggml pin \3cf03257\).
bsakaguchi 2026-10-29 21:25:09 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#414
No description provided.