Find Native Memory Leak in Java Application Using Jemalloc

Jemalloc: Java Native Memory profiling shows 100% je_prof_backtrace

Try configuring using the below flags :

./configure --enable-prof --enable-stats --enable-debug --enable-fill

Spring boot application not using jemalloc

When you run sudo, Java gets root environment which does not have your previously exported LD_PRELOAD and MALLOC_CONF.

Try

sudo LD_PRELOAD=/usr/local/lib/libjemalloc.so \
MALLOC_CONF=prof:true,lg_prof_interval:30,lg_prof_sample:17 \
java -jar application.jar

BTW, jemalloc is not always useful for profiling Java applications, since it cannot show Java stacks (but it is useful for preventing memory leaks caused by the standard allocator).

Try async-profiler as described in this answer.

Also check this post about Java native memory consumption.

Java Native Memory 'Other' section consumes a lot of memory

Your async-profilers arguments seem wrong.

Change event=itimer,Unsafe_AllocateMemory0 to event=Unsafe_AllocateMemory0

async-profiler also has an experimental nativemem mode specifically for finding native memory leaks. See https://github.com/jvm-profiling-tools/async-profiler/discussions/491 for the details.

Other section in NMT typically includes off-heap memory allocated with Unsafe.allocateMemory, in particular, Direct ByteBuffers.

How to track JVM native memory

There are several tools that you can use.
I'll refer to this excellent answer by apangin: Java using much more memory than heap size (or size correctly Docker memory limit)
I strongly encourage you to read all of that but for your question, this in particular is relevant:

There are tools and techniques for investigating issues with Java memory consumption: Native Memory Tracking, pmap, jemalloc, async-profiler.



Related Topics



Leave a reply



Submit