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