Skip to content

Instantly share code, notes, and snippets.

@zoran
Last active April 11, 2019 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoran/5ef05b2674a1acc1fc66940286d0fdfb to your computer and use it in GitHub Desktop.
Save zoran/5ef05b2674a1acc1fc66940286d0fdfb to your computer and use it in GitHub Desktop.
Return reasonable JVM options
#!/usr/bin/env bash
CGROUPS_MEM=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
MEMINFO_MEM=$(($(awk '/MemTotal/ {print $2}' /proc/meminfo)*1024))
MEM=$(($MEMINFO_MEM>$CGROUPS_MEM?$CGROUPS_MEM:$MEMINFO_MEM))
JVM_HEAP_RATIO=${JVM_HEAP_RATIO:-0.5}
XMX=$(awk '{printf("%d",$1*$2/1024^2)}' <<<" ${MEM} ${JVM_HEAP_RATIO} ")
echo "-Xmx${XMX}m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment