-->

private bytes increase for a javaw process in java

2019-02-03 03:22发布

问题:

My project has started using java 8 from java 7.

After switching to java 8, we are seeing issues like the memory consumed is getting higher with time.

Here are the investigations that we have done :

  • Issues comes only after migrating from java7 and from java8
  • As metaspace is the only thing related to memory which is changes from hava 7 to java 8. We monitored metaspace and this does not grow more then 20 MB.
  • Heap also remains consistent.

Now the only path left is to analyze how the memory gets distributes to process in java 7 and java 8, specifically private byte memory. Any thoughts or links here would be appreciated.

NOTE: this javaw application is a swing based application.

UPDATE 1 : After analyzing the native memory with NMT tool and generated a diff of memory occupied as compare to baseline. We found that the heap remained same but threads are leaking all this memory. So as no change in Heap, I am assuming that this leak is because of native code.

So challenge remains still open. Any thoughts on how to analyze the memory occupied by all the threads will be helpful here. Below are the snapshots taken from native memory tracking.

In this pic, you can see that 88 MB got increased in threads. Where arena and resource handle count had increased a lot.

in this picture you can see that 73 MB had increased in this Malloc. But no method name is shown here.

So please throw some info in understanding these 2 screenshot.

回答1:

I encountered the exact same issue.

Heap usage constant, only metaspace increase, NMT diffs showed a slow but steady leak in the memory used by threads specifically in the arena allocation. I had tried to fix it by setting the MALLOC_ARENAS_MAX=1 env var but that was not fruitful. Profiling native memory allocation with jemalloc/jeprof showed no leakage that could be attributed to client code, pointing instead to a JDK issue as the only smoking gun there was the memory leak due to malloc calls which, in theory, should be from JVM code.

Like you, I found that upgrading the JDK fixed the problem. The reason I am posting an answer here is because I know the reason it fixes the issue - it's a JDK bug that was fixed in JDK8 u152: https://bugs.openjdk.java.net/browse/JDK-8164293

The bug report mentions Class/malloc increase, not Thread/arena, but a bit further down one of the comments clarifies that the bug reproduction clearly shows increase in Thread/arena.



回答2:

You may try another GC implementation like G1 introduced in Java 7 and probably the default GC in Java 9. To do so just launch your Java apps with:

-XX:+UseG1GC

There's also an interesting functionality with G1 GC in Java 8u20 that can look for duplicated Strings in the heap and "deduplicate" them (this only works if you activate G1, not with the default Java 8's GC).

-XX:+UseStringDeduplication

Be aware to test thoroughly your system before going to production with such a change!!!

Here you can find a nice description of the diferent GCs you can use



回答3:

consider optimising the JVM options

  1. Parallel Collector(throughput collector)

    -XX:+UseParallelGC

  2. concurrent collectors (low-latency collectors)

    -XX:+UseConcMarkSweepGC

  3. use String Duplicates remover

    -XX:+UseStringDeduplication

  4. optimise compact ratio

    -XXcompactRatio: and refer link1 link2



回答4:

In this my answer you can see information and references how to profile native memory of JVM to find memory leaks. Shortly, see this.

UPDATE

Did you use -XX:NativeMemoryTracking=detail option? The results are straightforward, they show that the most memory allocated by malloc. :) It's a little bit obviously. Your next step is to profile your application. To analyze native methods and Java I use (and we use on production) flame graphs with perf_events. Look at this blog post for a good start.

Note, that your memory increased for threads, likely your threads grow in application. Before perf I recommend analyze thread dumps before/after to check does Java threads number grow and why. Thread dumps you can get with jstack/jvisualvm/jmc, etc.



回答5:

This issue does not come with Java 8 update 152. The exact root cause of why it was coming with earlier versions is still not clearly identified.