llama-mmap: don't use MAP_POPULATE on Linux - #28055
Conversation
|
Oops, referenced wrong commit. Now I'm looking stupid again. |
|
Another old PR (unmerged) discusses MAP_POPULATE: |
|
There are many ways to enforce prefetch as aggressive as possible without MAP_POPULATE. But it's practically impossible to disable it on Linux. The more I look at it, the more I'm sure it doesn't even need an option to control, it's simply harmful. For example, blocking mmap intuitively suggests that it blocks everything else: stalls CPU, delays GPU initialization. |
Unlike other hints, it's a blocking call that forces everything to load immediately. Other platforms supposedly don't behave like this. Originally added in 3d9a551 and unchanged/unchallenged (no reason to use it found).
Unlike other hints, it's a blocking call that forces everything to load immediately.
Other platforms supposedly don't behave like this.
Originally added in f963b63 and unchanged/unchallenged (no reason to use it found).
Overview
This flag causes troubles on Linux specifically.
Just an example: may need to load a huge model while using mmap, for one reason or another. Any attempt to do it will start with pointless but very long step of reading all weights at startup (and subsequently paging them out by OS). There seems to be no proper way to disable this behaviour gracefully, every option is not directly related to this.
Additional information
According to what I found, PrefetchVirtualMemory on Windows is a non-blocking hint too, just like madvise calls on POSIX path. MAP_POPULATE blocks each mmap call which can even be less efficient than async loading. It can also cause memory pressure detection mechanism to crash user session when model size is big enough (but not necessarily exceeding RAM).
Requirements