TECHNOLOGY

Use memory advice without claiming that weights are resident

In this article
THE QUICK TAKE

Treat memory advice according to its exact contract and verify host residency separately from model readiness.

A loader sends MADV_WILLNEED for mapped weights and immediately marks the model ready. Advice about future access is not a guarantee that every weight page is resident or that device preparation has finished. Define the required milestone before turning a successful advice call into a readiness claim.

Name the requested behavior

Record the exact advice value, mapped range and returned result. Conventional access hints and stronger population operations have different contracts. MADV_WILLNEED describes expected near-future use and possible read-ahead; it is not interchangeable with locking. Do not treat every madvise value as a harmless performance hint, because some documented operations change the mapping’s contents or allocation behavior.

Check the applicable mapping

Advice operates on page-aligned mapped ranges with documented restrictions. Verify the weight object’s identity, offset and permissions. A range error or unsupported mapping can fail before any useful preparation. Preserve errno rather than assuming a wrapper that issued the call also checked success. The requested length must describe the intended pages rather than an unrelated nearby buffer.

Observe residency honestly

A supported residency observation can describe pages at a point in time, subject to its access and interface limits. mincore explicitly provides a snapshot, not a future guarantee. Unlocked pages can change residency under pressure. A successful hint plus one warm observation therefore does not establish that later inference will avoid every file fault.

Separate host and device preparation

Host file-page availability does not show that tensors have been parsed, converted, transferred to the GPU or made ready for the engine’s execution path. Keep these milestones separate in startup telemetry. Otherwise a fast advice call can hide substantial downstream work and make a readiness signal arrive before the service can complete a valid request.

Compare the intended access path

In an isolated fixture, compare the same bounded mapped-file access with and without the chosen advice, retaining actual errors and preparation timings. Confirm the workload’s access order rather than assuming sequential reading. Acceptance supports a measured local preparation choice. It does not establish permanent residency, universal cold-start improvement or correctness of advice applied to a different mapping type and memory-pressure condition.

Primary references

Linux madvise.

Linux Residency Snapshot.

Linux mmap.

Related reading: OS page cache and cold model loading: what to record; First touch and NUMA: locating GPU host buffers.

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