Skip to content

openvino: add GGML_OPENVINO_COMPILE_MEM_SPILL with a RAM cap - #483

Merged
ravi9 merged 6 commits into
ravi9:dev_backend_openvinofrom
cavusmustafa:ov_spill_resident_budget
Dec 4, 2026
Merged

ravi9 merged 6 commits into
ravi9:dev_backend_openvinofrom
cavusmustafa:ov_spill_resident_budget

Conversation

@cavusmustafa

@cavusmustafa cavusmustafa commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Adds GGML_OPENVINO_COMPILE_MEM_SPILL, from 0 to 1, and renames GGML_OPENVINO_SPILL_DIR to GGML_OPENVINO_COMPILE_MEM_SPILL_DIR (/var/tmp by default).

  • 0: off, the default. GGML_OPENVINO_MEMORY_OPTIMIZE=1 sets it to 0.1, next to GGML_OPENVINO_REDUCE_COMPILE_MEM=1; each one can still be set on its own.
  • 1: back the host buffers of the backend with files, as GGML_OPENVINO_SPILL_DIR did. The kernel drops these pages only when RAM runs out, so on a machine with free RAM the memory peak does not change.
  • A fraction such as 0.1: spill, and keep at most that part of the spilled weights in RAM while the model loads and compiles. This setting lowers the peak the most.

A thread writes the spilled pages to the file and drops them (msync + MADV_PAGEOUT) after every half budget of weight writes while the model loads, and whenever the resident part exceeds the budget while compile_model reads the weights back or released weights are written again, and for 10 s after (the CPU plugin's first inference reads the weights too). Outside of these, the thread sleeps without measuring. A failed msync, madvise or mincore stops the limiter with one warning, so no page that is not on disk is dropped. The GGUF source pages are paged out too. The limiter applies only to the weight buffer, not to KV cache or compute buffers. The cap needs Linux 5.4 or later (MADV_PAGEOUT).

The disk space of a spill file is reserved with fallocate when the file is created, so a full disk no longer kills the process with SIGBUS. When the space is missing, or the directory is on tmpfs or cannot be used, the backend warns and uses RAM for that buffer. Each start writes the buffers to disk: the load takes longer, and decoding can be a little slower. NPU: off unless set. Windows: ignored, as before. Cache-only mode: off. An invalid value stops the backend at startup.

Docs: ggml/src/ggml-openvino/dev_doc/OpenVINO-ENV-VARS.md, dev_doc/COOKBOOK.md and dev_doc/README.md.

Additional information

With 0.1, process RSS drops from 5.5 to 1.7 GiB on Qwen2.5-7B Q4_0 and from 9.8 to 3.4 GiB on gemma-4-12B Q4_0 (Arc B390 iGPU). The generated text is identical, decode speed is unchanged, and the first token comes 0-4 s later, depending on disk write speed. One short spike (<0.5 s) remains: llama.cpp maps the GGUF with MAP_POPULATE before the backend allocates anything.

Measurements

GPU, 1024-token prompt + 128 tokens, -c 2048, page cache dropped before each run, mean of 2 runs. "First token" is counted from process start and includes compile_model.

model config RSS after the spike first token decode
Qwen2.5-7B COMPILE_MEM_SPILL=1 5.49 GiB 15.0 s 24.1 t/s
Qwen2.5-7B COMPILE_MEM_SPILL=0.1 1.66 GiB 16.3 s 24.1 t/s
gemma-4-12B COMPILE_MEM_SPILL=1 9.76 GiB 27.6 s 13.6 t/s
gemma-4-12B COMPILE_MEM_SPILL=0.1 3.42 GiB 27.1 s 13.6 t/s

GGML_OPENVINO_DEVICE=GPU GGML_OPENVINO_COMPILE_MEM_SPILL=0.1
llama-completion -m -ngl 99 -f -n 128 --ignore-eos -c 2048 --temp 0

Requirements

Written with Claude Opus 5.5

  • AI-usage line: fill it in yourself. You're responsible for everything submitted, and the project restricts AI-generated content (see AGENTS.md and CONTRIBUTING.md).
  • "Spill" rows: "RSS after the spike" for those rows is the whole-run peak; spill without a budget has no separate spike.
  • Commit hash: if you link to code, use a permanent link with a commit hash that already exists upstream, as AGENTS.md asks.

@cavusmustafa
cavusmustafa requested a review from wine99 as a code owner December 3, 2026 02:19
@ravi9
ravi9 force-pushed the dev_backend_openvino branch 2 times, most recently from 4b5fa3a to 6e03d0d Compare December 3, 2026 16:12
@ravi9
ravi9 force-pushed the ov_spill_resident_budget branch from bc441ad to 409ccf8 Compare December 3, 2026 18:15
@ravi9 ravi9 changed the title openvino: add GGML_OPENVINO_SPILL_RESIDENT to cap the spilled weights… openvino: add GGML_OPENVINO_COMPILE_MEM_SPILL with a RAM cap Dec 3, 2026
@ravi9
ravi9 force-pushed the ov_spill_resident_budget branch from 0acf71c to 234dabb Compare December 4, 2026 00:11
@ravi9
ravi9 merged commit f0ec67d into ravi9:dev_backend_openvino Dec 4, 2026
2 checks passed
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