Configuring Transparent HugePages

Explains how to review and adjust Transparent HugePages parameters, including status checks, mode changes, and defragment settings.

The Transparent HugePages (THP) feature is enabled by default in Oracle Linux. However, you might still need to access and configure THP according to the system's needs.

Parameters Used to Configure Transparent HugePages

The following table describes selected parameter settings that can be used when configuring Transparent HugePages (THP).

Commonly Used THP Parameters
Parameter File Location Value Options
enabled /sys/kernel/mm/transparent_hugepage/enabled Sets THP and its mode, which is one of the following:
  • always (default): THP is enabled in system-wide mode.

    In this setting, the kernel, whenever possible, assigns huge pages to processes using large contiguous virtual memory areas.

  • madvise: THP is enabled in per-process mode.

    In this setting the kernel only assigns huge pages to application processes that explicitly request huge pages through the madvise() system call.

  • disabled: THP is disabled.
defrag /sys/kernel/mm/transparent_hugepage/defrag
Determines how aggressively an application can reclaim pages and defrag memory when THP is unavailable. The following list explains the available options:
  • always: An application requesting THP stalls on allocation failure and directly reclaims pages and compact memory to obtain a THP immediately.

  • defer: An application doesn't stall but continues using small pages. The application requests the kernel daemons kswapd and kcompactd to reclaim pages and compact memory so that THP is available later.
  • defer+madvise:

    Regions using the madvise(MADV_HUGEPAGE) call stall on allocation failure and directly reclaim pages and compact memory to obtain a THP immediately

    However, all other regions request the kernel daemons kswapd and kcompactd to reclaim pages and compact memory so that THP is available later.

  • madvise (default): Regions using the madvise(MADV_HUGEPAGE) call stall on allocation failure and directly reclaim pages and compact memory to obtain a THP immediately.

Retrieving the Current Status of Transparent HugePages

Shows how to check the Transparent HugePages mode by reading the sysfs status file.

This procedure shows how to see the current status of THP in the sysfs virtual file system.

For more information about using the sysfs virtual file system, see Managing Kernels and System Boot on Oracle Linux.

To see the current setting of THP you can read the /sys/kernel/mm/transparent_hugepage/enabled parameter.

Use the cat command to view the current value of the THP in the sysfs.
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never

The value inside the square brackets represents the current setting.

Changing the Current Status of Transparent HugePages

Explains how to switch Transparent HugePages between available modes with sysfs updates.

This procedure shows how to change the current status of THP by setting a value in the sysfs virtual file system.

For more information about using the sysfs virtual file system, see Managing Kernels and System Boot on Oracle Linux.

To change the current status of THP, you need to write the preferred settings to /sys/kernel/mm/transparent_hugepage/enabled. The following example shows you how to set the status to always.

Note

Virtual file systems such as sysfs provide a file system interface to items that aren't necessarily stored as files on disk. The sysfs files therefore don't always interact with file commands in the same way that regular physical files on disk would. In the example procedure, the echo command used doesn't overwrite /sys/kernel/mm/transparent_hugepage/enabled, as it would if used with a regular file, but instead changes the selected option.

  1. Check the current status of THP by reading the enabled parameter.
    sudo cat /sys/kernel/mm/transparent_hugepage/enabled
    always madvise [never]

    The value inside the square brackets represents the current setting.

  2. Set THP mode to always.
    echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
  3. Confirm the change has been successful by reading the enabled parameter.
    sudo cat /sys/kernel/mm/transparent_hugepage/enabled
    [always] madvise never

Changing the defrag Setting of Transparent HugePages

Describes how to tune the Transparent HugePages defrag policy to balance performance and availability.

This procedure shows how to change the defragmentation setting of THP by setting a value in the sysfs virtual file system.

For more information about using the sysfs virtual file system, see Managing Kernels and System Boot on Oracle Linux.

To change the THP defrag setting you need to write the new setting to /sys/kernel/mm/transparent_hugepage/defrag.

Note

The best defrag setting varies from system to system. Reclaiming pages and memory compaction can increase the number of THP pages available. However, the process also uses CPU time. Therefore, you need to find the correct balance for a specific system.

The following example shows you how to set the defrag setting to madvise.

  1. Check the current value of the defrag parameter:
    sudo cat /sys/kernel/mm/transparent_hugepage/defrag
    [always] defer defer+madvise madvise never

    The value inside square brackets represents the current setting.

  2. Set the /sys/kernel/mm/transparent_hugepage/defrag parameter to madvise:
    echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
  3. Confirm the change by reading the defrag parameter.
    sudo cat /sys/kernel/mm/transparent_hugepage/defrag
    always defer defer+madvise [madvise] never