在 G1 GC 中,如何计算 IHOP 来启动并发标记周期?

在 G1 GC 中,如何计算 IHOP 来启动并发标记周期?

我试图了解 G1 GC 如何计算标记阈值以及它如何使用值-XX:InitiatingHeapOccupancyPercent-XX:+G1UseAdaptiveIHOP确定标记阈值以及将此标记阈值与哪个占用百分比(老一代或整个堆)进行比较。

文档中提到了两种不同的计算方法,

第一表示,占用率计算是针对整个堆而不是任何一代。

 -XX:InitiatingHeapOccupancyPercent=percent
Sets the percentage of the heap occupancy (0 to 100) at which to start a concurrent GC cycle. It’s used by garbage collectors that trigger a concurrent GC cycle based on the occupancy of the entire heap, not just one of the generations (for example, the G1 garbage collector).

第二个阈值是老生代大小的百分比

The Initiating Heap Occupancy Percent (IHOP) is the threshold at which an Initial Mark collection is triggered and it is defined as a percentage of the old generation size.

目前尚不清楚, occupancy percent = (current old generation size/Current total Heap size)*100

或者

occupancy percent = (Current Heap usage/Current total Heap size)*100

有人能指出我这里正确的计算方法吗?

答案1

首先结论:

occupancy percent = (current old generation usage + allocated bytes /Current total Heap size)*100

代码显然在 openjdk-jdk11u 的 src/hotspot/share/gc/g1/g1Policy.cpp 中

bool G1Policy::need_to_start_conc_mark(const char* source, size_t alloc_word_size) {
 ...
  size_t marking_initiating_used_threshold = _ihop_control->get_conc_mark_start_threshold();

  size_t cur_used_bytes = _g1h->non_young_capacity_bytes();
  size_t alloc_byte_size = alloc_word_size * HeapWordSize;
  size_t marking_request_bytes = cur_used_bytes + alloc_byte_size;

  bool result = false;
  if (marking_request_bytes > marking_initiating_used_threshold) {
    result = collector_state()->in_young_only_phase() && !collector_state()->in_young_gc_before_mixed();
   ...
  }

  return result;
}

仅老一代包括 humongous_set。

src/hotspot/share/gc/g1/g1CollectedHeap.hpp 中的代码


  size_t non_young_capacity_bytes() {
    return (_old_set.length() + _humongous_set.length()) * HeapRegion::GrainBytes;
  }

答案2

(current old generation size/Current total Heap size)*100 我有一个带有 -Xmx12g -Xms12g -IHOP45% 的 jvm 进程。当 Eden:6.5G、Old:4.5G、Sur:8M 时,它会触发 YGC(不是混合 gc)。4.5/12<45%(正常)

11g/12g>45%(应该混合 gc 但不要。)

相关内容