G1 GC频繁触发Full GC排查:G1ReservePercent未生效原因
G1 GC频繁Full GC及ReservePercent未生效排查问题
应用GC配置(已移除GC日志相关参数)
-Xms32g -Xmx32g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:G1ReservePercent=15 -XX:+UnlockExperimentalVMOptions -XX:G1NewSizePercent=20
GC日志中记录的实际参数
OpenJDK 64-Bit Server VM (25.202-b08) for linux-amd64 JRE (1.8.0_202-b08), built on Jan 22 2019 13:35:07 by "jenkins" with gcc 4.8.2 20140120 (Red Hat 4.8.2-15) Memory: 4k page, physical 263567564k(2925568k free), swap 0k(0k free) CommandLine flags: -XX:CICompilerCount=15 -XX:ConcGCThreads=6 -XX:G1HeapRegionSize=16777216 (16MB) -XX:G1NewSizePercent=20 -XX:G1ReservePercent=15 -XX:InitialHeapSize=34359738368(32GB) -XX:MarkStackSize=4194304 -XX:MaxGCPauseMillis=200 -XX:MaxHeapSize=34359738368 -XX:MaxNewSize=20602421248 -XX:MinHeapDeltaBytes=16777216 -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
Full GC日志详情
2023-10-06T08:31:44.068+0800: 659309.919: [Full GC (Allocation Failure) 23G->21G(32G), 19.5437974 secs] [Eden: 16.0M(6000.0M)->0.0B(6544.0M) Survivors: 544.0M->0.0B Heap: 23.8G(32.0G)->21.3G(32.0G)], [Metaspace: 90182K->90182K(94208K)] [Times: user=27.33 sys=1.05, real=19.54 secs] 2023-10-06T09:15:45.544+0800: 661951.395: [Full GC (Allocation Failure) 31G->20G(32G), 14.5219354 secs] [Eden: 0.0B(6544.0M)->0.0B(6544.0M) Survivors: 0.0B->0.0B Heap: 31.7G(32.0G)->20.4G(32.0G)], [Metaspace: 90216K->90216K(94208K)] [Times: user=19.32 sys=1.00, real=14.52 secs] 2023-10-06T09:47:37.129+0800: 663862.980: [Full GC (Allocation Failure) 31G->20G(32G), 15.0624531 secs] [Eden: 0.0B(6544.0M)->0.0B(6544.0M) Survivors: 0.0B->0.0B Heap: 31.7G(32.0G)->20.5G(32.0G)], [Metaspace: 90217K->90199K(94208K)] [Times: user=18.48 sys=2.25, real=15.06 secs] 2023-10-06T10:11:54.450+0800: 665320.301: [Full GC (Allocation Failure) 31G->20G(32G), 14.5384049 secs] [Eden: 0.0B(6544.0M)->0.0B(6544.0M) Survivors: 0.0B->0.0B Heap: 31.7G(32.0G)->20.7G(32.0G)], [Metaspace: 90217K->90202K(94208K)] [Times: user=18.65 sys=1.60, real=14.54 secs] 2023-10-06T10:36:51.857+0800: 666817.708: [Full GC (Allocation Failure) 31G->20G(32G), 14.1996159 secs] [Eden: 0.0B(6544.0M)->0.0B(6544.0M) Survivors: 0.0B->0.0B Heap: 31.7G(32.0G)->20.7G(32.0G)], [Metaspace: 90213K->90205K(94208K)] [Times: user=18.68 sys=1.30, real=14.20 secs] 2023-10-06T11:00:10.119+0800: 668215.970: [Full GC (Allocation Failure) 31G->20G(32G), 14.1973267 secs] [Eden: 0.0B(6544.0M)->0.0B(6544.0M) Survivors: 0.0B->0.0B Heap: 31.7G(32.0G)->20.8G(32.0G)], [Metaspace: 90218K->90211K(94208K)] [Times: user=19.31 sys=0.77, real=14.20 secs]
核心排查点
某后端服务采用G1 GC,运行约2天后频繁触发Full GC。按G1ReservePercent=15的设计逻辑,G1应确保至少15%的堆空间空闲,即堆占用达约27G时触发Old/Mixed GC避免堆耗尽。但日志显示堆占用至31.7G才触发Full GC,非Full GC启动过晚,需排查:
- 频繁触发Full GC的根本原因
G1ReservePercent未按预期生效的原因
内容的提问来源于stack exchange,提问作者L.Maple
相关产品推荐
相关产品推荐

