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.