Skip to content

llama-mmap: don't use MAP_POPULATE on Linux - #28055

Open
Nekotekina wants to merge 1 commit into
ggml-org:masterfrom
Nekotekina:master
Open

llama-mmap: don't use MAP_POPULATE on Linux#28055
Nekotekina wants to merge 1 commit into
ggml-org:masterfrom
Nekotekina:master

Conversation

@Nekotekina

@Nekotekina Nekotekina commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

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

@Nekotekina

Nekotekina commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Oops, referenced wrong commit. Now I'm looking stupid again.
#801 original juggernaut PR
Since it's very big and ubiquitous it's unlikely that one particular small part received proper scrutiny.

@Nekotekina

Nekotekina commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Another old PR (unmerged) discusses MAP_POPULATE:
#740
Author uses macOS, Linux is afterthought.
#740 (comment)
It says that MAP_POPULATE actually degraded the loading speed on desktop. But nevertheless it got propagated into another PR by another contributor who probably never tested it. Nothing definitive in the comments.

@Nekotekina

Nekotekina commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

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.

@Nekotekina

Copy link
Copy Markdown
Contributor Author

@ngxson pinging because you recently modified that code in #27794

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant