ADDITIONAL SYSTEM INFORMATION :
Linux x64 with default hugepages set as 1GB:
$ cat /proc/meminfo
....
Hugepagesize: 1048576 kB
$ cat /proc/cmdline
...
default_hugepagesz=1G hugepagesz=1GB hugepages=222
A DESCRIPTION OF THE PROBLEM :
When using -XX:+UseLargePages, and having the linux kernel setup for 1GB largepages (instead of the default 2MB), I can't get the Code cache virtual space to be using large page as well.
This happens because code in heap.cpp http://hg.openjdk.java.net/jdk/jdk/file/0ce279d8c9cd/src/hotspot/share/memory/heap.cpp#l110
if (os::can_execute_large_page_memory()) {
const size_t min_pages = 8;
page_size = MIN2(os::page_size_for_region_aligned(committed_size, min_pages),
os::page_size_for_region_aligned(rs.size(), min_pages));
}
So if I set stuff like -XX:ReservedCodeCacheSize=1G -XX:InitialCodeCacheSize=1G -XX:+UseLargePages it doesn't work
because the code above attempts to fit at least 8 pages in 1G. The function page_size_for_region_aligned is dividing 1GB by 8, and then attempts to find a page size which small than that size.
This works if the hugepage is 2MB (< 1GB/8), but doesn't work if hugepage=1GB of course.
The fix is just replacing the number 8 to 1, since I don't see why we should limit ourself to that number.
I tried looking in mercurial history why the number 8 was chosen, and I couldn't figure this out
it was always like this: http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/a61af66fc99e/src/share/vm/memory/heap.cpp#l106
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Boot linux machine with 1GB huge pages by setting the correct parameters in kernel (see the runtime information above)
and then run it with:
java -Xmx1g -Xms1g -XX:+AlwaysPreTouch -XX:+UseG1GC -XX:+UseLargePages -XX:ReservedCodeCacheSize=1G -XX:InitialCodeCacheSize=1G
it would show in /proc/meminfo that only 1GB page is used (for the heap)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected result is for CodeCache to be on hugepage as well,
and when changing the constant 8 to 1 in the function above (CodeHeap::reserve) I see it happening, and also another hugepage is used.
ACTUAL -
CodeCache isn't using hugepages
CUSTOMER SUBMITTED WORKAROUND :
None, recompile the code with a different constant.
FREQUENCY : always