-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool in bytes.
-XX:NewRatio=old/young By default, this option is set to 2.
-XX:SurvivorRatio=eden/survivor By default, this option is set to 8.
-Xmx3212M -XX:NewRatio=3 -XX:SurvivorRatio=9
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
System.out.println(heapMemoryUsage);
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
if(MemoryType.HEAP.equals(memoryPoolMXBean.getType())) {
System.out.println(memoryPoolMXBean.getName()+"\t"+memoryPoolMXBean.getUsage());
}
}
init = 134217728(131072K) used = 1698944(1659K) committed = 131596288(128512K) max = 3291480064(3214336K)
PS Eden Space init = 28311552(27648K) used = 1698944(1659K) committed = 28311552(27648K) max = 836763648(817152K)
PS Survivor Space init = 2621440(2560K) used = 0(0K) committed = 2621440(2560K) max = 2621440(2560K)
PS Old Gen init = 100663296(98304K) used = 0(0K) committed = 100663296(98304K) max = 2526019584(2466816K)
For example, setting -XX:NewRatio=3 means that the ratio between the young and tenured generation is 1:3. In other words, the combined size of the eden and survivor spaces will be one-fourth of the total heap size.
For example, -XX:SurvivorRatio=6 sets the ratio between eden and a survivor space to 1:6. In other words, each survivor space will be one-sixth the size of eden, and thus one-eighth the size of the young generation (not one-seventh, because there are two survivor spaces).
1
c4f36e5766583218 OP https://blog.csdn.net/fanwu72/article/details/8936746
```结论:init 约等于 xms 的值,max 约等于 xmx 的值。used 是已经被使用的内存大小,committed 是当前可使用的内存大小(包括已使用的),committed >= used。committed 不足时 jvm 向系统申请,若超过 max 则发生 OutOfMemoryError 错误。``` committed 初始运行时候约等于 init,然后随着使用 /gc 增大 /减小(与 init 无关) |
2
c4f36e5766583218 OP 猜测: XX:NewRatio XX:SurvivorRatio 可以使用 committed 列来算,可能之前选的值不太好,试了下```-XX:NewRatio=3 -XX:SurvivorRatio=6```是符合的
|
3
c4f36e5766583218 OP @c4f36e5766583218 #2 好像不对。重新猜测:
* XX:NewRatio XX:SurvivorRatio 可能之前选的值不太好,试```-XX:NewRatio=3 -XX:SurvivorRatio=6``` * PS Survivor Space 是指其中之一,共 2 个 * 使用 init 值来计算 * HeapMemory.init = (Eden.init + Survivor.init * 2) + Old.init * Old.init / (Eden.init + Survivor.init * 2) = 3 * Eden.init / Survivor.init = 6 |