Metaspace by default auto increases its size (up to what the underlying OS provides), while PermGen always has a fixed maximum size. You can set a fixed maximum for Metaspace with JVM parameters, but you cannot make PermGen auto-increase.
It is worthwhile to mention that prior to Java 7, interned
Strings used to be kept on the PermGen. That caused some serious problems with
the infamous:
java.lang.OutOfMemoryError: PermGen space
Whenever there is a need to resize PermGen/Metaspace, JVM
will do it as it does with the standard heap. Resizing those spaces requires a
full GC, which is always an expensive operation. It can usually be observed
during a startup when a lot of classes are being loaded. Especially if the
application has dependencies on many external libraries. If there are a lot of
full GCs during the startup, it’s usually because of that. If that case,
increasing the initial size can boost the startup performance.
To increase PermGen, we have the following commands:
-XX:PermSize=N - sets the initial (and
minimum size) of the Permanent Generation space.
-XX:MaxPermSize=N - sets the maximum size
of the Permanent Generation space.
In Java 8 and onwards, we can set the initial and maximum
size of Metaspace using the following commands:
-XX:MetaspaceSize=N - sets the initial (and
minimum size) of the Metaspace.
-XX:MaxMetaspaceSize=N - sets the maximum size
of the Metaspace.
Can you please give detailed info about metaspace, how it is diff from heap. How it impact our web app?
ReplyDelete