Operations 9 min read

Optimizing Linux Memory: When to Use Huge Pages and How to Disable THP

This guide explains the difference between standard Huge Pages and Transparent Huge Pages in Linux, outlines the performance benefits and drawbacks of using Huge Pages, and provides step‑by‑step commands and GRUB configuration methods to safely disable Transparent Huge Pages on CentOS systems.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Optimizing Linux Memory: When to Use Huge Pages and How to Disable THP

Huge Pages vs. Transparent Huge Pages

Linux supports two types of large memory pages: Huge Pages (standard large pages) and Transparent Huge Pages (THP) . Standard pages are pre‑allocated 2 MiB or 1 GiB blocks, while THP are created dynamically by the kernel.

Why Use Huge Pages?

Larger page size reduces the number of page table entries, improves TLB hit rates, lowers memory‑operation overhead, reduces kernel memory usage for page tables, eliminates swapping of those pages, and avoids kswapd activity.

Drawbacks and Compatibility

Enabling Huge Pages requires manual configuration and conflicts with Oracle 11g’s Automatic Memory Management (AMM), though Automatic Shared Memory Management (ASMM) still works. Transparent Huge Pages simplify usage but can cause instability in RAC clusters and performance issues on single‑node systems, especially for database workloads.

Disabling Transparent Huge Pages

Two methods are provided for CentOS 7.8:

Method 1 – Temporary Runtime Change

# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo never > /sys/kernel/mm/transparent_hugepage/defrag

Setting the files to never disables THP until the next reboot.

Method 2 – Persistent GRUB Configuration

Backup the current GRUB configuration:

# cp /etc/default/grub /etc/default/grub.$(date +%F).bak
# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.$(date +%F).bak

Edit /etc/default/grub (or /etc/sysconfig/grub) and append transparent_hugepage=never to GRUB_CMDLINE_LINUX:

GRUB_CMDLINE_LINUX="... transparent_hugepage=never"

Regenerate the GRUB configuration and reboot:

# grub2-mkconfig -o /boot/grub2/grub.cfg
# init 6

Verification

After reboot, confirm the settings:

# cat /sys/kernel/mm/transparent_hugepage/enabled
# cat /proc/meminfo | grep -i huge

The output should show [never] for the enabled file and zero values for AnonHugePages and HugePages_Total, indicating THP is disabled.

Monitoring THP Activity

Relevant runtime parameters can be inspected under /sys/kernel/mm/transparent_hugepage/, such as khugepaged/pages_to_scan, khugepaged/scan_sleep_millisecs, and khugepaged/alloc_sleep_millisecs, which control scanning frequency and defragmentation behavior.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxMemoryManagementhugepagesTransparentHugePages
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.