initial Java heap size means?

pixiline :

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?
Peter Lawrey :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=82257&siteId=1