Skip to content

feat(os): build transparent huge pages into the guest kernel, default madvise - #1503

Merged
kvinwang merged 1 commit into
nextfrom
feat/guest-thp
Oct 30, 2026
Merged

kvinwang merged 1 commit into
nextfrom
feat/guest-thp

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

Neither guest kernel has CONFIG_TRANSPARENT_HUGEPAGE, so all guest memory is mapped with 4 KiB pages. In a CVM each level of a guest page walk is itself translated through the secure EPT, so 4 KiB pages hurt workloads with a large hot working set.

This adds CONFIG_TRANSPARENT_HUGEPAGE=y with the sysfs default madvise to both backends, and asserts it in parity.json. Only regions marked MADV_HUGEPAGE get huge pages, so other workloads see no change. A workload that wants THP everywhere writes always to /sys/kernel/mm/transparent_hugepage/enabled at runtime. The measured kernel command line is unchanged.

Measured on a B200 TDX guest (host with 2 MiB secure-EPT mappings, guest 6.18.40 + THP):

  • Pointer chase, 4 KiB → 2 MiB guest pages: 112 → 81 ns at 256 MiB, 288 → 246 ns at 16 GiB.
  • Python/torch CPU microbenchmarks reached host speed.
  • SGLang moved its ~2.5 GiB of scheduler code onto MADV_HUGEPAGE memory, saving ~0.4 ms per decode step.

Testing:

  • make os-image (mkosi repro build) passes, including check-kernel-config.sh and the parity check.
  • The resolved .config has TRANSPARENT_HUGEPAGE=y and TRANSPARENT_HUGEPAGE_MADVISE=y.
  • Writing the sysfs file works from a privileged container; an unprivileged container is denied.

… madvise

Neither guest kernel has CONFIG_TRANSPARENT_HUGEPAGE, so every guest mapping
is backed by 4 KiB pages. In a CVM a TLB miss walks the guest page tables with
every level translated through the host's (secure) EPT, which makes 4 KiB
pages expensive for workloads with a large hot working set. On a B200 TDX
guest over 2 MiB EPT, guest 2 MiB pages took a pointer chase from 112 to 81 ns
(256 MiB) and from 288 to 246 ns (16 GiB), brought Python/torch CPU
microbenchmarks to bare-metal level, and let SGLang move its ~2.5 GiB of
scheduler code onto huge pages, saving ~0.4 ms per decode step.

The sysfs default is madvise: only regions marked MADV_HUGEPAGE get huge
pages, so workloads that do not ask see no change, and THP's memory bloat and
fault-time compaction stay opt-in. A workload that wants THP for everything
writes "always" to /sys/kernel/mm/transparent_hugepage/enabled at runtime
instead of adding transparent_hugepage= to the measured kernel command line.

Added to both backends and asserted in parity.json.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang merged commit 9c1a01e into next Oct 30, 2026
9 checks passed
@kvinwang
kvinwang deleted the feat/guest-thp branch October 30, 2026 00:35
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