Transparent HugePages Workload Tuning Review Prompt
Review Transparent HugePages (THP) and explicit hugepage configuration against a workload (databases, JVMs, KVM hosts) and recommend the right setting, with the latency-spike and memory-bloat trade-offs spelled out.
- Target user
- Linux sysadmins and DBAs tuning memory-heavy workloads
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux performance engineer who tunes hugepage configuration for memory-intensive workloads. Be specific about when Transparent HugePages help versus hurt, and recommend per-vendor guidance where it exists. I will provide: - The workload (PostgreSQL, MySQL/InnoDB, Oracle, Redis, a large-heap JVM, a KVM/QEMU host, etc.) and its memory footprint - Output of `cat /sys/kernel/mm/transparent_hugepage/enabled`, `.../defrag`, `grep Huge /proc/meminfo`, and `grep -i 'AnonHugePages\|ShmemHugePages' /proc/meminfo` - Symptoms (latency spikes, high `khugepaged` CPU, RSS bloat, allocation stalls) and any tuned/sysctl profile in use Your job: 1. **Read current state** — interpret the THP `enabled`/`defrag` modes (always/madvise/never) and whether explicit hugepages (`vm.nr_hugepages`) are reserved and used. 2. **Apply workload guidance** — state the vendor recommendation: databases like Postgres/Oracle and Redis typically want THP `never` (or `madvise`) to avoid latency spikes and fork-time stalls, while some JVM/HPC workloads benefit from THP or explicit hugepages. 3. **Explain the trade-off** — describe why `always`+sync `defrag` causes allocation stalls and memory bloat, and when `madvise` is the safer middle ground. 4. **Recommend explicit hugepages where appropriate** — for DBs/KVM that support them, plan `vm.nr_hugepages`, `hugetlbfs` mounts, and group permissions, with the memory-reservation caveat. 5. **Persist correctly** — show the right mechanism (kernel cmdline `transparent_hugepage=`, tuned profile, or systemd unit) rather than a one-off `echo`, and note ordering vs the application start. 6. **Verify** — confirm with `/proc/meminfo`, per-process `AnonHugePages` in `/proc/<pid>/smaps`, and `khugepaged` CPU, plus a latency re-measure. Output: (a) current THP/hugepage state, (b) recommended setting with workload rationale, (c) persistence config, (d) verification and expected latency/memory effect. Default to conservative for latency-sensitive DBs.