Back to Zing Documentation Home

Using Huge Pages with Zing Virtual Machine

Note

This setting is only applicable to the Zing Virtual Machine (ZVM) running in the non-ZST mode. Zing in the ZST mode always uses its efficient large pages implementation.

With the Zing Virtual Machine running in the non-ZST mode, Zing uses standard Linux pages 4KB in size for its Java heap by default, which requires no system configuration. As all 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 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 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 according to your operating system.

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 : 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 18.04 or 20.04, 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 # https://docs.azul.com/zing/InstallZingVirtual_EnableHugePages.htm 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

To persist the THP configuration shown above on CentOS/RHEL 8.x, 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_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 # https://docs.azul.com/zing/InstallZingVirtual_EnableHugePages.htm [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

  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 Virtual Machine (ZVM) with ZST to install the Zing System Tools (ZST) component. The Zing Virtual Machine automatically starts supporting the ZST component after its installation.

 

 

 

Last modified: December 18, 2020


© Azul Systems, Inc. 2020 All rights reserved.

Privacy Policy | Legal | Terms of Use