Black Friday week: local AI hardware on sale. See the list.
← All guides

llama.cpp mmap vs mlock (2026): --load-mode none, mlock and mmap+mlock Explained

llama.cpp has six ways to load a model, and the flag that picks one, -lm or --load-mode, replaced --no-mmap and --mlock in 2026. The modes are not interchangeable. One keeps the model in the page cache, one copies it into ordinary memory, and two lock it in RAM so the OS cannot swap it out. Here is what each mode does in the current source, which old command line each one replaces, and when the default is the wrong choice.

Jump to 10 sections
  1. Bottom Line (2026)
  2. What Each Load Mode Does
  3. The Old Flags, Mapped Exactly
  4. When to Turn mmap Off: CPU Offload
  5. When to Keep the Default
  6. mlock: The Lock Can Fail
  7. How to See Which Mode You Got
  8. Compare Modes With llama-bench
  9. Sources
  10. See Also

Bottom Line (2026)

  • Six modes, one flag. -lm, --load-mode takes auto, none, mmap, mlock, mmap+mlock or dio. The default is auto, which means mmap unless a device does not support it.
  • -lm mlock does not use mmap. It reads the weights into ordinary buffers and locks them in RAM. -lm mmap+mlock is the mode that maps the file and locks it. PR #26135 split the two on 2026-07-27. The first release with the split is b10145.
  • The old --no-mmap --mlock pair has an exact replacement: -lm mlock. The old --mlock on its own maps to -lm mmap+mlock.
  • Turn mmap off when part of the model lives in system RAM. That means --n-cpu-moe, --cpu-moe or -ot ...=CPU. llama.cpp prints a warning that tells you to use --load-mode none in that case.
  • Keep the default on a model that fits in VRAM. mmap loads faster, and --lazy-mode reads big tensors from the mapped file.
  • Got error: invalid argument: --no-mmap? The old spelling is gone. See the fix table on the flags page.

Every statement on this page was checked against llama.cpp master at commit 16f090f on 2026-11-28: the argument parser, the model loader and the server README.

What Each Load Mode Does

ModeUses mmapLocks in RAMWhat it is for
auto (default)Yes, unless a device has no mmap supportNoMost setups
noneNoNoCPU offload of MoE experts or layers
mmapYesNoThe same as auto on a device that supports mmap
mlockNoYesCPU offload on a machine that swaps under load
mmap+mlockYesYesA model you run from RAM and never want paged out
dioNoNoDirectIO reads, where the platform supports them

The help text for each mode, from common/arg.cpp:

  • auto: “mmap, unless a device does not support it”
  • none: “no special loading mode”
  • mmap: “memory-map model (if mmap disabled, slower load but may reduce pageouts if not using mlock)”
  • mlock: “force system to keep model in RAM rather than swapping or compressing”
  • mmap+mlock: “mmap + force system to keep model in RAM rather than swapping or compressing”
  • dio: “use DirectIO if available”

The “Uses mmap” column comes from the model loader. It turns mmap on for exactly three modes: mmap, mmap+mlock and auto. The memory lock applies to mlock and mmap+mlock.

The Old Flags, Mapped Exactly

Before July 2026, mmap was on by default (use_mmap = true in the old common.h), and --mlock added a lock on top. So each old command line maps to one mode:

Old command lineWhat it didWrite this instead
(no flag)mmapNothing. auto is the default
--no-mmapRead into ordinary buffers-lm none
--mlockmmap, then lock-lm mmap+mlock
--no-mmap --mlockRead into ordinary buffers, then lock-lm mlock
--mmapmmap-lm mmap, or delete it
--direct-ioDirectIO-lm dio

Why some guides give a different answer. PR #20834 added --load-mode on 2026-07-23. In that first version, mlock meant “mmap + force system to keep model in RAM”, so --no-mmap --mlock had no replacement. Issue #26110 reported the cost for MoE offload users. With -lm none, the expert pages went to swap under load, and generation fell from about 25-27 t/s to 7.55 t/s. With the old -lm mlock, the server was killed by the OOM killer. PR #26135 fixed it on 2026-07-27, four days after PR #20834. Builds from b10105 to b10144 have the old meaning. Run llama-server --version to see which build you have.

When to Turn mmap Off: CPU Offload

mmap is the wrong choice when you keep part of the model in system RAM on purpose. That is every --n-cpu-moe, --cpu-moe and -ot <pattern>=CPU setup.

llama.cpp tells you so itself. When a tensor override sends weights to the CPU while mmap is on, the loader prints this warning once:

llama_model_loader: tensor overrides to CPU are used with mmap enabled - consider using --load-mode none for better performance

