[PR #3980] [Engine] conversation buffer: advise 2 MiB huge pages on a fresh segment #4861

Open
opened 2026-11-07 16:30:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3980
Author: @wannagoxuf
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: feature/hugepage-fresh-segments


📝 Commits (1)

  • 8b0bb4b conversation buffer: advise 2 MiB huge pages on a fresh segment

📊 Changes

1 file changed (+20 additions, -0 deletions)

View changed files

📝 include/strata/core/conversation_buffer.hpp (+20 -0)

📄 Description

Problem and result: the host buffer that the layer split's copies travel through - the ConversationBuffer in include/strata/core/conversation_buffer.hpp - is a std::vector<uint8_t> of 16 MiB segments that are allocated fresh every turn and freed at the end of it. A fresh segment is a fresh mmap, and on a host with THP=madvise (the usual Linux default) glibc's segments never get 2 MiB pages on their own, so every page faults as 4 KiB. A device copy into such a segment therefore pays a page fault plus a per-page driver pin for the pages it drops right after, and the copy runs at 2.3 GB/s instead of the 21 GB/s the link does.

Measured on one RTX 4090, device to host, 2 MiB pages: warm pageable 21.3 GB/s, fresh 2.28, fresh with a pre-touch 22.3, fresh with MADV_HUGEPAGE 11.5, pinned 26.1. The host round trip of the slot shuttle is the path that pays it, because the buffer is freed at the end of every turn, so the next turn copies into pages the kernel has never seen.

With the advice, the fresh capture of a ~110K-token conversation costs 164 ms per 100K tokens instead of 261 ms (medians, same box, same workload, the same binary with the change off as the baseline) and the slot shuttle's p90 falls from 285 ms to 142 ms per 100K tokens.

Related discussion: #3321 (the layer split's copy path - the root cause and the measurements behind this change are in the thread).

Approach: after a fresh segment's storage is reserved, advise the 2 MiB-aligned middle of the reservation with MADV_HUGEPAGE. The ragged head and tail stay 4 KiB, which is what the kernel would give them anyway. The advice is placed before the segment is resized, so the zero fill of the fresh pages takes the huge pages too.

Nothing about the copy changes: the same bytes move through the same paths, only the page size of the destination changes. Eviction is untouched - a huge page is an ordinary anonymous page and munmap returns it.

Validation:

Passed:

  • Build: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=89 -DGGML_LLAMAFILE=OFF -DSTRATA_BUILD_TESTS=ON -DSTRATA_ENABLE_CUDA=ON + cmake --build . -j 40 (CUDA 12.8, driver 580.178.04, 4x RTX 4090).

  • ctest -j 4: no new failure. The build of the unmodified main and the build of this branch fail the same tests for the same reasons (the test data is not in the tree: the Q2_0 GGUF and pack/full/experts.bin; plus platform_memory_test, which wants a higher ulimit -l, and isa_guard_check).

  • Before/after, same box, same workload, one variable: Qwen3.8-flash IQ3_XXS, 4-way layer split 13,26,38, --batch 4, --kv k8v4 --kv-resident 524288, --conversation-cache-mib 393216 --conversation-cache-slots 192, 9 concurrent clients x 3 rounds of ~110K-token conversations. Per 100K tokens (n, median, mean, p90, max):

    | capture into the cache (fresh) | n=36 | 261 | 255 | 276 | 307 ms | -> | n=38 | 164 | 147 | 176 | 182 ms |
    | capture into the cache (K/V reused) | n=17 | 136 | 130 | 150 | 156 ms | -> | n=15 | 132 | 120 | 141 | 144 ms |
    | slot shuttle | n=64 | 64 | 101 | 285 | 329 ms | -> | n=64 | 63 | 80 | 142 | 193 ms |

    The fresh capture is 1.6x faster and the slot shuttle's tail halves (p90 285 -> 142 ms). The reused capture barely moves, as it should: it copies into pages the kernel already knows.

Failed: none observed.

Not run: the HIP and SYCL builds - no AMD or Intel toolchain on this machine. The change is two lines of POSIX (madvise under #if !defined(_WIN32)), but those two backends are not compiled here; a build of them would be welcome before the review.

Limits: the advice is a hint - the kernel may refuse it (under memory pressure, or with defrag set so that the allocation is not retried), and the copy then runs at the pageable speed as before. The measure only applies to a segment that is fresh; a reused segment already holds its pages. A machine with THP=always does not need the advice - the pages are already huge - so the change is a no-op there.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3980 **Author:** [@wannagoxuf](https://github.com/wannagoxuf) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/hugepage-fresh-segments` --- ### 📝 Commits (1) - [`8b0bb4b`](https://github.com/Niko1221/Strata/commit/8b0bb4b98b60173d617490af07775e941627b6d7) conversation buffer: advise 2 MiB huge pages on a fresh segment ### 📊 Changes **1 file changed** (+20 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_buffer.hpp` (+20 -0) </details> ### 📄 Description Problem and result: the host buffer that the layer split's copies travel through - the `ConversationBuffer` in `include/strata/core/conversation_buffer.hpp` - is a `std::vector<uint8_t>` of 16 MiB segments that are allocated fresh every turn and freed at the end of it. A fresh segment is a fresh mmap, and on a host with `THP=madvise` (the usual Linux default) glibc's segments never get 2 MiB pages on their own, so every page faults as 4 KiB. A device copy into such a segment therefore pays a page fault plus a per-page driver pin for the pages it drops right after, and the copy runs at 2.3 GB/s instead of the 21 GB/s the link does. Measured on one RTX 4090, device to host, 2 MiB pages: warm pageable 21.3 GB/s, fresh 2.28, fresh with a pre-touch 22.3, fresh with `MADV_HUGEPAGE` 11.5, pinned 26.1. The host round trip of the slot shuttle is the path that pays it, because the buffer is freed at the end of every turn, so the next turn copies into pages the kernel has never seen. With the advice, the fresh capture of a ~110K-token conversation costs 164 ms per 100K tokens instead of 261 ms (medians, same box, same workload, the same binary with the change off as the baseline) and the slot shuttle's p90 falls from 285 ms to 142 ms per 100K tokens. Related discussion: #3321 (the layer split's copy path - the root cause and the measurements behind this change are in the thread). Approach: after a fresh segment's storage is reserved, advise the 2 MiB-aligned middle of the reservation with `MADV_HUGEPAGE`. The ragged head and tail stay 4 KiB, which is what the kernel would give them anyway. The advice is placed before the segment is resized, so the zero fill of the fresh pages takes the huge pages too. Nothing about the copy changes: the same bytes move through the same paths, only the page size of the destination changes. Eviction is untouched - a huge page is an ordinary anonymous page and `munmap` returns it. Validation: Passed: - Build: `cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=89 -DGGML_LLAMAFILE=OFF -DSTRATA_BUILD_TESTS=ON -DSTRATA_ENABLE_CUDA=ON` + `cmake --build . -j 40` (CUDA 12.8, driver 580.178.04, 4x RTX 4090). - `ctest -j 4`: no new failure. The build of the unmodified main and the build of this branch fail the same tests for the same reasons (the test data is not in the tree: the Q2_0 GGUF and `pack/full/experts.bin`; plus `platform_memory_test`, which wants a higher `ulimit -l`, and `isa_guard_check`). - Before/after, same box, same workload, one variable: Qwen3.8-flash IQ3_XXS, 4-way layer split `13,26,38`, `--batch 4`, `--kv k8v4 --kv-resident 524288`, `--conversation-cache-mib 393216 --conversation-cache-slots 192`, 9 concurrent clients x 3 rounds of ~110K-token conversations. Per 100K tokens (n, median, mean, p90, max): | capture into the cache (fresh) | n=36 | 261 | 255 | 276 | 307 ms | -> | n=38 | 164 | 147 | 176 | 182 ms | | capture into the cache (K/V reused) | n=17 | 136 | 130 | 150 | 156 ms | -> | n=15 | 132 | 120 | 141 | 144 ms | | slot shuttle | n=64 | 64 | 101 | 285 | 329 ms | -> | n=64 | 63 | 80 | 142 | 193 ms | The fresh capture is 1.6x faster and the slot shuttle's tail halves (p90 285 -> 142 ms). The reused capture barely moves, as it should: it copies into pages the kernel already knows. Failed: none observed. Not run: the HIP and SYCL builds - no AMD or Intel toolchain on this machine. The change is two lines of POSIX (`madvise` under `#if !defined(_WIN32)`), but those two backends are not compiled here; a build of them would be welcome before the review. Limits: the advice is a hint - the kernel may refuse it (under memory pressure, or with `defrag` set so that the allocation is not retried), and the copy then runs at the pageable speed as before. The measure only applies to a segment that is fresh; a reused segment already holds its pages. A machine with `THP=always` does not need the advice - the pages are already huge - so the change is a no-op there. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4861
No description provided.