Confusing memory settings on Ubuntu

When I install ES from a .deb package on Ubuntu, it creates /etc/default/elasticsearch with something like this:

ES_HEAP_SIZE=2g
ES_MIN_MEM=512m
ES_MAX_MEM=2g
ES_JAVA_OPTS="-Xmx2048m -Xms512m"

All these things are passed as environment variables inside the actual startup script.

Aren't all those settings redundant? Can I just set ES_HEAP_SIZE and call it a day?

Or do I have to also set -Xmx and -Xms? And if this is the case, do I need to set -Xmx bigger than heap?

How would you change that list of variables, if any changes are required? I'm not talking about the actual heap size and whatnot, but I'm curious whether it makes sense to maintain that list, and how the various values should be correlated, if at all.

Once you define ES_HEAP_SIZE the script will set MIN & MAX:

$ cd /usr/share/elasticsearch/bin
$ grep ES_HEAP_SIZE elasticsearch.in.sh 
if [ "x$ES_HEAP_SIZE" != "x" ]; then
    ES_MIN_MEM=$ES_HEAP_SIZE
    ES_MAX_MEM=$ES_HEAP_SIZE

So yes they are redundant but they are there should you want to set them differently. So you can just set ES_HEAP_SIZE and comment out ES_MIN_MEM, ES_MAX_MEM & ES_JAVA_OPTS and to avoid any confusion if they are defined in your /etc/default/elasticsearch.

1 Like