问题描述
我对可能控制 CMS 收集器何时启动的两个参数感到困惑:
I am confused about two parameters that may control when the CMS collector kicks in:
MaxHeapFreeRatio
(默认为 70%)
CMSInitiatingOccupancyFraction
(默认超过 90%)
这些参数的具体含义是什么?收集器什么时候开始(标记阶段),收集(清扫阶段)?
What does each of those parameters mean, exactly? When does the collector start (the marking phase), and collect (the sweeping phase)?
推荐答案
CMSInitiatingOccupancyFraction
决定 CMS 何时启动(为了使此选项有效,您还必须设置 -XX:+UseCMSInitiatingOccupancyOnly
).MaxHeapFreeRatio
是用于调整世代空间大小的选项.
CMSInitiatingOccupancyFraction
decides when the CMS kicks in (in order for this option to be effective you must also set -XX:+UseCMSInitiatingOccupancyOnly
). MaxHeapFreeRatio
is an option to size the generational spaces.
例如看...
http://java.sun.com/docs/hotspot/gc1.4.2/faq.html
并发收集一般不能提速,但可以提早启动.当老年代中分配的空间百分比超过阈值时,并发收集开始运行.此阈值是根据并发收集器的一般经验计算得出的.如果正在发生完整收集,则可能需要更早地启动并发收集.命令行标志 CMSInitiatingOccupancyFraction 可用于设置开始收集的级别.其默认值约为 68%.调整值的命令行是-XX:CMSInitiatingOccupancyFraction=<percent>
http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html
默认情况下,虚拟机会在每个集合处增大或缩小堆,以尝试将每个集合处的可用空间与活动对象的比例保持在特定范围内.这个目标范围由参数-XX:MinHeapFreeRatio=
和-XX:MaxHeapFreeRatio=
设置为百分比,总大小为以 -Xms
为界,以 -Xmx
为界.
.. 或 ..
http://www.petefreitag.com/articles/gctuning/
-XX:MaxHeapFreeRatio
- 当一代中可用空间的百分比超过此值时,一代将缩小以满足此值.默认值为 70
我用一个测试程序运行了一些模拟,该程序只是随机创建字节数组的映射并将它们复制到周围.我注意到 a) 分数值没有得到尊重 - 特别是在保守值(比如 50)的情况下,CMS 初始标记阶段的占用率远远超过 50%,通常在 70-80% 左右,b) 尽管如此,更小的分数值使 CMS初始阶段发生得较早(程序使用了-Xmx1536m -Xmx1536m -XX:NewSize=512m -XX:+UseConcMarkSweepGc
+ gc logging 和两个测试参数)
EDIT : I ran a few simulations with a test program that just randomly creates maps of byte arrays and copies them around. I noticed that a) fraction value was not respected - in particular with a conservative value (say 50) the CMS initial mark stage kicked in much beyond 50% occupancy, typically around 70-80% and b) nonetheless smaller fraction values made the CMS initial stage happen earlier(program used -Xmx1536m -Xmx1536m -XX:NewSize=512m -XX:+UseConcMarkSweepGc
+ gc logging and the two test parameters)
我还发现了一个关于此的旧错误报告:http:///bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486089
I've also found an old bug report regarding this: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486089
这篇关于CMS 垃圾收集器 - 它何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!