Tenured district concurrent garbage collector CMS Introduction

Source: Internet
Author: User

Transferred from: http://javis163.iteye.com/blog/1679059

When using the CMS collector, the collection process for the old generation is as follows when the collection is started:
1, first the JVM decides what time to start garbage collection according to-xx:cmsinitiatingoccupancyfraction,-xx:+usecmsinitiatingoccupancyonly;
2, if the-xx:+usecmsinitiatingoccupancyonly is set, then the CMS GC will only be triggered if the old generation occupies exactly the proportions set by the-xx:cmsinitiatingoccupancyfraction parameter ;
3, if the-xx:+usecmsinitiatingoccupancyonly is not set, then the system will decide when to trigger the CMS GC according to the statistics, so sometimes you will encounter a 80% ratio is set to the CMS GC, but it is triggered at 50%. The reason why this parameter is not set;
4, when the CMS GC starts, the first stage is Cms-initial-mark, this phase is the initial marking phase, is the stop the world stage, so this stage of the object is only the most directly accessible from the root set of objects;
cms-initial-mark:961330k (1572864K), The used space and total space of the old generation when the indicator is recorded
5, the next stage is Cms-concurrent-mark, this phase is executed concurrently with the application thread, the so-called concurrency collector refers to this, the main function is to mark the object to reach
This phase Prints 2 logs: Cms-concurrent-mark-start,cms-concurrent-mark
6, the next stage is Cms-concurrent-preclean, this phase is mainly to do some pre-cleanup, because the markup and application threads are executed concurrently, so there will be some object state after the tag will change, this phase is to solve this problem because the subsequent rescan phase will also stop The world, in order to make the pause time as small as possible, also need to preclean stage to do a part of the work to save time
This phase Prints 2 logs: Cms-concurrent-preclean-start,cms-concurrent-preclean
7, the next stage is the Cms-concurrent-abortable-preclean phase, the purpose of joining this phase is to make the CMS GC more controllable, the role is to perform some pre-cleanup to reduce the time that the rescan phase caused the application to pause
This phase involves several parameters:
-xx:cmsmaxabortableprecleantime: When the Abortable-preclean phase execution reaches this time, it will not end.
-xx:cmsscheduleremarkedensizethreshold (Default 2m): control when the Abortable-preclean phase begins to execute,
That is, when Eden uses this value, the Abortable-preclean phase is started
-xx:cmsscheduleremarkedenpenetratio (Default 50%): control when the Abortable-preclean phase ends execution
This phase will print some logs as follows:
Cms-concurrent-abortable-preclean-start,cms-concurrent-abortable-preclean,
Cms:abort Preclean due to time XXX
8, then the next stage is the second stop the world stage, that is, the rescan phase, this phase suspended the application thread, the object is re-scanned and tagged;
YG occupancy:964861k (2403008K), refers to the situation of young generation at the time of implementation
CMS remark:961330k (1572864K), refers to the case of an old generation at the time of execution
It also prints out the time-consuming process of weak reference processing, class unloading, etc.
9, and then the next stage is cms-concurrent-sweep, to carry out the concurrent garbage cleanup
10, finally Cms-concurrent-reset, resets the related data structure for the next CMS GC
11,full GC:
There are 2 scenarios that trigger the full GC, and the entire app pauses
A,concurrent-mode-failure: When the CMS GC is in progress, there is a new object for the old generation, but the old generation of space is not enough
B,promotion-failed: When a young GC is in progress, some of the Young's objects are still available, but the S1 or S2 do not fit, so they need to be placed in the old generation, but the old generation space cannot accommodate this.

The parameters that affect the GC duration and trigger of the CMS are the following 2:
-xx:cmsmaxabortableprecleantime=5000
-xx:cmsinitiatingoccupancyfraction=80
The solution is also for these two parameters, the root cause is the amount of memory consumed per request is too large
How to resolve:
A, for the trigger stage of the CMS GC, adjust the-XX:CMSINITIATINGOCCUPANCYFRACTION=50, trigger the CMS GC early, you can alleviate when the old generation reached 80%,cms GC processing is not complete, resulting in concurrent mode Failure Trigger full GC
B, modify the-xx:cmsmaxabortableprecleantime=500, reduce the time of the Cms-concurrent-abortable-preclean phase
C, the compact is not performed when the CMS GC is considered, so join-xx:+usecmscompactatfullcollection
(Compact of Memory after CMS GC) and-xx:cmsfullgcsbeforecompaction=4 (compact after full GC4) parameters


Tenured district concurrent garbage collector CMS Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.