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
Check the status of THP:
$ cat /sys/kernel/mm/transparent_hugepage/enabledConfigure THP.
Enabling THP:
$ echo always > /sys/kernel/mm/transparent_hugepage/enabledDisabling THP:
$ echo never > /sys/kernel/mm/transparent_hugepage/enabledSetting THP to
madvise:$ echo madvise > /sys/kernel/mm/transparent_hugepage/enabledTo 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
madvisesystem 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
madviseonly. 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.
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
-
TuneDpackage is installed. -
TuneDservice is enabled.
Procedure
Copy the active profile file to the same directory:
$ sudo cp -R /usr/lib/tuned/my_profile /usr/lib/tuned/my_copied_profileEdit the
tune.conffile:$ sudo vi /usr/lib/tuned/my_copied_profile/tuned.confTo enable THP, add the line:
[bootloader] cmdline = transparent_hugepage=alwaysTo disable THP, add the line:
[bootloader] cmdline = transparent_hugepage=neverTo set THP to
madvise, add the line:[bootloader] cmdline = transparent_hugepage=madvise
Restart the
TuneDservice:$ sudo systemctl restart tunedSet the new profile active:
$ sudo tuned-adm profile my_copied_profile
Verification
Verify that the new profile is active:
$ sudo tuned-adm activeVerify 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
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"Configure THP by adding kernel parameters.
To enable THP:
# grubby --args="transparent_hugepage=always" --update-kernel=DEFAULTTo disable THP:
# grubby --args="transparent_hugepage=never" --update-kernel=DEFAULTTo set THP to
madvise:# grubby --args="transparent_hugepage=madvise" --update-kernel=DEFAULT
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
-
Create new systemd service files for enabling, disabling and setting THP to
madvise. For example,/etc/systemd/system/disable-thp.service. Configure THP by adding the following contents to a new systemd service file.
To enable THP, add the following content to
<new_thp_file>.servicefile:[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.targetTo disable THP, add the following content to
<new_thp_file>.servicefile:[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.targetTo set THP to
madvise, add the following content to<new_thp_file>.servicefile:[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
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