G1垃圾收集器:为什么生存空间总是满的? [英] G1 Garbage Collector: Why survivor space is always full?
问题描述
以下是 jmap -heap
命令的输出:
幸存空间:
地区= 52
容量= 54525952(52.0MB)使用
= 54525952(52.0MB)
免费= 0(0.0MB)
使用100.0%
我执行了很多次,发现的值
总是等于使用
。
我的问题是为什么幸存者空间总是充满(如此之小)?我已指定 -Xmx2200m -Xms2200m -Xmn1100m
。
(我预计幸存者的空间应该是220M,这意味着应该有更多的空间存活下来)
- update -
jheap的完整输出:
2个线程的Garbage-First(G1) s)
堆配置:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2306867200(2200.0MB)
NewSize = 1153433600(1100.0MB)$
SurRivorRatio = 8
MetaspaceSize = 16777216(16.0MB)
bNewSize = 1153433600(1100.0MB)
OldSize = 4194304(4.0MB)
NewRatio = 2
CompressedClassSpaceSize = 1073741824(1024.0MB)
MaxMetaspaceSize = 4294963200(4095.99609375MB)
G1HeapRegionSize = 1048576(1.0MB)
堆使用情况:
G1堆:
地区= 14488
容量= 15191769088(14488.0MB)
使用= 10 83703304(1033.5000076293945MB)
免费= 14108065784(13454.499992370605MB)
7.13348983730946%使用
G1年轻一代:
伊甸园空间:
地区= 988
= 1163919360(1110.0MB)
used = 1035993088(988.0MB)
free = 127926272(122.0MB)
89.009009009009%已使用
幸存者空间:
地区= 45
容量= 47185920(45.0MB)
使用= 47185920(45.0MB)
免费= 0(0.0MB)
使用100.0%
G1老一代:$ b $使用
$ b = 2
容量= 1095761920 $ b 30424 interned字符串占用3027304字节。
我的观察。
-
当您停止自定义一些参数时,G1GC很有效。我建议删除
Xmn
(young gen)设置。 c> -Xms 和 -
作为最大堆内存大小/ 2048。对于4G堆,2MB应该是区域大小&对于2 GB的堆,1 MB应该是理想的区域大小。
-
要配置的关键参数:
-XX:G1HeapRegionSize = n,XX:MaxGCPauseMillis = m,-XX:ParallelGCThreads = n, -XX:ConcGCThreads = n
除了-Xms和-Xmx
-Xmx
来自 Oracle
当您评估并优化G1 GC时,请牢记以下建议:
年轻一代大小:避免使用-Xmn选项或任何或其他相关选项(如-XX:NewRatio)显式设置年轻一代大小。确定年轻一代的规模会覆盖目标的暂停时间目标。暂停时间目标:当您评估或调整任何垃圾收集时,始终存在延迟与吞吐量权衡。
Here is the output of jmap -heap
command:
Survivor Space:
regions = 52
capacity = 54525952 (52.0MB)
used = 54525952 (52.0MB)
free = 0 (0.0MB)
100.0% used
I've executed it many times and I found that the value of capacity
is alway equal to used
.
My question is why survivor space is alway full(and so small)? I've specified -Xmx2200m -Xms2200m -Xmn1100m
.
(I expect the survivor space should be 220M, which means there should be more space for survivor region)
-- update--
Full output of jheap:
Garbage-First (G1) GC with 2 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2306867200 (2200.0MB)
NewSize = 1153433600 (1100.0MB)
MaxNewSize = 1153433600 (1100.0MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 16777216 (16.0MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 4294963200 (4095.99609375MB)
G1HeapRegionSize = 1048576 (1.0MB)
Heap Usage:
G1 Heap:
regions = 14488
capacity = 15191769088 (14488.0MB)
used = 1083703304 (1033.5000076293945MB)
free = 14108065784 (13454.499992370605MB)
7.13348983730946% used
G1 Young Generation:
Eden Space:
regions = 988
capacity = 1163919360 (1110.0MB)
used = 1035993088 (988.0MB)
free = 127926272 (122.0MB)
89.009009009009% used
Survivor Space:
regions = 45
capacity = 47185920 (45.0MB)
used = 47185920 (45.0MB)
free = 0 (0.0MB)
100.0% used
G1 Old Generation:
regions = 2
capacity = 1095761920 (1045.0MB)
used = 524296 (0.5000076293945312MB)
free = 1095237624 (1044.4999923706055MB)
0.04784762003775419% used
30424 interned Strings occupying 3027304 bytes.
My observations.
G1GC is efficient when you stop customizing some of the parameters. I suggest to remove
Xmn
( young gen) setting.Set different values of
-Xms
and-Xmx
Region size should be configured as Maximum heap memory size / 2048. For 4G heap, 2 MB should be region size & for 2 GB heap, 1 MB should be ideal region size.
key parameters to be configured :
-XX:G1HeapRegionSize=n, XX:MaxGCPauseMillis=m, -XX:ParallelGCThreads=n, -XX:ConcGCThreads=n
apart from-Xms and -Xmx
Have a look at this SE post and infoQ article for more details.
Recommendation from Oracle
When you evaluate and fine-tune G1 GC, keep the following recommendations in mind:
Young Generation Size: Avoid explicitly setting young generation size with the -Xmn option or any or other related option such as -XX:NewRatio. Fixing the size of the young generation overrides the target pause-time goal.
Pause Time Goals: When you evaluate or tune any garbage collection, there is always a latency versus throughput trade-off.
这篇关于G1垃圾收集器:为什么生存空间总是满的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!