【问题标题】:Does G1 GC have a max size of region or max amount of region?G1 GC 是否有最大区域大小或最大区域数量?
【发布时间】:2017-03-03 02:56:01
【问题描述】:

我在学习 G1 GC 时,发现了这篇文章:http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html。在那篇文章中,有一段话是这样说的:

G1 GC 是一个区域化的分代垃圾收集器,这意味着 Java 对象堆(heap)被划分为多个大小相等的区域。启动时,Java 虚拟机 (JVM) 会设置区域大小。区域大小可以从 1 MB 到 32 MB 不等,具体取决于堆大小。目标是不超过 2048 个区域。

是不是说G1 GC可以处理的java堆内存最大大小是2048 * 32M,如果超过了会怎么样?

【问题讨论】:

    标签: java garbage-collection jvm g1gc


    【解决方案1】:

    来自HotSpot JVM sources:

      // Minimum region size; we won't go lower than that.
      // We might want to decrease this in the future, to deal with small
      // heaps a bit more efficiently.
      static const size_t MIN_REGION_SIZE = 1024 * 1024;
    
      // Maximum region size; we don't go higher than that. There's a good
      // reason for having an upper bound. We don't want regions to get too
      // large, otherwise cleanup's effectiveness would decrease as there
      // will be fewer opportunities to find totally empty regions after
      // marking.
      static const size_t MAX_REGION_SIZE = 32 * 1024 * 1024;
    
      // The automatic region size calculation will try to have around this
      // many regions in the heap (based on the min heap size).
      static const size_t TARGET_REGION_NUMBER = 2048;
    
    • MIN_REGION_SIZE (1MB) 和 MAX_REGION_SIZE (32MB) 是硬限制;
    • TARGET_REGION_NUMBER 只是一个提示,如果未在 JVM 选项中指定,则用于计算默认区域大小。实际数量可能会超过此值。

    【讨论】:

    • 您是否知道为什么/何时要使用-XX:G1HeapRegionSize 调整区域大小?例如,我注意到在 Minecraft 发行版中默认设置为 32MB - 远高于 JVM 的默认值。
    • @jocull 例如,增加区域大小有助于减少巨大的分配量。
    • G1 是否有内存上限,或者直到 1 TB 的堆大小也很好?
    • @samshers 完全取决于应用程序、其分配率和模式。 G1 可能会处理这么大的堆,但在您的情况下是否可以接受 GC 暂停 - 我不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    相关资源
    最近更新 更多