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
Bottom Line (2026)
- Six modes, one flag.
-lm, --load-modetakesauto,none,mmap,mlock,mmap+mlockordio. The default isauto, which means mmap unless a device does not support it. -lm mlockdoes not use mmap. It reads the weights into ordinary buffers and locks them in RAM.-lm mmap+mlockis 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 --mlockpair has an exact replacement:-lm mlock. The old--mlockon 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-moeor-ot ...=CPU. llama.cpp prints a warning that tells you to use--load-mode nonein that case. - Keep the default on a model that fits in VRAM. mmap loads faster, and
--lazy-modereads 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
| Mode | Uses mmap | Locks in RAM | What it is for |
|---|---|---|---|
auto (default) | Yes, unless a device has no mmap support | No | Most setups |
none | No | No | CPU offload of MoE experts or layers |
mmap | Yes | No | The same as auto on a device that supports mmap |
mlock | No | Yes | CPU offload on a machine that swaps under load |
mmap+mlock | Yes | Yes | A model you run from RAM and never want paged out |
dio | No | No | DirectIO 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 line | What it did | Write this instead |
|---|---|---|
| (no flag) | mmap | Nothing. auto is the default |
--no-mmap | Read into ordinary buffers | -lm none |
--mlock | mmap, then lock | -lm mmap+mlock |
--no-mmap --mlock | Read into ordinary buffers, then lock | -lm mlock |
--mmap | mmap | -lm mmap, or delete it |
--direct-io | DirectIO | -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.
- Pinned memory uploads faster. The llama.cpp MoE cache docs say: “The host experts are pinned with
-lm none,-lm mlockand-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.” - Fewer pageouts. The
mmaphelp 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,autofalls back tooffwhen mmap is not in use.- Devices without mmap. You do not need to set anything.
autochecks 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.
common/arg.cpp: the-lmand-lzmhelp text and accepted values.src/llama-model-loader.cpp: which modes use mmap, and the tensor-override warning.src/llama-model.cpp: which modes lock memory, theautofallback, and theload_mode =log line.src/llama-mmap.cpp: the mlock warning and its hints.- Server README: the
LLAMA_ARG_LOAD_MODEvalues and precedence. docs/moe-cache.md: which modes pin host experts.- History: PR #20834 (merged 2026-07-23), issue #26110 (closed 2026-07-27), PR #26135 (merged 2026-07-27, first release b10145).
See Also
- llama.cpp Flags Explained: every other flag, and the fix for each
error: invalid argument - llama.cpp MoE Offload Flags Explained:
--n-cpu-moesweeps, where-lm nonematters most - llama.cpp MoE Cache Explained: the GPU cache for experts in system RAM, and why pinned memory changes its numbers
- AMD ROCm Setup for Local LLMs: the Strix Halo
-lm noneguidance