Changing the defrag Setting of Transparent HugePages

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 Oracle Linux 8: Managing Kernels and System Boot

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