I want my JVM to give back memory to the OS if it's not using it. I don't care about performance.
When I set -Xms128m -Xmx4g, I see the JVM's memory usage grow while indexing and searching, but it never shrinks again afterwards. For most of my projects it will grow to about 2GB.
I am positive that it doesn't need all that memory, because most of my projects run fine with -Xmx256m and JVM memory will remain at around 0.5GB.
It will predictably crash with the largest projects. I would like to set a large enough heap size to be safe, without unnecessarily paying >1GB for this.
Which ES settings or JVM flags can I use for this?
Using ES 7.17 on a Windows Server 2022 with the JVM included with ES.
Basically, you would need to set -XX:MaxHeapFreeRatio to make the JVM free memory when the maximum is reached and -XX:-ShrinkHeapInSteps to false so the process of freeing RAM takes place immediately.
This should work as the included Java version is Java12+ and the jvm.options make use of the G1 garbage collector.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.