11.6. Managing transparent huge pages


Transparent huge pages (THP) are enabled by default in Red Hat Enterprise Linux 10. However, you can enable, disable, or set the transparent huge pages to madvise with runtime configuration, TuneD profiles, kernel command line parameters, or systemd unit file.

Transparent huge pages (THP) can be managed at runtime to optimize memory usage. The runtime configuration is not persistent across system reboots.

Procedure

  1. Check the status of THP:

    $ cat /sys/kernel/mm/transparent_hugepage/enabled
  2. Configure THP.

    • Enabling THP:

      $ echo always > /sys/kernel/mm/transparent_hugepage/enabled
    • Disabling THP:

      $ echo never > /sys/kernel/mm/transparent_hugepage/enabled
    • Setting THP to madvise:

      $ echo madvise > /sys/kernel/mm/transparent_hugepage/enabled

      To prevent applications from allocating more memory resources than necessary, disable the system-wide transparent huge pages and only enable them for the applications that explicitly request it through the madvise system call.

      注意

      Sometimes, providing low latency to short-lived allocations has higher priority than immediately achieving the best performance with long-lived allocations. In such cases, you can disable direct compaction while leaving THP enabled.

      Direct compaction is a synchronous memory compaction during the huge page allocation. Disabling direct compaction provides no guarantee of saving memory, but can decrease the risk of higher latencies during frequent page faults. Also, disabling direct compaction allows synchronous compaction of Virtual Memory Areas (VMAs) highlighted in madvise only. Note that if the workload benefits significantly from THP, the performance decreases. Disable direct compaction:

      $ echo never > /sys/kernel/mm/transparent_hugepage/defrag

      See the madvise(2) man page on your system for more information.

11.6.2. Managing transparent huge pages with TuneD profiles

You can manage transparent huge pages (THP) by using TuneD profiles. The tuned.conf file provides the configuration of TuneD profiles. This configuration is persistent across system reboots.

Prerequisites

  • TuneD package is installed.
  • TuneD service is enabled.

Procedure

  1. Copy the active profile file to the same directory:

    $ sudo cp -R /usr/lib/tuned/my_profile /usr/lib/tuned/my_copied_profile
  2. Edit the tune.conf file:

    $ sudo vi /usr/lib/tuned/my_copied_profile/tuned.conf
    • To enable THP, add the line:

      [bootloader]
      
      cmdline = transparent_hugepage=always
    • To disable THP, add the line:

      [bootloader]
      
      cmdline = transparent_hugepage=never
    • To set THP to madvise, add the line:

      [bootloader]
      
      cmdline = transparent_hugepage=madvise
  3. Restart the TuneD service:

    $ sudo systemctl restart tuned
  4. Set the new profile active:

    $ sudo tuned-adm profile my_copied_profile

Verification

  1. Verify that the new profile is active:

    $ sudo tuned-adm active
  2. Verify that the required mode of THP is set:

    $ cat /sys/kernel/mm/transparent_hugepage/enabled

You can manage transparent huge pages (THP) at boot time by modifying kernel parameters. This configuration is persistent across system reboots.

Prerequisites

  • You have root permissions on the system.

Procedure

  1. Get the current kernel command line parameters:

    # grubby --info=$(grubby --default-kernel)
    kernel="/boot/vmlinuz-6.12.X-XXX.XX.X.el10_0.x86_64"
    args="ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX console=tty0 console=ttyS0"
    root="UUID=XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    initrd="/boot/initramfs-6.12.X-XXX.XX.X.el10_0.x86_64.img"
    title="Red Hat Enterprise Linux (6.12.X-XXX.XX.X.el10_0.x86_64) 10.0"
    id="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-6.12.X-XXX.XX.X.el10_0.x86_64"
  2. Configure THP by adding kernel parameters.

    • To enable THP:

      # grubby --args="transparent_hugepage=always" --update-kernel=DEFAULT
    • To disable THP:

      # grubby --args="transparent_hugepage=never" --update-kernel=DEFAULT
    • To set THP to madvise:

      # grubby --args="transparent_hugepage=madvise" --update-kernel=DEFAULT
  3. Reboot the system for changes to take effect:

    # reboot

Verification

  • To verify the status of THP, view the following files:

    # cat /sys/kernel/mm/transparent_hugepage/enabled
    always madvise [never]
    # grep AnonHugePages: /proc/meminfo
    AnonHugePages:         0 kB
    # grep nr_anon_transparent_hugepages /proc/vmstat
    nr_anon_transparent_hugepages 0

You can manage transparent huge pages (THP) at system startup by using systemd unit files. By creating a systemd service, you get consistent THP configuration across system reboots.

Prerequisites

  • You have root permissions on the system.

Procedure

  1. Create new systemd service files for enabling, disabling and setting THP to madvise. For example, /etc/systemd/system/disable-thp.service.
  2. Configure THP by adding the following contents to a new systemd service file.

    • To enable THP, add the following content to <new_thp_file>.service file:

      [Unit]
      Description=Enable Transparent Hugepages
      After=local-fs.target
      Before=sysinit.target
      
      [Service]
      Type=oneshot
      RemainAfterExit=yes
      ExecStart=/bin/sh -c 'echo always > /sys/kernel/mm/transparent_hugepage/enabled
      
      [Install]
      WantedBy=multi-user.target
    • To disable THP, add the following content to <new_thp_file>.service file:

      [Unit]
      Description=Disable Transparent Hugepages
      After=local-fs.target
      Before=sysinit.target
      
      [Service]
      Type=oneshot
      RemainAfterExit=yes
      ExecStart=/bin/sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled
      
      [Install]
      WantedBy=multi-user.target
    • To set THP to madvise, add the following content to <new_thp_file>.service file:

      [Unit]
      Description=Madvise Transparent Hugepages
      After=local-fs.target
      Before=sysinit.target
      
      [Service]
      Type=oneshot
      RemainAfterExit=yes
      ExecStart=/bin/sh -c 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
      
      [Install]
      WantedBy=multi-user.target
  3. Enable and start the service:

    # systemctl enable <new_thp_file>.service
    # systemctl start <new_thp_file>.service

Verification

  • To verify the status of THP, view the following files:

    $ cat /sys/kernel/mm/transparent_hugepage/enabled
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部