Skip to content

Instantly share code, notes, and snippets.

@ajbrown
Created December 17, 2016 17:49
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 ajbrown/70dd0b4405e353a5ed13175ba94d6c0e to your computer and use it in GitHub Desktop.
Save ajbrown/70dd0b4405e353a5ed13175ba94d6c0e to your computer and use it in GitHub Desktop.
Dynamically determine the Java heap based on the total memory of the VM.
#!/usr/bin/env bash
totalMemKB=$(awk '/MemTotal:/ { print $2 }' /proc/meminfo)
usagePercent=70
let heapMB=$totalMemKB*$usagePercent/100/1024
JAV_OPTS="$JAVA_OPTS -Xmx${heapMB}M -Xms${heapMB}M"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment