Memory Mapping's Instant Load & Half RAM Advantage
`llama.cpp` leverages memory mapping (mmap) to load large language models almost instantaneously from disk, significantly reducing RAM usage by only loading necessary parts of the model as needed, which allows models that would otherwise be too large to fit in physical memory.
The top 3
- Shared Memory: Doubling Model Capacity: Memory mapping in llama.cpp enables multiple processes to share the same read-only model weights in physical memory (using `MAP_SHARED`), effectively reducing total RAM usage. This allows users to load models up to twice as large as before without compromising system stability.
- Instant Load: 100x Faster Model Access: By directly mapping model files into virtual memory, llama.cpp bypasses traditional file I/O operations, making models available almost instantly without a full data transfer. This optimization led to up to a 100x speed improvement in load times for Linux users and 10x for Windows/macOS.
- On-Demand Paging: Minimal RAM Footprint: Memory mapping allows the operating system to treat the model file on disk as if it were already in memory, fetching only the necessary parts into physical RAM as computations demand them. This 'memory-on-demand' approach significantly reduces the actual resident memory footprint compared to loading the entire model upfront.
Sources
Open the full topic