1. Memory Allocation Overhead
- Fragmentation: THP can lead to memory fragmentation. While it attempts to allocate large pages (typically 2MB), under memory pressure, it might fail and fall back to smaller pages, causing fragmentation.
- Inefficient Memory Usage: MySQL’s InnoDB engine manages its memory buffers (like the buffer pool) in chunks. THP's larger page sizes can lead to inefficient memory usage, where memory is allocated but not effectively utilized.
2. Jitter and Latency Issues
- Increased Swap Tendency: Systems with THP enabled are more prone to swap, even when there is available memory. Swapping can cause significant performance degradation for database systems.
- Performance Inconsistency: THP can cause unpredictable performance, especially in high-throughput, write-intensive workloads. This is often due to the way THP handles memory under different load conditions.
3. Interference with InnoDB’s Own Optimization
- Page Management: InnoDB is optimized for standard 4KB pages. THP, by changing the page size, can interfere with these optimizations, reducing the effectiveness of InnoDB’s internal mechanisms for memory management.
- CPU Overhead: Managing huge pages can incur additional CPU overhead, affecting the overall performance of the MySQL server.
4. Difficulty in Performance Tuning
- Tuning Complexity: THP adds another layer of complexity to the performance tuning of MySQL. Diagnosing issues caused by THP can be challenging, as its effects may not be immediately apparent.
- Inconsistent Behavior: The performance impact of THP can vary depending on the workload, making it difficult to create a consistent and reliable performance tuning strategy.
Disabling Transparent Huge PagesDue to these potential issues, it is often recommended to disable THP on servers running MySQL. This can be done by setting the
transparent_hugepage kernel parameter to
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
/etc/rc.local) to persist across reboots.