OS-Level Magic: How mmap Enables Shared Memory and On-Demand Paging

At its core, `mmap()` is an operating system system call that maps a file's content directly into a process's virtual address space. This allows for 'demand paging,' where only the necessary parts of the model are loaded into physical RAM as they are accessed, rather than the entire file upfront. Crucially, the `MAP_SHARED` flag facilitates inter-process communication by allowing multiple applications to share the same physical memory pages of the model file, optimizing resource use for local LLM inference.

Sources

Open the full topic