3

I recently upgraded java version from 1.6 to 1.8. After migrating to java 1.8, the metaspace memory consumption increases with time (observed this through JConsole.) Also with every web page access, the metaspace size increases. So,

Is there any way I can forcefully clean up Metaspace?

Is there any way I can check what all goes in Metaspace and increases metaspace size?

Which GC (SerialGC, G1, ConcMarkSweep) efficiently cleans up Metaspace & what JVM VM configurations I should use for GC?

What is the minimal RAM java 1.8 requires for correct metaspace operations? In my case, its limited to 256M RAM with equal amount of swap size on a miniature linux box.

If we limit the metaspace size using XX:MaxMetaSpaceSize, JVM raises outofmemory:metaspace condition.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Possible duplicate of [How to get Java8 Metaspace dump (not heap dump)](http://stackoverflow.com/q/37919215/1362755) – the8472 Sep 04 '16 at 14:45
  • You mean like the magic “-uselessmemory” flag? When you set a limit, you are already enforcing a cleanup when the limit is reached. When you get an `OutOfMemoryError` in turn, it means, there is nothing more to clean up. – Holger Sep 05 '16 at 10:36
  • But why there is nothing to clean up especially in metaspace? If GC is executed either through JVM or even via Jconsole tool, there is a considerable drop down in heap space, but metaspace is almost untouched. Whats the reason behind it? Class loader leckage? How can I detect such leckage from code? – pragnesh rathod Sep 06 '16 at 01:32
  • yes, most likely a leak. and that's already covered in other SO questions – the8472 Sep 07 '16 at 18:07

1 Answers1

1

Thanks a bunch for your answers!

I found Old JaxB and JDK8 Metaspace OutOfMemory Issue, to be depicting the same problem as mine.

With "-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true", I was able to get metaspace usage stable.

With this option in place, if my application is idle (just periodically accesses a webservice, read xml and show up the details from within xml to my view layer), it no longer increases the memory usage neither in top command output not metaspace (in Jconsole).

But, if I perform any operation (ie. access webpages and perform database operations/file IO etc.) the memory usage goes up. This was the case with java 1.6 as well, but with java 1.6 the memory used to get to its normal level within 5-6 minutes time. But with java 1.8, it takes 10-12 hours to get to its normal level.

Here are my jvm configurations:

java -Dsun.rmi.dgc.client.gcInterval=60000 -XX:NewRatio=3 - 
XX:MinHeapFreeRatio=60 -XX:MaxHeapFreeRatio=70 -Xmx64M -Xms32M -
XX:MetaspaceSize=12M -XX:+UseLargePagesInMetaspace -
XX:CompressedClassSpaceSize=10M -XX:+UseLargePages -
XX:+CMSClassUnloadingEnabled -
Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true - 
Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -
Dcom.sun.management.jmxremote.authenticate=false -
Dcom.sun.management.jmxremote.port=1099 -Dfile.encoding=UTF8 -
Dorg.apache.jasper.compiler.disablejsr199=true -Duser.timezone=$timezone -jar start.jar
Community
  • 1
  • 1