39

What the difference between

-Xms4096m
-Xmx2048M 
-XX:MaxPermSize=712M

I am getting confused of this two -Xmx2048M and -XX:MaxPermSize=712M

and will happen if I use -Xmx2048M or -Xmx2048m

Sanjay Dutt
  • 1,173
  • 4
  • 15
  • 19

1 Answers1

69

Java objects reside in an area called the heap, while metadata such as class objects and method objects reside in the permanent generation or Perm Gen area. The permanent generation is not part of the heap.

The heap is created when the JVM starts up and may increase or decrease in size while the application runs. When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.

-Xmssize Specifies the initial heap size.

-Xmxsize Specifies the maximum heap size.

-XX:MaxPermSize=size Sets the maximum permanent generation space size. This option was deprecated in JDK 8, and superseded by the -XX:MaxMetaspaceSize option.

Sizes are expressed in bytes. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.

References:

How is the java memory pool divided?

What is perm space?

Java (JVM) Memory Model – Memory Management in Java

Java 7 SE Command Line Options

Java 7 HotSpot VM Options

Community
  • 1
  • 1
JRL
  • 3,363
  • 24
  • 36
  • Thanks, but what will happen if I increase a size of this -XX:MaxPermSize=8192m. Because I am facing performnace issue and application process got slow – Sanjay Dutt Jul 13 '16 at 05:55
  • 3
    **If you have performance issues you need to diagnose them and find the cause.** 8192m is an excessive amount of perm gen space. Usually you only need to increase perm gen when you are getting `java.lang.OutOfMemoryError: PermGen space` errors. If garbage collection is triggering very often, may be you need to increase the heap memory with `-xmx`, but note that less memory will be available to the OS disk cache. Take a look at https://rimuhosting.com/knowledgebase/linux/java/-Xmx-settings and [Tuning Tomcat Performance For Optimum Speed](https://www.mulesoft.com/tcat/tomcat-performance). – JRL Jul 13 '16 at 14:02
  • Hi @JRL, thanks for this short and clean explanation! My team and I just have a final question, maybe you will be able to help us : do that two amounts of memory add up? Let's say that I allow 2048M to my Java application managed on Kubernetes, and this one is set up with a -Xmx of 2048M and a -XX:MaxPermSize of 384M. Is it better to allow 2560M of memory to my application ? Or 2048M will be fine ? – lboix Jan 03 '20 at 19:48
  • 1
    @lboix These two areas are independent and their memory adds up, so you will need at least 2432M if both reach its maximum. – JRL Jan 06 '20 at 20:44