Configuring Transparent HugePages
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.
The following sections look at various THP parameters and examples of how they can be configured.
Parameters Used to Configure Transparent HugePages
Table 6-3 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:
|
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:
|
Configuring Transparent HugePages at Runtime
The following sections show you examples of how you can configure THP at runtime by accessing
the THP parameters in the sysfs
virtual file system.
Retrieving the Current Status of Transparent HugePages
/sys/kernel/mm/transparent_hugepage/enabled
parameter as shown in the
following code
sample:sudo 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
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
:
- 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.
- Set THP mode to
always
.echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
- Confirm the change has been successful by reading the
enabled
parameter.sudo cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
Note:
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 previous example, 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:
sudo cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
always
sudo cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
.
Changing the defrag Setting of Transparent HugePages
/sys/kernel/mm/transparent_hugepage/defrag
Note:
The bestdefrag
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
.
- 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.
- Set the
/sys/kernel/mm/transparent_hugepage/defrag
parameter tomadvise
:echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
- Confirm the change has worked by reading the
defrag
parameter.sudo cat /sys/kernel/mm/transparent_hugepage/defrag
always defer defer+madvise [madvise] never