Skip to content

Commit

Permalink
Merge pull request #1165 from square/rick/dynamic-github-action-runne…
Browse files Browse the repository at this point in the history
…r-memory

set GHA runner max heap size dynamically based upon runner hardware
  • Loading branch information
RBusarow authored Feb 6, 2024
2 parents a7f0ebb + ee46891 commit d31c843
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions .github/actions/gradle-args/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,44 @@ runs:
run: |
runnerOS=$RUNNER_OS
# Set common JVM arguments
jvmArgs="-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
totalMemory=0
# How much memory does the OS require?
memoryOverhead=0
case $runnerOS in
macOS)
jvmArgs="-Xmx10g -XX:MaxMetaspaceSize=5g $jvmArgs"
totalMemory=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024+0.5)}')
memoryOverhead=3
;;
Linux)
jvmArgs="-Xmx4g -XX:MaxMetaspaceSize=3g $jvmArgs"
totalMemory=$(awk '/MemTotal/ {print int($2/1024/1024+0.5)}' /proc/meminfo)
memoryOverhead=3
;;
Windows)
jvmArgs="-Xmx3g -XX:MaxMetaspaceSize=756m $jvmArgs"
# Fetch and parse memory in MB, then convert to GB
totalMemory=$(powershell -Command "& { [Math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) }")
# Check if totalMemory is a valid number
if ! [[ "$totalMemory" =~ ^[0-9]+$ ]]; then
echo "Failed to retrieve or parse total memory: $totalMemory"
exit 1
fi
memoryOverhead=3
;;
*)
echo "Unsupported runner OS: $runnerOS"
exit 1
;;
esac
availableMemory=$((totalMemory - memoryOverhead))
echo " total memory: $totalMemory"
echo " memory overhead: $memoryOverhead"
echo "available memory: $availableMemory"
jvmArgs="-Xmx${availableMemory}g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
propertyArgs="-Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false"
echo "gradle-property-args=$propertyArgs" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit d31c843

Please sign in to comment.