Enabling Huge Pages
Note
|
This setting is only applicable to the Azul Zulu Prime Builds of OpenJDK (Azul Zulu Prime JVM) running without Azul Zulu Prime System Tools (ZST). Azul Zulu Prime JVM in the ZST mode always uses its efficient large pages implementation. |
With the Azul Zulu Prime JVM running in the non-ZST mode, Azul Zulu Prime JVM uses standard Linux pages 4KB in size for its Java heap by default, which requires no system configuration. As all Azul Zulu Prime JVM modes use the same C4 GC algorithm, good performance regarding the garbage collection is expected and for most applications, the default setting is sufficient.
However, some applications may benefit from the use of large pages (2 MB) due to reduced misses on the Translation Lookaside Buffer (TLB). Azul Zulu Prime JVM with ZST implements a more efficient memory manager for large pages than standard Linux and is recommended in those situations.
If the Zing System Tools (ZST) cannot be used, a good alternative is transparent huge pages (THP) on RHEL/CentOS 8, Ubuntu 18, Amazon Linux since 2018, Debian 10, SLES 12 SP4 and their later versions. These operating systems support THP with shared memory and feature improved implementation of THP that reduces the risk of system pauses.
Transparent Huge Pages (THP)
Verify if your Linux system can be configured for the type of THP supported by Azul Zulu Prime JVM in the non-ZST mode:
cat /sys/kernel/mm/transparent_hugepage/shmem_enabled
It should return a line similar to the following:
always within_size advise never deny force
If it returns No such file or directory
, your Linux version does not support shared memory THP. Use the ZST or upgrade to a more recent Linux version as an alternative.
To enable THP for Azul Zulu Prime JVM in the non-ZST mode, first make a copy of the current settings:
/opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep huge > zingthp_old.conf
Now run the following commands to enable THP for Azul Zulu Prime JVM:
echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled
echo defer | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
echo 1 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
To persist these settings over a reboot, refer to Permanent THP Setting on Ubuntu or Permanent THP Setting on RHEL/CentOS according to your operating system below.
Once the above settings are in place, Azul Zulu Prime JVM in the non-ZST mode automatically uses transparent huge pages. This can be verified by checking the GC log header file:
[GCHH : Use transparent huge pages for java heap : true ]
If the process is running and can successfully acquire huge pages, it is reflected in the output of the following command:
grep HugePages: /proc/meminfo
This lists Azul Zulu Prime JVM’s usage of THP for the complete Java heap defined by -Xmx
under the ShmemHugePages
metric while OpenJDK’s usage of THP would be listed as AnonHugePages
.
If you ever need to disable THP on Azul Zulu Prime JVM under this system configuration, add -XX:-UseTransparentHugePages
to the command line of the Java process.
Permanent THP Setting on Ubuntu
To persist the THP configuration shown above on Ubuntu 18.04 or 20.04, do the following:
-
Check if the setting is needed as it might already be enabled, and make a copy of this current setting:
/opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep huge > zingthp_old_ubuntu.conf -
Compare the settings with the recommendation shown above. If some of the settings already match and some not, your system is most likely tuned for some application. Refer to the documentation of that tuning to decide how to proceed and merge both tunings.
-
To permanently enable recommended THP settings for Azul Zulu Prime JVM without ZST, run the following:
sudo apt install sysfsutils sudo tee /etc/sysfs.d/zingthp.conf <<EOF kernel/mm/transparent_hugepage/enabled=madvise kernel/mm/transparent_hugepage/shmem_enabled=advise kernel/mm/transparent_hugepage/defrag=defer kernel/mm/transparent_hugepage/khugepaged/defrag=1 EOF sudo systemctl restart sysfsutils -
Verify the change:
/opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep hugeA sample output showing Azul Zulu Prime JVM using THP should look as follows:
[GCHH : Use transparent huge pages for java heap : true ]
Permanent THP Setting on RHEL/CentOS/Oracle Linux
To persist the THP configuration shown above on CentOS/RHEL 8.x, do the following:
Note
|
The following can also be aplied on Oracle Linux version 7.9 UEK (only). |
-
Check if the setting is needed as it might already be enabled, and make a copy of this current setting:
/opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep huge > zingthp_old_rhel.conf -
Compare the settings with the recommendation shown above. If some of the settings already match and some not, your system is most likely tuned for some application. Refer to the documentation of that tuning to decide how to proceed and merge both tunings.
-
To permanently enable recommended THP settings for Azul Zulu Prime JVM without ZST, run the following:
sudo mkdir /usr/lib/tuned/zingthp sudo tee /usr/lib/tuned/zingthp/tuned.conf <<EOF [main] summary=Enable SHMEM transparent huge pages in madvise mode for Zing without ZST [sysfs] /sys/kernel/mm/transparent_hugepage/enabled=madvise /sys/kernel/mm/transparent_hugepage/shmem_enabled=advise /sys/kernel/mm/transparent_hugepage/defrag=defer /sys/kernel/mm/transparent_hugepage/khugepaged/defrag=1 EOF -
List the currently activate tuned profiles:
sudo tuned-adm active -
Make a copy of the list of active profiles. In this example let’s assume the active profile is named MYPROFILE.
-
Add the Azul Zulu Prime JVM THP profile by enabling the current profile and the Azul Zulu Prime JVM THP profile together:
sudo tuned-adm profile MYPROFILE zingthp -
Verify the change:
/opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep hugeA sample output showing Azul Zulu Prime JVM using THP should look as follows:
[GCHH : Use transparent huge pages for java heap : true ]
Explicit/Static Huge Pages
Due to its complexity in setting up and the risk of poor performance if misconfigured, Explicit/Static huge pages in the non-ZST mode are not recommended.
Note
|
If the tuning guidelines above do not help, follow instructions in Installing the Azul Zulu Prime JVM with ZST to install the ZST component. The Azul Zulu Prime JVM automatically starts supporting the ZST component after its installation. |