initial Java heap size means?

北战南征 提交于 2019-12-10 16:32:20

问题


So i got a program who use Java heap

-Xms5g -Xmx12g 

I have set the initial Java heap size to 5gb and MAX heap size to 12gb

But when i look in task manager or resource monitor, My program is only using 400mb.

So here are my questions:

  1. What does initial Java heap size means?
  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? As initial heap means minimum size right?

回答1:


The -Xmx maximum heap size is the largest size the heap can grow up to.

The -Xms initial heap size is the of the extents of the heap. It won't use more than this amount of space without triggering a full GC.

However this heap is divided into regions e.g. say you have a 5 GiB initial heap with

  • an Eden size of 200 MB
  • two survivor spaces of 100 MB
  • a tenured space of 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)

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). The survivors spaces will get used after a couple of minor collection however initially they might not be all touched e.g. 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.

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.

At this point even though the extents are 5 GB, only 200 + 2 * 50 + 100 MB of memory has been touched or allocated.

In short, Linux allocates pages lazily so you have to write to them to use memory.




回答2:


The simplest program below started with -Xms5g argument takes 5+ GB of memory

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"?



来源:https://stackoverflow.com/questions/51399604/initial-java-heap-size-means

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!