Performance Tuning & Kernel Parameters (Sysctl)
Boosting Memory Efficiency with Transparent Huge Pages Defragmentation
🧩 The Challenge
Applications with high memory churn often experience latency spikes when the kernel struggles to allocate contiguous memory blocks. The default background defragmentation behavior can cause significant CPU overhead and stalled processes.
💡 The Fix
Modify the kernel tunable to force the transparent huge page mechanism to only perform defragmentation when necessary or disable it entirely to prioritize latency over minor memory gains.
sysctl -w vm.transparent_hugepage_defrag=madvise
⚙️ Why It Works
Setting the value to madvise ensures that the kernel only attempts to defragment memory regions explicitly requested by an application, preventing unpredictable system-wide performance degradation.
🚀 Pro-Tip: Use echo never > /sys/kernel/mm/transparent_hugepage/enabled to completely disable THP if you are running a database workload sensitive to page compaction stalls.
Linux Tips & Tricks | © ngelinux.com | 7/6/2026
