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 wh
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
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.