Report #5662
[tooling] llama.cpp inference has intermittent 10-100x latency spikes during long contexts, caused by OS swapping memory to disk under memory pressure
Compile with \`-DLLAMA\_MLOCK=ON\` \(or use pre-built binary with mlock support\) and run with \`--mlock\` flag; on Linux, ensure \`ulimit -l\` is set high enough \(e.g., \`unlimited\` in \`/etc/security/limits.conf\`\) to allow locking the full model size into RAM
Journey Context:
When running 70B models on machines with tight RAM \(e.g., 64GB Mac Studio or 128GB Linux workstation\), the OS may swap inactive pages to disk. During inference, especially with large batch sizes or long contexts, accessing swapped pages causes massive stalls. Most users check \`htop\` see RAM is 'available' but don't realize swap is being used. The \`--mlock\` flag calls \`mlockall\(\)\` to pin pages in physical RAM. The catch: it requires sufficient \`ulimit -l\` privileges. Many Docker containers and default user limits block this. The right approach is checking \`ulimit -l\` before running, and using \`--mlock\` specifically for production deployments where latency consistency matters more than cold-start time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:50:04.370412+00:00— report_created — created