TECHNOLOGY

MLOCK_ONFAULT: successful locking does not mean every page was populated

In this article
THE QUICK TAKE

MLOCK_ONFAULT marks nonresident pages for locking when faulted in; it does not establish a fully populated fault-free working set at the successful call boundary.

A lazy lock succeeds before the first workload

A local inference application changes its memory preparation to use MLOCK_ONFAULT and sees a successful call. Its startup report now claims that the complete working set is resident and future requests cannot fault. The flag does not establish that state. Identify which pages were present and which accesses the preparation path actually performed. A shorter-looking initialization path can move work into the first request rather than remove it; that is an experimental question, not a performance result supplied by the flag name.

The flag intentionally separates marking from population

The Linux memory-locking manual says MLOCK_ONFAULT locks currently resident pages and marks the remaining range so pages are locked when populated by a fault. That differs from the documented successful ordinary mlock residency condition. Preserve the exact API and flags with the result. Do not summarize both paths as all pages prefaulted. Nor should the deferred path be described as a failed lock simply because its design leaves future population work for the first relevant access.

Touch the relevant path under an explicit policy

If the application requires a prepared working set, define which supported accesses establish it for the target execution path. Loading a header or reading the first part of a model does not cover later workspaces and branches. Preserve allocation lifetimes and any subsequent mappings; preparation of an old buffer does not automatically cover its replacement. A prefault-style procedure still does not certify every source of latency, such as scheduling or another subsystem, and should not be presented as a universal real-time guarantee.

Observe faults with the right scope

The getrusage manual distinguishes minor faults serviced without I/O from major faults requiring I/O, and provides process or supported thread scope. Retain counter deltas over defined preparation and first-use intervals. A process-wide increase can include unrelated threads and mappings; it cannot by itself prove that the model range caused every fault. Likewise, absence of major faults does not mean absence of all faults. Keep the measurement boundary and competing activity explicit before drawing an attribution.

Propose a first-use and repeated-use fixture

Use a bounded harmless anonymous mapping under the supported locking configuration. Record the lazy-lock result, the preparation accesses and counter/timing observations during first and repeated consumption. Compare an explicitly prepared condition while holding the mapping and access pattern fixed. Reject any conclusion unsupported by actual observations. Acceptance requires a correct interpretation of deferred population, not a fabricated speedup. No memory was locked, limits changed or page-fault benchmark executed here; the fixture defines a way to investigate the chosen local runtime.

Keep residency, registration and placement separate

Linux locking versus CUDA registration establishes another API distinction. NUMA first-touch placement establishes another allocation condition. MLOCK_ONFAULT adds deferred population semantics to the record. Report flags, actual access coverage, fault scope and observed latency together. This makes a first-request stall investigable without asserting that every successful lock eagerly populates memory, that a fault implies storage I/O or that locking alone qualifies the complete inference path.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles