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:
- 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.
- 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).
- 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.
- VmMap tool does not update the looked memory column.
- 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:
Java Mission Controller: Doesn't provide page size info.
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 ??