Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor the JVM usage of large memory pages in Windows 7?

I am trying to measure the performance gain of using large memory pages in Windows 7 HotSpot JVM. In order to do that, I need to monitor the JVM memory usage to make sure that Large Pages are actually utilized. Unfortunately, I can't find away to achieve that. Below is a description of the setup and trials I have done:

Environment Setup

I am using 64-bit Windows 7 ultimate edition for my tests. "Lock pages in memory" Windows security policy is enabled as described in Java Support for Large Memory Pages. I also verified that Large Pages feature is enabled by running java version command as the following:

java -XX:+UseLargePages -version

Where I get the following results, which dedicate that large pages feature is enabled:

java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

I used this sample Java program from this video in all my trials to consume all the memory available for the java heap:

public class InfinteStringHashmap {
public static void main(String[] args) throws Exception{
    Map<Long, String> map = new HashMap<Long, String>();

    for(long i=1; true; i++){
        StringBuilder sb = new StringBuilder();
        for(long j=0;j<i;j++) sb.append(" ");
        map.put(i, sb.toString());

        if(i % 1000 == 0){
            System.out.print(".");
            Thread.sleep(1000);
        }
    }
  }
}

I ran this sample program using the following command (with a fixed heap size of 512m for example):

java -Xms512m -Xmx512m -XX:+UseLargePages InfinteStringHashmap

I also tried other heap sizes as small as 12MB and as large as 10GB. Please note that I run my test application immediately after restarting the machine to make sure my free RAM memory is not fragmented.

Failed trials to monitor the memory

In order to verify whether Large Memory Pages are used or not, I tried:

  1. RamMap tool from Windows SystInternals which has a specific field for Large Pages. No matter how I change the heap size, it does not show usage of Large Memory pages. To verify it, I tried Creating a File Mapping Using Large Pages example from the MSDN to narrow down the possibilities. It worked perfectly fine (it print a 2MB page size from insied the code). RamMap tool does not show anything.
  2. Printing the page size used by the Java process using the code suggested in this post. It prints 4096 (the default page size on Windows) all the time. To verify it, I tried Large Pages on Linux version of the Hotspot JVM as described in this video, and it worked. However, printing the page size didn't work (it prints 4096 all the time).
  3. Vadump tool that shows virtual memory statistics about a specific process. The "-o" option is supposed to show the types of VM used by a process, the number of used pages, and the total size of occupied by each type which can be used to deduce whether large pages are used. Unfortunately, this command fails with error code 24 when I set the JVM UseLargePages option.
  4. VmMap tool does not update the looked memory column.
  5. Simple monitoring tools like TaskManager and Perfmon do not provide detailed information about Large pages.

Edit: I tried the following tools that were suggested in the comments:

  1. Java Mission Controller: Doesn't provide page size info.

  2. Process Explorer: same as above

Is there away to measure the page size of a process or monitor the usage of large memory pages in Windows ??

like image 903
Ala' Alkhaldi Avatar asked Jun 18 '14 18:06

Ala' Alkhaldi


People also ask

How do I monitor JVM heap?

The easy way to monitor Heap usage is by using a commercial APM (Application Performance management tool) such as CA Wily APM, AppDynamics, New Relic, Riverbed, etc. APM tools not only monitor the heap usage, but you can also configure the tool to Alert you when Heap usage is not normal.

Why JVM heap utilization is too high?

This is because the JVM steadily increases heap usage percentage until the garbage collection process frees up memory again. High heap usage occurs when the garbage collection process cannot keep up. An indicator of high heap usage is when the garbage collection is incapable of reducing the heap usage to around 30%.


1 Answers

I think that your test method is not appropriate. You use the Large Memory Pages when you want to optimize the TLB:

A Translation-Lookaside Buffer (TLB) is a page translation cache that holds the most-recently used virtual-to-physical address translations. TLB is a scarce system resource. A TLB miss can be costly as the processor must then read from the hierarchical page table, which may require multiple memory accesses. By using bigger page size, a single TLB entry can represent larger memory range. There will be less pressure on TLB and memory-intensive applications may have better performance.

You can use [JVisualVM], to profile your application. but in case of your test you create new objects. Im not an expert here but for mz understanding of TBL, you should load data from memory to structure that should be in the buffer. If is not there i should be loaded.

In theory a test that measure time for constant number of operations should be sufficient to see influence of the VM parameter.

like image 51
Damian Leszczyński - Vash Avatar answered Nov 09 '22 20:11

Damian Leszczyński - Vash