There are two reasons.

  1. Pinned memory uploads faster. The llama.cpp MoE cache docs say: “The host experts are pinned with -lm none, -lm mlock and -lm dio, unless --no-host, but not when they are mmap’d (the default). The device uploads pinned experts at the full speed of the link.”
  2. Fewer pageouts. The mmap help text says that with mmap off you get a “slower load but may reduce pageouts if not using mlock”.

--n-cpu-moe and --cpu-moe are tensor overrides inside llama.cpp, so they trigger the same warning as a hand-written -ot.

Start with -lm none. If the machine still swaps under real load, change to -lm mlock. That is the case issue #26110 measured.

# MoE model with experts in system RAM
llama-server -m model.gguf -ngl 999 --n-cpu-moe 20 -fa on -lm none

# the same, on a machine that swaps under load
llama-server -m model.gguf -ngl 999 --n-cpu-moe 20 -fa on -lm mlock

The --n-cpu-moe value here is an example. Sweep your own: see llama.cpp MoE Offload Flags Explained.

When to Keep the Default

Keep auto when the whole model fits in VRAM, or when you run on the CPU with RAM to spare.

  • Load time. The help text says that without mmap you get a “slower load”.
  • --lazy-mode. It reads large tensors, for example per-layer embeddings, from disk on demand. The README says it “requires mmap”. The default, auto, turns it on only for tensors larger than 4 GiB. The current loader still maps the file for those tensors under -lm none. But on a device with no mmap support, auto falls back to off when mmap is not in use.
  • Devices without mmap. You do not need to set anything. auto checks every device and turns mmap off if one does not support it.

mlock: The Lock Can Fail

-lm mlock and -lm mmap+mlock ask the OS to lock the memory. The OS can refuse. The model still loads, but llama.cpp prints a warning like this:

warning: failed to mlock <size>-byte buffer (after previously locking <size> bytes): <system error>

When the cause is the lock limit, llama.cpp adds a hint (src/llama-mmap.cpp):

  • Linux: “Try increasing RLIMIT_MEMLOCK (‘ulimit -l’ as root).”
  • macOS: “Try increasing the sysctl values ‘vm.user_wire_limit’ and ‘vm.global_user_wire_limit’ and/or decreasing ‘vm.global_no_user_wire_amount’. Also try increasing RLIMIT_MEMLOCK (ulimit -l).”

A lock does not add memory. If the model and the KV cache do not fit in RAM, a lock cannot fix that.

How to See Which Mode You Got

The load log names the mode that llama.cpp actually used:

load_tensors: loading model tensors, this can take a while... (load_mode = none)

With auto, the log does not print auto. It prints the result: mmap, or none if a device turned mmap off. Use this line when a setup “ignores” your flag.

Docker and systemd. The environment variable is LLAMA_ARG_LOAD_MODE. It takes the same six values. A command-line flag wins over the variable. The old LLAMA_ARG_NO_MMAP and LLAMA_ARG_MLOCK variables belong to removed flags, so the server ignores them and gives no warning.

Compare Modes With llama-bench

llama-bench takes the same -lm flag, and it accepts a comma-separated list. One run measures several modes on the same model:

llama-bench -m model.gguf -lm mmap,none,mlock

llama-bench dropped its old -mmp flag in the same 2026 change. Use -lm none where you had -mmp 0.

See which card holds your model in VRAM: most load-mode tuning exists to work around weights that do not fit on the GPU.

Sources

All read on 2026-11-28 at llama.cpp commit 16f090f.

See Also

Was this guide useful?

Read next

llama.cpp MoE Cache Explained (2026): 2.2x on an RTX 5090
What --moe-cache-mib and --moe-cache-cpu-share do in llama.cpp, which builds have them, the measured speed-ups and slow-downs, and how the tuning script finds your numbers.
llama.cpp Flags Explained (2026): --no-mmap Is Now -lm none
Fix llama.cpp 'error: invalid argument: --no-mmap' (use -lm none) and every other removed flag. What -ngl, -lm, -fa, -c, -ub, the KV cache flags and the new -fit and --lazy-mode do, checked against v0.9.0.
llama.cpp --n-cpu-moe Explained: 35B MoE on a 12GB GPU
--n-cpu-moe keeps MoE expert weights in system RAM so a 35B MoE runs on a 12GB card. How to pick N for your VRAM, the other flags, and community tok/s.
Dual-Socket vs Single-Socket EPYC for LLM Inference: The Second CPU Pays 1.83x on a Dense Model and 1.02x on DeepSeek R1
Does a second CPU socket speed up local LLM inference? A controlled same-machine A/B says yes for dense models and almost not at all for DeepSeek R1. Here are the measured numbers, the NUMA fix that recovers 80%, and a correction to our own earlier page.