Thursday, April 5, 2012

How to Test Large Page Support on Your Linux System

Enabling large page support on Linux systems can give a significant boost to Java performance. This is especially true for Java applications with large datasets or running with large heap sizes[1].

In this article,  we will show you how to test:
  • if your Linux system supports large page
  • if your Linux system is configured correctly for large page support

How to Test If Large Page Is Supported?


To check if your system can support large page memory, try the following:  
$ cat /proc/meminfo | grep Huge  

Below we show the test results of three systems:

System 1
$ cat /proc/meminfo | grep Huge
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

System 1 supports large page memory.  However, it was not configured to use it.  Note that large page size is in 2MB instead of the standard 4KB.

System 2
$ cat /proc/meminfo | grep Huge
$

System 2 does not support large page memory.

System 3
$  cat /proc/meminfo | grep Huge
HugePages_Total:  4000
HugePages_Free:   4000
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

System 3 supports large page memory and it is configured to support up to  8GB.

How to Test If Large Page Is Configured Correctly?


In the following tests, we use Hotspot VM as our JVM.   Beginning with Java SE 5.0 there is now a cross-platform flag for requesting large memory pages:
  • -XX:+UseLargePages (on by default for Solaris, off by default for Windows and Linux).

It is a good idea to verify that the large-page configuration in your system is correct  by running this command:  

$java -Xmx400m -XX:+UseLargePages -version

Test 1

$java -Xmx400m -XX:+UseLargePages -version
Java HotSpot(TM) Server VM warning: Failed to reserve shared memory (errno = 12).
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Server VM (build 11.0-b16, mixed mode)
Test 1 was run on System 1 which supports large page, but is not configured for its use.

Test 2

$ java -Xmx400m -XX:+UseLargePages -version
Java HotSpot(TM) Server VM warning: Failed to reserve shared memory (errno = 38).
 java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)

Test 2 was run on System 2 which doesn't support large page.

Test 3

$ ./java -Xmx400m -XX:+UseLargePages -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)

Test 3 was run on System 3 which supports large page and is configured to use it.

Conclusion


In this article, we have introduced you how to test:
  • if your system supports large page or not
  • if your system is configured correctly for large page

Two final tips:
  1. To learn how to configure large page support on your Linux system, read [1].
  2. To request large memory pages on JRockit, you can use the following VM options[4]:
    • -XlargePages
    • -XlargePages:exitOnFailure
    • -XX:+|-UseLargePagesFor[Heap|Code] 
      • Recommended by Oracle

References

  1. Java SE Tuning Tip: Large Pages on Windows and Linux 
  2. Understanding Garbage Collection
  3. Java Tuning White Paper
  4. Oracle® JRockit Command-Line Reference
  5. Memlock limit too small (one of the requirements for large page support)
  6. JRockit: Could not acquire large pages for 2Mbytes code
  7. JRockit: Unable to open temporary file /mnt/hugepages/jrock8SadIG
  8. Oracle Fusion Middleware 11g SOA White Paper February 2013 (Check out "Huge pages" for the instructions of enabling huge pages on Linux kernel 2.6)
  9. huge page - The Linux Kernel Archives

No comments: