Java: what determines the maximum maximum heap size in linux machine

I have two Linux machines (both are virtual machines), one of which has 12 GB of memory, and the other is 8 GB.

I tried to run the same java program on both machines with the maximum maximum heap size (using the -Xmx flag). Below are the results that I got.

  • 12GB machine: 9460MB
  • 8GB machine: 4790MB

If I specify the maximum heap size beyond the above limits, I get below error.

Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes

I checked the free memory on two systems (using the command free) and I got the following.

  • 12GB machine: approximately 3GB free.
  • 8GB machine: approximately 4GB free.

, , java-, ? ( 1073741824 , )

+4
3

, ravindra, , , .

( ) :

ulimit-v

:

ulimit -v <new amount in KB>

2 , . ulimit -v unlimited, .

+1

JDK bug ( JDK 9, 8. , ​​ 8. x, .

"ulimit -v", , JVM GC.

// After "ulimit -v" The jvm does not start with default command line. 
$ ulimit -S -v 4194304
$ java -version
Error occurred during initialization of VM
Could not allocate metaspace: 1073741824 bytes

:

, MALLOC_ARENA_MAX.

MALLOC_ARENA_MAX = 4, jvm - .

, , jvm. , .

"UseConcMarkSweepGC" . MaxMetaspaceSize = 128m, . , , , . GC .

.

ulimit -S -v 4194304 
java -XX:MaxHeapSize=512m -XX:InitialHeapSize=512m -XX:CompressedClassSpaceSize=64m -XX:MaxMetaspaceSize=128m -XX:+UseConcMarkSweepGC -version
+3

- . , overcommit - , ​​ , ( ), , .

, overcommit . , 2 /proc/sys/vm/overcommit_memory. ( , 0 " ".) overcommit.

0

Source: https://habr.com/ru/post/1616454/


All Articles