14

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 ??

Community
  • 1
  • 1
Ala' Alkhaldi
  • 308
  • 2
  • 9
  • I am also interested in this. -server -XX:+UseLargePages -XX:+PrintFinalFlags shows that UseLargePages:=false (why?), and the fact that all heap memory is solely within the private working set confirms that this is the case. Ability to lock pages in memory is enabled for the JVM-running user, up to 12 GB RAM free right after restart. – Tadas S Nov 06 '15 at 09:20

3 Answers3

1

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.

  • Measuring the performance gain of using Large Memory Pages (LMP) is my final goal. Currently, I am trying to make sure that I actually use them. Ideally, when LMP is used, all the object I create should be held in a non-heap memory and should be prevented to swap out. Once I am sure about using LMP, the test you suggested is the right way to measure the performance gain. – Ala' Alkhaldi Jul 01 '14 at 17:47
0

I'm not sure if this is what you're looking for.
But procexp (Process Explorer) might be helpful. It isn't anything special. Just a fancier Task Manager for Windows 7.

Also, with the later downloads of the Java JDK there is something called Java Mission Control.

Good Luck!

aaiezza
  • 1,297
  • 3
  • 11
  • 21
0

LMP seems to be a feature of a particular allocation rather than a feature of the entire process (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366720(v=vs.85).aspx). Tracking which allocation used and which did not use LMP may not be feasible.

Update: try attaching a system calls monitor to your process. You may be able to see if VirtualAlloc is called with correct parameters.

  • The JVM process is a special. "a JVM can’t mix large pages and small pages. Even if you provide the appropriate “large page” option" ([Source](http://developer.amd.com/resources/java-zone/java-zone-archive/supersizing-java-large-pages-on-the-opteron-processor-part-2/)). Could you elaborate more about attaching system call monitors? – Ala' Alkhaldi Jul 01 '14 at 18:24
  • I suspect JVM uses large pages for its heap. On Linux I'd use strace. One system call monitor I know on Windows is procmon - but it only records files, registry and thread/process, not memory. Another choice seems to be Windows Performance Recorder, but I never used it personally. I am sure more tools exist. –  Jul 01 '14 at 18:36