当前位置:网站首页>CMS garbage collector
CMS garbage collector
2020-11-08 20:13:00 【Entry station】
CMS Garbage collector collection step by step
- Initial marker (Stop the world)
- Concurrent Tags
- Pre cleaning
- Pre cleaning that can be terminated
- Re label (Stop the world)
- Concurrent elimination
- Concurrent reset
Initial marker
> Mark GcRoots Direct access to the elderly , Old age objects referenced by new generation surviving objects . The whole process is in JDK1.7 Is single threaded in JDK1.8 Is multithreaded ( adopt CMSParallelInitialMarkEnabled Parameter adjustment ). This process can lead to STW.
Concurrent Tags
> from Initial marker
Phase marked objects start , Mark other living objects , At this stage, the garbage collection thread and the application thread run simultaneously . Because it's running at the same time , Application threads are still running , It will lead to the promotion of the object , Changes in object references , Special objects are assigned directly to the old age . These affected objects of the old age are Card Will be marked as Dirty, For relabeling phase scanning , The object of the old age Card Marked as Dirty The possible reasons for this are shown in the green line below .
Pre cleaning
> Since the previous phase was executed concurrently, unmarked change objects are only marked as Dirty object , Not yet dealt with , Pre cleaning
It's to mark these Dirty object
. Here's the picture : In the concurrent tagging phase 3 Number Card Marked as Dirty. This stage is for Re label
Stage preparation .
Pre cleaning will 6 No. 1 is a living object
Pre cleaning that can be terminated
> This stage is also a preparation for the re marking stage , Before entering the re labeling phase , It's better to have a Minor GC, Clean up the younger generation , This will clear most of the younger generation's targets ( The vast majority of young people live and die ), Try to shorten Re label
Stage pause time ,CMS It also provides CMSScavengeBeforeRemark Parameters , It can be forced to proceed in sequence before entering the relabeling Minor gc.
Re label (remark)
> Pre cleaning
and Pre cleaning that can be terminated
All for Re label
Stage preparation , because Re label
Stage will happen (STW), So make sure you have as much pause time as you can , Otherwise, it will affect the user experience of the application . The target of this phase of scanning is : The younger generation +GC Roots+Dirty Old age object , This phase is multithreaded (XX:+CMSParallelRemarkEnabled).
Concurrent elimination
> The user thread is activated , Objects that are not marked are cleared .'
Concurrent reset
> CMS The garbage collector parameter returns to its initial state , Prepare for the next garbage collection .
Use CMS What to pay attention to in garbage collector
Re label
The pause time is too long
> 80% Time spent in Re label
Stage , If you find that Re label
Stage pause time is too long , Try adding -XX:+CMSScavengeBeforeRemark
, stay Re label
Do it once before Minor GC
, The goal is to reduce invalid references to older objects , Reduce Re label
The cost of .
Memory fragmentation problem
> CMS It's based on markers - Clearing algorithm's ,CMS Only garbage objects will be deleted , Does not compress memory space , Will cause memory fragmentation . We need to use -XX:CMSFullGCsBeforeCompaction=n
Parameters to adjust , It means last time CMS After concurrent execution , How many more times to execute Full GC
To do memory compression .
concurrent mode failure
> stay CMS GC In the process, because the app is also running , At that time, the light generation was full of , Yes Minor GC
Now , You need to put the surviving objects into the older generation , At this time, there is not enough space for the elderly , At this time CMS There's no chance to recycle the older generation . You can set the following two parameters
- -XX:CMSInitiatingOccupancyFraction=75
> CMS The utilization rate of memory reaches 75% Will start GC, The default is 92%, Too high will lead to promotion failed
- -XX:+UseCMSInitiatingOccupancyOnly
> If not set UseCMSInitiatingOccupancyOnly
, Only set CMSInitiatingOccupancyFraction
that JVM Only for the first time , It will be adjusted automatically later .
> Why set the above two parameters , In the garbage collection stage , The user thread is still running , So you have to leave enough space for user threads to run .CMS The first five stages are all marked with living objects , except ” Initial marker ” and ” Re label ” Stage meeting stop the word , The other three phases are run with the user thread , That's what happens gc Thread is marking live objects , User threads also promote new objects to the old age , The cleaning up has not started yet ,old gen There's no room for more objects , This will lead to concurrent mode failure, And then you'll use a serial collector to recycle old-fashioned garbage , It took a long time to cause a pause . CMSInitiatingOccupancyFraction Set a reasonable value for the parameter , The settings are big , Will increase concurrent mode failure Frequency of occurrence , The settings are small , It will increase again CMS frequency , So choose a reasonable value according to the running situation of the application . If it is found that these two parameters are set too large, it will lead to full gc, Small settings will cause frequent CMS GC, It means that the space in your old age is too small , It's time to increase the size of space for the elderly .
promotion failed
> It's going on Minor GC when ,Survivor space can't let go , The object can only be put into the old generation , At this time, the old generation can't let go , Most of the time, there are too many memory fragments in the old days , As a result, there is no continuous space for objects .
Premature promotion and promotion failure
> happen Minor GC when , If the object is too large (Survivor Space It can't be stored ) It's basically going to go back to the old days , This phenomenon is called premature promotion , This will result in the older generation being augmented by short-term and medium-term objects , Can cause serious performance problems . If the old generation is full , Will trigger Full GC, This will result in traversing the entire heap , Promotion failure .
Solution
- If a large object promotion failure is caused by memory fragmentation ,cms Need to do space consolidation and compression ;
- If it's due to too fast ascension , explain Survivor Insufficient free space , Then try to turn it up Survivor;
- If it's due to the lack of space for the elderly , Try to CMS The trigger threshold is lowered .
CMS summary
- CMS Only the older generation , Response speed first .
- Re labeling will STW, Long pause time , So do one before this Minor GC, Will reduce a lot of invalid references to older objects .
- Memory fragmentation problem caused by Full GC, Please use
-XX:CMSFullGCsBeforeCompaction=n
, Organize the memory regularly to reduce memory fragmentation . - JDK1.7,JDK1.8 Set up CMS Garbage collector
XX:+UseConcMarkSweepGC
Several important CMS Parameters
-XX:CMSFullGCsBeforeCompaction=n
Full GC
n After the memory compression-XX:CMSInitiatingOccupancyFraction=70
-XX:+UseCMSInitiatingOccupancyOnly
Memory footprint 70% Will triggerCMS GC
-XX:+CMSScavengeBeforeRemark
CMS GC Do it once before Minor GC
版权声明
本文为[Entry station]所创,转载请带上原文链接,感谢
边栏推荐
- Dynamic query processing method of stored procedure
- 使用Fastai开发和部署图像分类器应用
- CountDownLatch 瞬间炸裂!同基于 AQS,凭什么 CyclicBarrier 可以这么秀?
- Solve the failure of go get download package
- Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
- Dynamic programming: maximum subarray
- Why need to use API management platform
- C / C + + learning diary: original code, inverse code and complement code
- Regular backup of WordPress website program and database to qiniu cloud
- Implementation of warehouse management system with ABP (net core) + easyUI + efcore
猜你喜欢
latex入门
Using GaN based oversampling technique to improve the accuracy of model for mortality prediction of unbalanced covid-19
Flink系列(0)——准备篇(流处理基础)
SQL quick query
动态规划答疑篇
opencv 解决ippicv下载失败问题ippicv_2019_lnx_intel64_general_20180723.tgz离线下载
. net core cross platform resource monitoring library and dotnet tool
11 important operations of Python list
Simple process of reading pictures by QT program developed by Python
Interesting article sharing: what is the difference between C language and C + +, C?
随机推荐
Dynamic query processing method of stored procedure
Solution to cross domain problem of front end separation
快来看看!AQS 和 CountDownLatch 有怎么样的关系?
An online accident caused by improper use of thread pool
Awk implements SQL like join operation
使用Fastai开发和部署图像分类器应用
中缀表达式转后缀表达式
Select sort
[elastic search technology sharing] - ten pictures to show you the principle of ES! Understand why to say: ES is quasi real time!
【云服务】阿里云服务器ECS实例规格那么多,如何选型?最佳实践说明
AI perfume is coming. Will you buy it?
Django之简易用户系统(3)
Simple process of reading pictures by QT program developed by Python
Suffix expression to infix expression
第一部分——第1章概述
如果把编程语言当武功绝学!C++是九阴真经,那程序员呢?
To introduce to you, this is my flow chart software—— draw.io
趣文分享:C 语言和 C++、C# 的区别在什么地方?
net.sf.json.JSONObject对时间戳的格式化处理
Regular backup of WordPress website program and database to qiniu cloud