Transparent Huge Pages (THP) is an abstraction layer in the Linux kernel designed to automate the creation, management, and use of huge memory pages (typically 2MB instead of the standard 4KB). While THP can improve performance for general-purpose computing by reducing the Translation Lookaside Buffer (TLB) footprint, it is notoriously problematic for enterprise database systems. High-performance databases like Redis, MongoDB, and Oracle manage memory highly efficiently on their own; introducing THP often leads to memory bloat, latency spikes, and severe system degradation during heavy write operations.
This guide explains how to completely disable Transparent Huge Pages on an Ubuntu Server to guarantee stable performance for demanding database workloads.
Disable THP at Runtime
You can temporarily disable the THP daemon while the server is running. This is useful for testing database performance before making permanent changes.
- Connect to your Ubuntu server via SSH and open a terminal.
- Execute the following command to explicitly disable THP (requires root privileges):
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled - Next, disable the THP defragmentation daemon to prevent memory compaction overhead:
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag - Verify that the changes have taken effect by checking the status. The word
[never]should be enclosed in brackets in the output:cat /sys/kernel/mm/transparent_hugepage/enabled
Note that changes made via the /sys filesystem are ephemeral and will revert to their default state upon system reboot.
Disable THP Permanently via GRUB Bootloader
To ensure THP remains completely disabled across reboots—which is critical for production database environments—you must append kernel parameters to the GRUB configuration file.
- Open the GRUB configuration file using a text editor such as
nano:sudo nano /etc/default/grub - Locate the line beginning with
GRUB_CMDLINE_LINUX_DEFAULT. - Append the parameters
transparent_hugepage=neverto the end of the existing string, inside the quotation marks. For example:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash transparent_hugepage=never" - Save the file and exit the text editor (in
nano, press Ctrl+O, Enter, then Ctrl+X). - Update the GRUB bootloader to apply the new kernel parameters:
sudo update-grub - Reboot the server for the permanent changes to take effect:
sudo reboot
Upon reboot, the Linux kernel will strictly refuse to allocate transparent huge pages, ensuring your database engine has exclusive, uninhibited control over its memory management architecture.