java jvm UseConcMarkSweepGC收集器下新生代与老生代内存比例问题

Jeffreyji
  • 9

jdk版本:
jdk1.8.0_172
jvm参数设置如下:

-server -Xms4096m -Xmx4096m -XX:+UseConcMarkSweepGC

使用jmap -heap得到的jvm信息如下:

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 4294967296 (4096.0MB)
   NewSize                  = 872415232 (832.0MB)
   MaxNewSize               = 872415232 (832.0MB)
   OldSize                  = 3422552064 (3264.0MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 785186816 (748.8125MB)
   used     = 574468424 (547.8557815551758MB)
   free     = 210718392 (200.95671844482422MB)
   73.1632793997397% used
Eden Space:
   capacity = 697958400 (665.625MB)
   used     = 523313936 (499.07106018066406MB)
   free     = 174644464 (166.55393981933594MB)
   74.97781185812794% used
From Space:
   capacity = 87228416 (83.1875MB)
   used     = 51154488 (48.78472137451172MB)
   free     = 36073928 (34.40277862548828MB)
   58.64429316244835% used
To Space:
   capacity = 87228416 (83.1875MB)
   used     = 0 (0.0MB)
   free     = 87228416 (83.1875MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 3422552064 (3264.0MB)
   used     = 94509608 (90.13138580322266MB)
   free     = 3328042456 (3173.8686141967773MB)
   2.761378241520302% used

查看了一下官方jvm文档
image.png
也就是说在-server的模式下,新生代与老生代默认的比例应该是1:8,但是从上面jmap拿到的信息来看并不是的(也不是1:2)。
如果在jvm参数中指定了
-XX:NewRatio=8
则结果为:

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 4294967296 (4096.0MB)
   NewSize                  = 477167616 (455.0625MB)
   MaxNewSize               = 477167616 (455.0625MB)
   OldSize                  = 3817799680 (3640.9375MB)
   NewRatio                 = 8
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 429457408 (409.5625MB)
   used     = 234440080 (223.57948303222656MB)
   free     = 195017328 (185.98301696777344MB)
   54.58983257310583% used
Eden Space:
   capacity = 381747200 (364.0625MB)
   used     = 223183120 (212.84400939941406MB)
   free     = 158564080 (151.21849060058594MB)
   58.46359056464592% used
From Space:
   capacity = 47710208 (45.5MB)
   used     = 11256960 (10.7354736328125MB)
   free     = 36453248 (34.7645263671875MB)
   23.594447544642858% used
To Space:
   capacity = 47710208 (45.5MB)
   used     = 0 (0.0MB)
   free     = 47710208 (45.5MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 3817799680 (3640.9375MB)
   used     = 90144904 (85.96887969970703MB)
   free     = 3727654776 (3554.968620300293MB)
   2.3611742772213757% used

求解。

回复
阅读 356
1 个回答
✓ 已被采纳

这个 NewRatio 在 CMS 下“不生效”的问题,算是一个 BUG 吧,或者好像叫 Feature 也可以……

JVM Ergonomics 会自动调整一些参数,导致 CMS 下 Ratio 就不对了,没啥纠结的,显示指定一下 NewSize 就好。

参考

  1. https://bugs.java.com/bugdata...
  2. https://docs.oracle.com/javas...
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