Visit Azul.com Support

Enabling Huge Pages

Table of Contents
Need help?
Schedule a consultation with an Azul performance expert.
Contact Us
Looking for Zing?
The Azul Zing Virtual Machine is now Azul Zulu Prime Builds of OpenJDK and part of Azul Platform Prime.
Learn more
Note
This setting is only applicable to the Azul Zing Builds of OpenJDK (Zing) running without Azul Zing System Tools (ZST). Zing in ZST mode always uses its efficient large pages implementation.

With Zing running in non-ZST mode, Zing uses standard Linux pages 4KB in size for its Java heap by default, which requires no system configuration. As all Azul Zing 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). Zing with ZST implements a more efficient memory manager for large pages than standard Linux and is recommended in those situations.

If ZST can not 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 Zing 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 Zing 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 Zing:

 
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/Oracle Linux/Amazon Linux according to your operating system below.

Once the above settings are in place, Zing 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 Zing’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 Zing 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, do the following:

  1. 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
  2. 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.

  3. To permanently enable recommended THP settings for Zing 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
  4. Verify the change:

     
    /opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep huge

    A sample output showing Zing using THP should look as follows:

     
    [GCHH : Use transparent huge pages for java heap : true ]

Permanent THP Setting on RHEL / CentOS / Oracle Linux / Amazon Linux

To persist the THP configuration on CentOS Stream / RHEL 8 or newer, Oracle Linux 8 and 9 and UEK 7.9 or Amazon Linux.

  1. 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
  2. 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.

  3. To permanently enable recommended THP settings for Zing 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 [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
  4. List the currently activate tuned profiles:

     
    sudo tuned-adm active
  5. Make a copy of the list of active profiles. In this example let’s assume the active profile is named MYPROFILE.

  6. Add the Zing THP profile by enabling the current profile and the Zing THP profile together:

     
    sudo tuned-adm profile MYPROFILE zingthp
  7. Verify the change:

     
    /opt/zing/zing-jdk11/bin/java -Xlog:gc -version | grep huge

    A sample output showing Zing 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 Zing with ZST to install the ZST component. The Zing automatically starts supporting the ZST component after its installation.