简体   繁体   English

初始Java堆大小意味着什么?

[英]initial Java heap size means?

So i got a program who use Java heap 所以我有一个使用Java堆的程序

-Xms5g -Xmx12g 

I have set the initial Java heap size to 5gb and MAX heap size to 12gb 我已将初始Java堆大小设置为5gb,将最大堆大小设置为12gb

But when i look in task manager or resource monitor, My program is only using 400mb. 但是当我查看任务管理器或资源监视器时,我的程序仅使用400mb。

So here are my questions: 所以这是我的问题:

  1. What does initial Java heap size means? 初始Java堆大小是什么意思?
  2. How come if i set initial Java heap size to 5gb, i only see the RAM use on the program to 400mb, should it not be 5gb? 如果我将初始Java堆大小设置为5gb,为什么我只看到程序上的RAM使用为400mb,而不是5gb,怎么会这样呢? As initial heap means minimum size right? 因为初始堆意味着最小大小,对吗?

The -Xmx maximum heap size is the largest size the heap can grow up to. -Xmx最大堆大小是堆可以增长到的最大大小。

The -Xms initial heap size is the of the extents of the heap. -Xms初始堆大小是堆范围的大小。 It won't use more than this amount of space without triggering a full GC. 在不触发完整GC的情况下,它不会使用超过此数量的空间。

However this heap is divided into regions eg say you have a 5 GiB initial heap with 但是,该堆分为多个区域,例如说您有一个5 GiB的初始堆,

  • an Eden size of 200 MB 伊甸园大小为200 MB
  • two survivor spaces of 100 MB 两个100 MB的幸存者空间
  • a tenured space of 4.6 GB. 4.6 GB的租用空间。

When you start using the memory, the pages (4 KiB regions) which are touched are allocated on demand on Linux (unless you use an option to pretouch them all) 当您开始使用内存时,在Linux上按需分配了被触摸的页面(4 KiB区域)(除非您使用选项来对它们全部进行预修饰)

Your Eden space will be used pretty quickly so the first 200 MB gets used quite fast (quite a lot if used even before main is called). 您的Eden空间将很快被使用,因此前200 MB的使用速度非常快(如果在调用main之前就已经使用了很多)。 The survivors spaces will get used after a couple of minor collection however initially they might not be all touched eg say they never fill to more than 50 MB each (of the 100 MB available), the total memory touched at this point is 200 MB + 2 * 50 MB. 幸存者空间将在几次较小的收集之后使用,但是最初它们可能不会被全部使用,例如说它们从未填充到超过50 MB(100 MB可用空间中),此时触摸的总内存为200 MB + 2 * 50 MB。

Some large objects go straight into tenured space, however for most applications, the tenured space is largely taken up with smaller, long lived objects. 一些大的对象直接进入租用空间,但是对于大多数应用程序,租用空间在很大程度上占用了较小的,寿命长的对象。 Lets say after many minor collections, about 100 MB of objects have been promoted to tenured space. 可以说,在进行了许多次较小的收集之后,大约100 MB的对象已被提升到永久性空间。

At this point even though the extents are 5 GB, only 200 + 2 * 50 + 100 MB of memory has been touched or allocated. 此时,即使扩展区为5 GB,也只能触摸或分配200 + 2 * 50 + 100 MB的内存。

In short, Linux allocates pages lazily so you have to write to them to use memory. 简而言之,Linux延迟分配页面,因此您必须写页面以使用内存。

The simplest program below started with -Xms5g argument takes 5+ GB of memory 下面以-Xms5g参数-Xms5g的最简单的程序占用5 GB以上的内存

public static void main(String[] args) throws Exception {
  Thread.currentThread().join();
}

Either you are looking at wrong process or there is something very special with your platform. 您正在查看错误的流程,或者平台有一些非常特殊的东西。 Could it be that you are on windows and you are looking at "Working Set" instead of "Private Bytes" ? 可能是因为您在Windows上,而是在查看“工作集”而不是“专用字节”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM