Be sure to remember the 14 JVM memory configuration parameters

jvm setting parameters do more (Oracle official website of the Java HotSpot VM Options ), but as a java developer, that several parameters most commonly used basic meaning of certain death and remember and understand. It is recommended that a site http://jvmmemory.com/ above you can easily set parameters jvm (of course this site is also some errors, the most reliable or to check under the Oracle documentation).

Notice: Here we default to Linux JAVA8 hotspot environment, for example, the Oracle official website of the Java Platform, Standard Edition Tools Reference (and there are detailed parameter configuration instructions).

14 are given below and the most common basic memory configuration parameters.

parameter

Equivalent to

-Xss1024k

-XX:ThreadStackSize=1024k

-Xms512m

 

-Xmx1024m

-XX:MaxHeapSize=1024m

-Xmn512m

 

-XX:NewSize=512m

 

-XX:MaxNewSize=512m

 

-XX:NewRatio=8

 

-XX:SurvivorRatio=32

 

-XX: MinHeapFreeRatio = 40

 

-XX:MaxHeapFreeRatio=70

 

-XX:MetaspaceSize=128m

 

-XX:MaxMetaspaceSize=256m

 

First we look at the structure of jvm memory model, it is not described in detail here, I used a diagram to make you never forget (jvisualvm visualGC plug, not the figure below jvm parameters above, only for the convenience of jvm memory model of memory). Of course, this picture Sike also permanently remembered, he had more than we remember a few parameters is no longer difficult, long time will not feel strange or forget.

一个重要的概念就是我们常常所说的设置jvm的内存参数大多关注的是堆内存的大小,你可以简单理解成这样:堆内存 = Old + Eden + S0 + S1年轻的 = Eden(新生代) + S0 + S1

栈内存大小相关设置

-Xss1024k

  • 意义: 设置线程栈占用内存大小。
  • 默认值:不同的操作系统平台,其默认值不同,具体看官网说明。

堆内存大小相关设置

-Xms512m

  • 意义: 设置堆内存初始值大小。
  • 默认值:如果未设置,初始值将是老年代和年轻代分配制内存之和。

-Xmx1024m

年轻代内存大小相关设置

-Xmn512m

  • 意义: 设置新生代的初始值及最大值。
  • 默认值:堆内存的1/4(这里要记住不是最大堆内存,还是已经分配的堆内存的1/4)。

-XX:NewSize=512m

  • 意义:设置新生代的初始值。

-XX:MaxNewSize=512m

  • 意义:设置新生代的最大值。

比率方式设置

-XX:NewRatio=8

  • 意义:设置老年代和年轻代的比例。比如:-XX:NewRatio=8 表示老年代内存:年轻代内存=8:1 => 老年代占堆内存的8/9;年轻代占堆内存的1/9
  • 默认值:2 。

-XX:SurvivorRatio=32

  • 意义:设置新生代和存活区的比例(这里需要注意的是存活区指的是其中一个)。比如:-XX:SurvivorRatio=8 表示存活区:新生代=1:8 =》新生代占年轻代的8/10,每个存活区各占年轻代的1/10
  • 默认值:8 。

-XX:MinHeapFreeRatio=40

  • 意义:GC后,如果发现空闲堆内存占到整个预估上限值的40%,则增大上限值。
  • 默认值:40 。

-XX:MaxHeapFreeRatio=70

  • 意义:GC后,如果发现空闲堆内存占到整个预估上限值的70%,则收缩预估上限值。
  • 默认值:70。

Meta大小相关设置

-XX:MetaspaceSize=128m

  • 意义:初始元空间大小,达到该值就会触发垃圾收集进行类型卸载,同时GC会对该值进行调整:如果释放了大量的空间,就适当降低该值;如果释放了很少的空间,那么在不超过MaxMetaspaceSize时,适当提高该值。
  • 默认值:依赖平台。

-XX:MaxMetaspaceSize=256m

  • 意义:设置元空间的最大值,默认是没有上限的,也就是说你的系统内存上限是多少它就是多少。
  • 默认值:默认没有上限,在技术上,Metaspace的尺寸可以增长到交换空间。

以上就是14个参数,为了深刻理解,建议本地配置让后观察内存大小变化(可以使用jmap -heap pid 或者 visualGC来帮助观察)验证自己的理解是否正确。

Guess you like

Origin www.cnblogs.com/shoshana-kong/p/11314686.html