CMS常见错误

** 碎片参数 **

-XX:OldPLABSize=16
-XX:-ResizeOldPLAB
-XX:+PrintGCDetails
-XX:+PrintPromotionFailure
-XX:PrintFLSStatistics=1

** Concurrent mode failure **

  1. 设置-XX:CMSInitiatingOccupancyFraction
  2. 增大old区的大小
At beginning  of each young GC, collector should ensure that there is enough free
 memory in old space to promote aged objects from young space. Modern CMS 
collector estimates size of objects to be promoted using statistics from previous
 collections. If old space does not have enough free bytes to hold estimated 
promotion amount, **concurrent mode failure** will be raise. Concurrent mode
 failure doesn't necessary lead to Full GC, in certain cases JVM will just wait for
 concurrent collection cycle to finish, but application will remain in STW pause 
until young collection will be finished.


Most frequent reason for concurrent mode failure is late initiation of CMS cycle. 
JVM tries to estimate amount of garbage in heap and duration of CMS cycle and
 start it as late as possible to avoid wasting of CPU. Unfortunately this estimation
 may be too optimistic. You can advise JVM to start CMS earlier using following
 flags:

-XX:CMSInitiatingOccupancyFraction=30-XX:+UseCMSInitiatingOccupancyOnly


Setting above will force CMS cycle is more than 30% of old space is use. Second 
option disables JVM heuristics, without second parameter JVM may not obey 
CMS initiating occupancy fraction setting.


Normally for server type applications you would like CMS to be running 
continuously. If you are experiencing **concurrent mode failure**, even though 
next CMS cycle is starting right after previous, it means that CMS throughput is 
just not enough. In this case you should increase size of old generation and give 
CMS collector more head room to do its job. Alternatively you may try to dedicate 
more CPU cores for concurrent collector, but CPU is usually even more limited 
resource on modern servers than memory.


In summary, there are two reasons for **concurrent mode failure**STW pause 
mentioned above, both of them can be remedied fairly easily with JVM options.

** Promotion failure **

Promotion failure is more complicated situation. CMS collector is not compacting 
free memory in old space, instead it have to deal with fragmented free space (a 
set of free memory chunks). It is possible, that all free bytes are scattered though 
small chunks, and it is impossible to find certain amount of continuous memory to 
promote particular large object, even though total number of free bytes is large
 enough.

Heap fragmentation is well known problem, and there are few effective techniques 
reducing fragmentation.

CMS memory manager is using separate free lists for different size of chunks. 
Using these free lists, it can effectively fill small holes in fragmented memory 
space with objects of exact size. This technique is known to be fairly effective 
(and widely used in C/C++ memory managers). But, surprisingly, it doesn't seems
 to work well for JVM in many real live situations.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文阅读 前言 这段时间懈怠了,罪过! 最近看到有同事也开始用上了微信公众号写博客了,挺好的~给他们点赞,这博客我...
    码农戏码阅读 6,056评论 2 31
  • 一次CMS GC问题排查过程(理解原理+读懂GC日志) - iamzhongyong - ITeye技术网站 h...
    葡萄喃喃呓语阅读 2,023评论 0 11
  • 简书 占小狼转载请注明原创出处,谢谢 上周有幸给部门的小伙伴分享了一些JVM相关的知识,在整个做PPT的过程中,也...
    美团Java阅读 8,336评论 19 76
  • 这篇文章是我之前翻阅了不少的书籍以及从网络上收集的一些资料的整理,因此不免有一些不准确的地方,同时不同JDK版本的...
    高广超阅读 15,818评论 3 83
  • 介绍JVM中7个区域,然后把每个区域可能造成内存的溢出的情况说明 程序计数器:看做当前线程所执行的字节码行号指示器...
    jemmm阅读 2,270评论 0 9