When allocating off-heap memory in Java (through direct buffers, or JNI native code for example), will the allocated memory be backed by huge pages if the JVM is using -XX:+UseLargePages ?
Asked
Active
Viewed 554 times
1 Answers
4
No, HotSpot JVM uses a plain libc malloc
call to allocate memory for a direct ByteBuffer.
However, if you replace the standard system allocator with, for example, jemalloc - you'll be able to configure malloc to use huge pages when available.
Another option to use huge pages for direct ByteBuffers is to create a file on a hugetlbfs filesystem and then map it in Java as a MappedByteBuffer
.

apangin
- 92,924
- 10
- 193
- 247
-
I guess using libhugetlbfs to overload the malloc behaviour when expanding the heap would be another option? Would this solution or the jemalloc one work for malloc calls done via JNI? – user36568 Jan 08 '20 at 22:54
-
@user36568 Right, libhugetlbfs should do the job, too. It will work both for direct ByteBuffers and other malloc calls in JNI code. – apangin Jan 12 '20 at 13:03