性能问答>CMS不是按照NewRatio参数来控制新生代大小吗(elasticsearch7.5的参数)>
5回复
2年前

CMS不是按照NewRatio参数来控制新生代大小吗(elasticsearch7.5的参数)



根据

jinfo -flags 15786

的信息如下:
-XX:+AlwaysPreTouch
-XX:CICompilerCount=4
-XX:CMSInitiatingOccupancyFraction=85
-XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log
-XX:+HeapDumpBeforeFullGC
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/var/lib/elasticsearch
-XX:InitialHeapSize=10737418240
-XX:MaxDirectMemorySize=5368709120
-XX:MaxHeapSize=10737418240
-XX:MaxTenuringThreshold=6
-XX:MinHeapDeltaBytes=196608
-XX:MinHeapSize=10737418240
-XX:NonNMethodCodeHeapSize=5836300
-XX:NonProfiledCodeHeapSize=122910970
-XX:MaxNewSize=697892864
-XX:NewSize=697892864
-XX:OldSize=10039525376
-XX:-OmitStackTraceInFastThrow
-XX:ProfiledCodeHeapSize=122910970
-XX:ReservedCodeCacheSize=251658240
-XX:+SegmentedCodeCache
-XX:SoftMaxHeapSize=10737418240
-XX:ThreadStackSize=1024
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+UseCompressedClassPointers
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC

特别是 NewSize=660M OldSize=9574M
这个数字 和

jinfo -flag NewRatio 15786
XX:NewRatio=2

不符啊。

InitialHeapSize=10737418240 = 10g
根据 NewRatio=2 
新生代不应该是 是 10g * 0.3 = 3.33g吗 怎么才660M呢

我是新手,请大神原谅我的白痴问题,并不吝赐教。

5084 阅读
请先登录,再评论
  size_t young_gen_per_worker = CMSYoungGenPerWorker;

  // Preferred young gen size for "short" pauses:
  // upper bound depends on # of threads and NewRatio.
  const size_t preferred_max_new_size_unaligned =
    MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * ParallelGCThreads));
  size_t preferred_max_new_size =
    align_up(preferred_max_new_size_unaligned, os::vm_page_size());

  // Unless explicitly requested otherwise, size young gen
  // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads

  // If either MaxNewSize or NewRatio is set on the command line,
  // assume the user is trying to set the size of the young gen.
  if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {

    // Set MaxNewSize to our calculated preferred_max_new_size unless
    // NewSize was set on the command line and it is larger than
    // preferred_max_new_size.
    if (!FLAG_IS_DEFAULT(NewSize)) {   // NewSize explicitly set at command-line
      FLAG_SET_ERGO(size_t, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
    } else {
      FLAG_SET_ERGO(size_t, MaxNewSize, preferred_max_new_size);
    }
    log_trace(gc, heap)("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);

    // Code along this path potentially sets NewSize and OldSize
    log_trace(gc, heap)("CMS set min_heap_size: " SIZE_FORMAT " initial_heap_size:  " SIZE_FORMAT " max_heap: " SIZE_FORMAT,
                        Arguments::min_heap_size(), InitialHeapSize, max_heap);
    size_t min_new = preferred_max_new_size;
    if (FLAG_IS_CMDLINE(NewSize)) {
      min_new = NewSize;
    }
    if (max_heap > min_new && Arguments::min_heap_size() > min_new) {
      // Unless explicitly requested otherwise, make young gen
      // at least min_new, and at most preferred_max_new_size.
      if (FLAG_IS_DEFAULT(NewSize)) {
        FLAG_SET_ERGO(size_t, NewSize, MAX2(NewSize, min_new));
        FLAG_SET_ERGO(size_t, NewSize, MIN2(preferred_max_new_size, NewSize));
        log_trace(gc, heap)("CMS ergo set NewSize: " SIZE_FORMAT, NewSize);
      }
      // Unless explicitly requested otherwise, size old gen
      // so it's NewRatio x of NewSize.
      if (FLAG_IS_DEFAULT(OldSize)) {
        if (max_heap > NewSize) {
          FLAG_SET_ERGO(size_t, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize));
          log_trace(gc, heap)("CMS ergo set OldSize: " SIZE_FORMAT, OldSize);
        }
      }
    }
  }

可以看下这块的逻辑,MaxNewSize并不是完全由NewRatio决定的,和CMSYoungGenPerWorker以及ParallelGCThreads有关,可以jinfo看下这两个参数在你平台下的值

另外可以参考下下面的宏定义

#define ScaleForWordSize(x) align_down_((x) * 13 / 10, HeapWordSize)
12年前
回复 你假笨:
jinfo -flag CMSYoungGenPerWorker 32561
-XX:CMSYoungGenPerWorker=67108864

jinfo -flag ParallelGCThreads 32561
-XX:ParallelGCThreads=8

明白了,感谢笨神

2年前回复

找到一篇大佬的回答,非常详细
https://www.cnblogs.com/micrari/p/8831834.html
image.png

22年前

jps -v看看你设置的JVM参数,通过jinfo看到的参数偏多,不好判断

2年前

image.png

2年前