I have started facing Native memory allocation issue. I guess could be related with the -Xmx and -Xms settings. What is the recommended way to set this values ?
Currentl
Possible solutions:
-Xmx
/-Xms
)-Xss
)-XX:ReservedCodeCacheSize=
You are clearly asking for a lot more than is physically available on your system. You have 16GB total but it's 90% in use, and you don't have any swap space, so there's no way you're getting -Xms6G
let alone more (-Xmx13G
).
You need to figure out what other processes are consuming memory using, for instance, top
and sort by resident memory (upper-case letter O
, then q
), and stop enough of them to free up at least 6GB before running your JVM.
That, or double your physical memory to 32GB, or add 16GB of swap (but that could result in thrashing if the system is heavily loaded).
Jim Garrison provided a good answer as to why op is getting that issue.
I would like to address a secondary question of the op:
I read that is recommended to set same values but without any explanation of why.
Basically, the JVM will allocate whatever you put in -Xms
as soon as the JVM starts, then grow as required to -Xmx
, once that is reached, it goes garbage collecting (flushing things no longer used).
Running GC on lots of objects (here 7Gb worth of objects) is not a good idea because it will take time and a lot of resources. Setting them to the same value is OK, as GC is collected along the way. GC has operations that are "stop-the-world", where nothing else can run while garbage is collected. Now imagine cleaning up 7Gb of garbage, that is going to take a non-negligible amount of time and cause long pauses.
You really should read https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/introduction.html