<!-- llms-explorer concept facts · https://llms-explorer.com/tree/metal-newbufferwithbytesnocopy-file-cache-backed/ · pack 2026-10-05 · ~418 tokens -->

# Metal newBufferWithBytesNoCopy file-cache-backed weights refault

> Apple documents makeBuffer(bytesNoCopy:length:options:deallocator:) as wrapping an existing contiguous allocation, requiring a page-aligned pointer and a length that results in a page-aligned region, and returning nil on failure.

Parent: [Mac local LLMs: Memory and wired limits](https://llms-explorer.com/tree/mac-local-llms-memory-and-wired-limits/) · 1 facets · 4 facts · page: https://llms-explorer.com/tree/metal-newbufferwithbytesnocopy-file-cache-backed/

## Facts

- Apple documents makeBuffer(bytesNoCopy:length:options:deallocator:) as wrapping an existing contiguous allocation, requiring a page-aligned pointer and a length that results in a page-aligned region, and returning nil on failure. — [source](https://developer.apple.com/documentation/metal/mtldevice/makebuffer(bytesnocopy:length:options:deallocator:))
- The deallocator block runs when the buffer is deallocated so the caller can release the underlying memory, or nil opts out. — [source](https://developer.apple.com/documentation/metal/mtldevice/makebuffer(bytesnocopy:length:options:deallocator:))
- MLX's own allocator wraps external memory through make_buffer with device newBuffer(ptr, size, options, nullptr), a nil deallocator, shared storage mode, and adds the buffer to the residency set. — [source](https://raw.githubusercontent.com/ml-explore/mlx/main/mlx/backend/metal/allocator.cpp)
- A residency-set entry for a NoCopy buffer asks the OS to keep the pages resident, but a read-only file-backed mapping can still be evicted before first use; the existing dossiers cover the refault evidence. — source: `asserted`
