llama-mmap: hint THP on mmap'd weights (Linux)#19
Open
Marxist-Leninist wants to merge 3 commits intoPrismML-Eng:masterfrom
Open
llama-mmap: hint THP on mmap'd weights (Linux)#19Marxist-Leninist wants to merge 3 commits intoPrismML-Eng:masterfrom
Marxist-Leninist wants to merge 3 commits intoPrismML-Eng:masterfrom
Conversation
Author
|
Heads-up: the failing The PrismML-Eng labeler workflow ( server/webui:
- changed-files:
- all:
- any-glob-to-any-file:
- tools/server/webui/**
server/webui:
- changed-files:
- any-glob-to-any-file:
- tools/server/webui/**Happy to open either fix as a separate PR if you'd like. |
d74dd9b to
a4ce593
Compare
Issue madvise(MADV_HUGEPAGE) on the read-only file mapping used for model weights on Linux. For a 1 GB model this drops the potential page count from ~262K 4KB pages to ~512 2MB pages, reducing TLB pressure and (more importantly) reducing the number of re-faults when pages get evicted under memory pressure. No-op on kernels where THP is disabled. On 'madvise' mode (the common modern default for desktop distros), this is opt-in and requires the caller to ask. Guarded by defined(MADV_HUGEPAGE) so it compiles cleanly on non-Linux. Benchmark on a Skylake-SP VM, Bonsai-8B Q1_0, -fa on -ctk q8_0 -ctv q8_0 -t 12 -ub 128: neutral on this machine (~9.5 t/s tg128 both before and after) because the VM isn't memory-constrained. The change is intended for systems where the mapping does get evicted and re-faulted under pressure.
a4ce593 to
036a707
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
madvise(MADV_HUGEPAGE)on the read-only file mapping used for model weights on Linux. For a 1 GB model this drops the potential page count from ~262K 4KB pages to ~512 2MB pages, reducing TLB pressure and (more importantly) reducing the number of re-faults when pages get evicted under memory pressure.Linux-only, guarded by
defined(MADV_HUGEPAGE)and__linux__. Skipped whennumais set. No-op where THP is disabled.Bench on a Skylake-SP VM, Bonsai-8B Q1_0,
-fa on -ctk q8_0 -ctv q8_0 -t 12 -ub 128: neutral (~9.5 t/s tg128 both before and after) because the VM isn't memory-constrained. The change is intended for systems where the mapping does get evicted under pressure (constrained laptops, containers).Tried the same hint on
ggml_aligned_mallocfor KV/activation buffers as well — that showed a ~5% regression with no visible AnonHugePages, dropped that half.