포스트

Ollama Memory Pressure with One Active Request: Measurements and Limits

Holding request concurrency at one while increasing configured KV slots on a 32GB Mac Mini: observed slowdown, sampled RSS, and the limits of system-wide paging counters.

Ollama Memory Pressure with One Active Request: Measurements and Limits

Correction — September 13, 2026: The original post treated system-wide Pageouts as proof of KV-specific swap thrashing and labeled prefill duration as TTFT. It also called the experiment purely memory-isolated. This revision preserves the measurements while separating them from unverified mechanisms and removes untested safe-concurrency recommendations.

The Question

The parallel sweep varied active requests within a fixed four-slot configuration. Its RSS stayed almost constant as concurrency increased, so that sweep did not isolate swap-induced slowdown. Changing the configured slot count was a separate experiment.

Here I kept one active request and increased OLLAMA_NUM_PARALLEL, restarting Ollama at each level. In the tested configuration, more configured slots increased the memory provisioned at model load even when most slots were idle. This reduces the confounding effect of simultaneous active requests, but does not prove that GPU work, caching, engine configuration, and system state were identical.

Experiment Design

flowchart LR
    A["NP=1, active requests=1"] -->|"Restart; increase configured slots"| B["NP=8, active requests=1"]
    B -->|"Restart; increase configured slots"| C["NP=15, active requests=1"]

The hypothesis was that larger preallocated capacity would increase memory pressure and affect the same sequential workload. Page-level attribution would require additional instrumentation.

Hardware

ComponentSpec
MachineMac Mini (2024)
ChipApple M4
Unified Memory32 GB
Memory Bandwidth~120 GB/s
GPU Cores10-core
Storage256 GB SSD (swap target)
OSmacOS Sequoia

Apple Silicon’s unified memory architecture means GPU and CPU share the same physical RAM pool. When Ollama allocates KV cache, it directly competes with the OS and other applications for the same 32 GB.

Model & Configuration

ParameterValueWhy
Modelqwen2.5-coder:7b (Q4_K_M, 4.7 GB)Small enough to leave room for KV cache growth
num_ctx32,768Context setting used for each configured slot
QuantizationQ4_K_MStandard Ollama default
Seed42Reproducibility
Temperature0.0Reduce sampling variability

Workload

Each benchmark step sends the exact same prompt:

“Write a Python function that validates an email address using regex. Include type hints, error handling, docstring, and 3 example test cases.”

This prompt is intentionally simple and consistent — the goal isn’t to test different prompts, but to measure how the same workload performs under different memory conditions.

Per step (each NUM_PARALLEL level):

  1. Restart Ollama with OLLAMA_NUM_PARALLEL=N
  2. Send one warm-up request (triggers model + KV cache allocation)
  3. Run 5 benchmark requests with 3-second cooldown between each
  4. Average the 5 results for stability
  5. Record: generation speed, prefill speed and duration, sampled RSS, system swap usage, and changes in system Pageouts

What the Script Measures

The script computes generation and prefill speed from Ollama’s token counts and durations. Its ttft_ms field is prompt_eval_duration / 10⁶; requests are non-streaming, so it does not measure client-observed time to first token.

memory_mb is the larger of the pre- and post-measurement RSS sums for matching Ollama processes. The calculation divides by 1024², so the values are MiB despite the original MB field name. This is not a continuously sampled peak, and shared pages can be counted in multiple processes.

swap_used_mb comes from psutil.swap_memory(). page_outs is the change in the system-wide vm_stat Pageouts counter across each five-request measurement interval. Neither identifies the owning process or buffer. The observed roughly 950 MiB RSS increase per additional slot in the early rows is consistent with increased KV provisioning; it is not a direct per-buffer allocation trace.

Results

NPGen t/sPrefill t/sPrefill (ms)Sampled RSS (MiB)Pageouts deltaPhase
121.11,085535,6830🟢 Flat
221.11,091536,6320🟢
321.01,100537,5880🟢
421.01,093538,5400🟢
520.91,098539,4950🟢
622.21,2274710,4480🟢
722.31,1974811,4030🟢
820.21,1115212,6790🟢
918.71,0185713,6320🟡 Degradation
1017.29626014,5876🟡
1115.69286315,53642🔴
1214.38926516,386131🔴 Cliff
1314.49196316,47122⚪ Stabilized
1414.49176316,5222⚪
1514.49236316,8409⚪

