title: How to monitor the JVM usage of large memory pages in Windows 7?
body: <p>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:</p>
  
  <p><strong>Environment Setup</strong></p>
  
  <p>I am using 64-bit Windows 7 ultimate edition for my tests. "Lock pages in memory" Windows security policy is enabled as described in <a href="http://www.oracle.com/technetwork/java/javase/tech/largememory-jsp-137182.html" rel="nofollow noreferrer">Java Support for Large Memory Pages</a>. I also verified that Large Pages feature is enabled by running java version command as the following:</p>
  
  <pre><code>java -XX:+UseLargePages -version
  </code></pre>
  
  <p>Where I get the following results, which dedicate that large pages feature is enabled:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I used this sample Java program from <a href="https://www.youtube.com/watch?v=6dLAo1LGHrk" rel="nofollow noreferrer">this video</a> in all my trials to consume all the memory available for the java heap:</p>
  
  <pre><code>public class InfinteStringHashmap {
  public static void main(String[] args) throws Exception{
      Map&lt;Long, String&gt; map = new HashMap&lt;Long, String&gt;();
  
      for(long i=1; true; i++){
          StringBuilder sb = new StringBuilder();
          for(long j=0;j&lt;i;j++) sb.append(" ");
          map.put(i, sb.toString());
  
          if(i % 1000 == 0){
              System.out.print(".");
              Thread.sleep(1000);
          }
      }
    }
  }
  </code></pre>
  
  <p>I ran this sample program using the following command (with a fixed heap size of 512m for example):</p>
  
  <pre><code>java -Xms512m -Xmx512m -XX:+UseLargePages InfinteStringHashmap
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>Failed trials to monitor the memory</strong></p>
  
  <p>In order to verify whether Large Memory Pages are used or not, I tried:</p>
  
  <ol>
  <li><a href="http://technet.microsoft.com/en-us/sysinternals/ff700229.aspx" rel="nofollow noreferrer">RamMap tool</a> 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 <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366543%28v=vs.85%29.aspx" rel="nofollow noreferrer">Creating a File Mapping Using Large Pages</a> 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.</li>
  <li>Printing the page size used by the Java process using the code suggested in <a href="https://stackoverflow.com/questions/19047584/getting-virtual-memory-page-size-by-java-code">this post</a>. 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 <a href="https://www.youtube.com/watch?v=6dLAo1LGHrk" rel="nofollow noreferrer">this video</a>, and it worked. However, printing the page size didn't work (it prints 4096 all the time).</li>
  <li><a href="http://www.softpedia.com/get/System/System-Miscellaneous/Vadump.shtml" rel="nofollow noreferrer">Vadump</a> 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.</li>
  <li><a href="http://technet.microsoft.com/en-us/sysinternals/dd535533.aspx" rel="nofollow noreferrer">VmMap</a> tool does not update the looked memory column.</li>
  <li>Simple monitoring tools like TaskManager and Perfmon do not provide detailed information about Large pages.</li>
  </ol>
  
  <p><strong>Edit</strong>: I tried the following tools that were suggested in the comments:</p>
  
  <ol start="6">
  <li><p>Java Mission Controller: Doesn't provide page size info.</p></li>
  <li><p>Process Explorer: same as above</p></li>
  </ol>
  
  <p><strong>Is there away to measure the page size of a process or monitor the usage of large memory pages in Windows ??</strong></p>