CMS 垃圾收集器 - 它何时运行? [英] CMS garbage collector - when does it run?

查看:22
本文介绍了CMS 垃圾收集器 - 它何时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对可能控制 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>

The concurrent collection generally cannot be sped up but it can be started earlier. A concurrent collection starts running when the percentage of allocated space in the old generation crosses a threshold. This threshold is calculated based on general experience with the concurrent collector. If full collections are occurring, the concurrent collections may need to be started earlier. The command line flag CMSInitiatingOccupancyFraction can be used to set the level at which the collection is started. Its default value is approximately 68%. The command line to adjust the value is -XX:CMSInitiatingOccupancyFraction=<percent>

http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

默认情况下,虚拟机会在每个集合处增大或缩小堆,以尝试将每个集合处的可用空间与活动对象的比例保持在特定范围内.这个目标范围由参数-XX:MinHeapFreeRatio=-XX:MaxHeapFreeRatio=设置为百分比,总大小为以 -Xms 为界,以 -Xmx 为界.

By default, the virtual machine grows or shrinks the heap at each collection to try to keep the proportion of free space to live objects at each collection within a specific range. This target range is set as a percentage by the parameters -XX:MinHeapFreeRatio=<minimum> and -XX:MaxHeapFreeRatio=<maximum>, and the total size is bounded below by -Xms and above by -Xmx.

.. 或 ..

http://www.petefreitag.com/articles/gctuning/

-XX:MaxHeapFreeRatio - 当一代中可用空间的百分比超过此值时,一代将缩小以满足此值.默认值为 70

-XX:MaxHeapFreeRatio - when the percentage of free space in a generation exceeded this value the generation will shrink to meet this value. Default is 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 垃圾收集器 - 它何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