UPGRD
← Home

Artificial Intelligence

Running LLMs Larger Than Your RAM: What Memory Mapping Actually Does

Memory mapping makes it possible to address language models larger than available physical memory. The real question is whether the resulting inference speed is useful.

Home · · 6 min read · Updated November 26, 2026
  • LLM
  • GGUF
  • llama.cpp
  • NVMe
  • Memory Mapping
  • Inference
Diagram showing language-model weights moving between an NVMe drive, system RAM and GPU memory.

Quick summary

Memory mapping makes it possible to address language models larger than available physical memory. The real question is whether the resulting inference speed is useful.

“The model loads” and “the model runs well” are different claims. Memory mapping can let a process establish a virtual address range for a model file that is larger than available physical RAM. It does not create extra memory bandwidth, keep every model page resident, or make storage behave like RAM. Whether generation is practical depends on which weights the inference engine needs, how quickly those pages can be supplied, and how much memory remains available for runtime state and the operating system.

A mapping is an address range, not a pile of RAM

With a mapped file, the operating system maps file offsets into a process’s virtual address space. Pages become resident in physical memory when accessed, subject to the operating system’s page-cache and memory-management behavior. An access to a page not currently resident can trigger a page fault; the kernel may retrieve its contents from storage, or the data may already be in cache. Under memory pressure, pages can be reclaimed and later have to be read again. Thus, a model whose file fits on an NVMe drive but not in RAM may be addressable, while still suffering slow or variable reads as the working set cycles through memory.

“Virtual size” is not equivalent to resident set size. Likewise, a high page-cache figure is not necessarily memory permanently unavailable to other work: reclaimable file-backed cache can be evicted, though doing so may force later reads. Performance depends on locality. Reusing mapped pages from memory can be quite different from repeatedly faulting them back from a drive. For a related storage-tier example, see how ZFS separates ARC, L2ARC and SLOG.

Why token generation is unforgiving

For a dense autoregressive model, decoding generates tokens sequentially: the next token depends on the previous result. During each decode step, a large share of model weights may need to be read to compute that token. If the relevant weights cannot remain in RAM or accelerator memory, repeatedly fetching them from storage can dominate latency. The model’s compressed representation, compute, quantization, batch size, context length, memory bandwidth, and runtime implementation all matter, but an SSD does not become a drop-in extension of RAM.

Consider only an idealized bandwidth calculation: if an inference step had to read 20 GB of weights and the storage sustained 5 GB/s of useful reads, the arithmetic lower bound for that transfer alone would be 4 seconds per token. That is not a benchmark, prediction, or measured llama.cpp result. It assumes the full amount is transferred for each step, perfectly sustained bandwidth, and no competing cost; actual behavior may differ substantially due to caching, fault granularity, CPU/GPU transfer, parallelism, and computation. The calculation illustrates why repeated storage traffic can erase the apparent convenience of mapping a large file.

Mixture-of-Experts models change which weights are used for a token, but do not automatically make SSD streaming efficient. A router may select only some experts, yet the active experts and shared layers still need to be supplied at low latency. If experts are not resident, repeatedly fetching selected blocks can lead to unpredictable page faults and storage traffic; sparsity is not a promise that an arbitrary model larger than RAM will run smoothly.

Understand what your runtime controls

GGUF is the model-file format used by llama.cpp and related tooling; it packages model metadata and tensors, with many variants storing quantized tensors. Quantization reduces weight storage and often memory needs, but does not remove the need to read and compute over the weights that the selected inference path uses. Available loading behavior is version-dependent, so inspect the options for the exact build you deploy.

The current llama.cpp completion documentation describes a loading-mode option (--load-mode, with -lm) that includes automatic behavior, memory mapping, locking pages in RAM, both mapping and locking, and direct I/O where available. It also documents lazy reading for certain tensors and GPU layer offload controls. Older examples may use --mmap or --no-mmap; do not assume a flag from a guide written for another revision is still the current interface. Mapping and locking are distinct: mapping establishes file-backed virtual memory, while locking requests that pages stay in RAM rather than being swapped or compressed, subject to platform and resource constraints. Neither choice guarantees a model fits without memory pressure.

./llama-bench -m /models/model.gguf -p 0 -n 64 -lm mmap -r 3

This version-specific example measures decode throughput only; it does not report time to first token or model-page residency. Replace the model path and preserve the exact llama.cpp build when comparing modes.

Benchmark the workload you will serve

Use an isolated host and record enough detail to separate cold-start cost from steady-state decoding. Keep model file, quantization, prompt, context length, generation length, thread configuration, GPU-offload settings, and runtime build constant when comparing modes. Measure prompt processing and decode throughput separately, plus time to first token and total request latency. Prompt ingestion can parallelize work differently from sequential token decode, so a single aggregate tokens-per-second number hides important behavior.

Track process resident memory and host memory availability, GPU memory use when relevant, major page faults, and storage reads during the run. A cold first request and a warm repeat can tell very different stories: the latter may benefit from file-backed pages remaining in cache. Also watch swap activity and concurrent workloads, and test the intended concurrency rather than just one interactive session. A successful short run does not show that the system can sustain a large active set without evicting pages under normal service load.

For llama.cpp, use the benchmark utility and inference options documented for your checked-out version, and preserve the command line and model metadata with the results. If a model is partially offloaded to a GPU, explicitly record how many layers and which split mode are used; “the model fits” can mean very different combinations of host RAM and VRAM. Compare mmap settings only while controlling other variables. If the model stays resident and decoding is acceptable, mmap can be convenient and avoid a separate eager-copy step. If weights continually fault from a slow device, a smaller quantization, more RAM, greater accelerator memory, or a different model is usually a more useful direction than treating mmap as capacity without cost.

The practical question

Memory mapping solves an address-space and file-loading problem. It does not solve the bandwidth requirements of inference. For an occasional local experiment, slower generation can be an acceptable tradeoff. For a service, the right question is whether first-token latency, sustained decode rate, and concurrency meet requirements when the system is in its real memory state—not merely whether a model file can be opened.

References

llama.cpp completion usage and loading options; llama.cpp benchmark utility; Linux mmap(2); Linux mlock(2).