Guard KV cache against page-cache pressure#134
Open
Ghatage wants to merge 1 commit into
Open
Conversation
The disk KV cache uses plain read/write to avoid mapping more VM into a process that already maps a large GGUF, but the bytes still land in the Linux page cache where they compete with the mmapped weights for resident memory. A 30k-token cold save leaves hundreds of MiB sitting in Cached: after the save returns, exactly the RAM pressure the no-mmap decision was meant to avoid. Hint the kernel to invalidate those pages with posix_fadvise(POSIX_FADV_DONTNEED) right after each full payload write and read. Header-only scans are deliberately untouched, since repeated small header reads still benefit from page-cache reuse. Expose DS4_KV_KEEP_PAGES=1 as an escape hatch for diagnostic comparisons, mirroring the existing cuda_model_drop_file_pages and its DS4_CUDA_KEEP_MODEL_PAGES toggle. Correctness: make test; ./ds4_test --server. Two new mincore-based tests assert that resident pages of a 4 MiB temp file drop from ~all to under 25% after the hint, and that DS4_KV_KEEP_PAGES=1 keeps them in place.
Owner
|
Like this. Will take care. |
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.
The disk KV cache uses plain read/write to avoid mapping more VM into a process that already maps a large GGUF, but the bytes still land in the Linux page cache where they compete with the mmapped weights for resident memory. A 30k-token cold save leaves hundreds of MiB sitting in Cached: after the save returns, exactly the RAM pressure the no-mmap decision was meant to avoid.
Hint the kernel to invalidate those pages with
posix_fadvise(POSIX_FADV_DONTNEED) right after each full payload write and read. Header-only scans are deliberately untouched, since repeated small header reads still benefit from page-cache reuse. Expose DS4_KV_KEEP_PAGES=1 as an escape hatch for diagnostic comparisons, mirroring the existing cuda_model_drop_file_pages and its DS4_CUDA_KEEP_MODEL_PAGES toggle.
Correctness: make test; ./ds4_test --server.
Two new mincore-based tests assert that resident pages of a 4 MiB temp file drop from ~all to under 25% after the hint, and that DS4_KV_KEEP_PAGES=1 keeps them in place.