§ 014 · Linux

How to Permanently Disable Transparent Huge Pages (THP) on Ubuntu 22.04

Disabling Transparent Huge Pages (THP) permanently on Ubuntu 22.04 requires editing system configuration files to apply the change at boot time. There are a few methods to achieve this, but one common approach is to use rc.local or a custom systemd service since Ubuntu may not have rc.local enabled by default in newer versions. Here, I’ll show you how to create a systemd service to disable THP.

Step 1: Create a systemd Service File

  1. Use your favorite text editor to create a new systemd service file. Here, we’ll use vi:
  2. Add the following content to the file:
  3. Save and close the file.

Step 2: Reload Systemd and Enable the Service

After creating the service file, you need to reload the systemd manager configuration, enable the service to start at boot, and then start the service immediately to apply the change without rebooting.

Execute the following commands in the terminal:

Step 3: Verify the Changes

To verify that Transparent Huge Pages have been disabled, you can use the cat command to check the current settings:

Both commands should output never, indicating that Transparent Huge Pages are disabled.

Conclusion

By following these steps, you’ve created a systemd service to disable Transparent Huge Pages permanently on Ubuntu 22.04. This change will persist across reboots, ensuring that THP is disabled each time the system starts. This method is preferred for systems where THP may interfere with the performance of certain applications, especially databases like MongoDB, Redis, etc., that recommend disabling THP for better performance and efficiency.

Written by

Vinicius Grippa

Writes this blog. Mostly about databases. Boring on purpose.

More about me →

The floor is yours.

0 comments · Moderated · civil & on-topic

First comment appears here once approved. Questions, corrections, and counterpoints welcome — just no self-promotion.

Add a comment

Your email address is never published. * required

Subscribe · Posted when ready

A quiet, technical email about databases.

One post per send, corrections when I’m wrong, nothing else. No social-media cross-posts. No “what we learned.”

Unsubscribe with any reply