Visualization

xychart-beta
    title "Generation Speed vs NUM_PARALLEL (One Active Request)"
    x-axis "NUM_PARALLEL" [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    y-axis "Gen Speed (t/s)" 10 --> 25
    line [21.1, 21.1, 21.0, 21.0, 20.9, 22.2, 22.3, 20.2, 18.7, 17.2, 15.6, 14.3, 14.4, 14.4, 14.4]
xychart-beta
    title "Ollama Memory (RSS) vs NUM_PARALLEL"
    x-axis "NUM_PARALLEL" [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    y-axis "Sampled RSS (MiB)" 4000 --> 18000
    line [5683, 6632, 7588, 8540, 9495, 10448, 11403, 12679, 13632, 14587, 15536, 16386, 16471, 16522, 16840]

Observations and Interpretation

NP=1–8: RSS rises with relatively stable speed

Generation speed stays around 20–22 t/s while sampled RSS rises from 5,683 to 12,679 MiB. This is consistent with extra configured capacity consuming memory before those slots serve requests. It does not prove that unused slots have zero execution cost. The modest speed variation was not accompanied by per-run uncertainty estimates in the saved aggregate results.

NP=9–12: speed falls and Pageouts increase

The raw result changes from 21.09 t/s at NP=1 to 14.31 t/s at NP=12, a 32.1% reduction. RSS at NP=12 is 16,385.6 MiB. The Pageouts deltas are 0, 6, 42, and 131 at NP=9, 10, 11, and 12 respectively. Raw results

These observations are consistent with memory pressure contributing to slowdown, but they do not identify a particular compression or paging mechanism. Swap was already about 1,789 MiB at NP=1. NP=10 was the first positive Pageouts delta in these measurement intervals, not the first time the system had used swap. Recorded swap usage actually declined to about 1,773 MiB at NP=12.

The original statements that NP=9 marked the start of compression, that NP=12 proved swap thrashing, and that the GPU was waiting on swapped KV pages were not supported by these counters. Resolving that would require time-correlated CPU/GPU measurements, page-ins, compressor statistics, and process/resource attribution.

NP=13–15: speed levels off

The saved results level off near 14.4 t/s. A stable working set or changed reclamation behavior could contribute, but the measurements do not show which pages became hot or cold, or prove that idle GPU KV buffers were swapped. This is an observed plateau, not a verified OS-equilibrium mechanism.

What to Take from the Experiment

The result supports a practical investigation direction: configured capacity can increase resident memory and correlate with slower service even with one active request. It does not establish a universal 32% penalty, or a memory-only causal effect with all other variables excluded.

For this 32 GB, 7B, 32K-context experiment, slowdown became visible around NP=9. I have removed the earlier table of “max safe” settings for 16 GB and 64 GB machines and other model sizes because those configurations were not measured here. Capacity planning also needs weights, recurrent state, compute buffers, other processes, and workload-dependent peaks; reserving a fixed 8 GB for the OS cannot guarantee safety.

A stronger follow-up would record actual KV allocation, continuously sampled process and GPU memory, client-streamed TTFT, repeated-run uncertainty, and matched warm-up/cache conditions while varying configured capacity.

Reproducing This Experiment

1
2
3
4
5
6
7
8
9
git clone https://github.com/rockyRunnr/ollama-bench
cd ollama-bench && pip install -e .

# Run the configured-slot sweep with one active request
python memory_pressure_test.py \
    --model qwen2.5-coder:7b \
    --num-ctx 32768 \
    --max-np 15 \
    --output results.json

The script automatically restarts Ollama at each NUM_PARALLEL level, runs 5 requests with 3-second cooldowns, and records system-wide Pageouts from vm_stat plus swap usage from psutil. These are system-level counters.

GitHub


The measured speed decline and plateau motivated the later KV allocation investigation. Identifying the exact memory mechanism remains separate from observing those phases.

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.