Skip to content

Commit 3b28f37

Browse files
committed
set GHA runner max heap size dynamically based upon runner hardware
Before this change, we set the max heap size based upon runner OS. That worked well enough, since we only used the free GitHub-hosted runners with well-known hardware. Now that we have two different Ubuntu runner sizes, that older strategy is leaving free memory on the table.
1 parent a7f0ebb commit 3b28f37

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

.github/actions/gradle-args/action.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,40 @@ runs:
2121
run: |
2222
runnerOS=$RUNNER_OS
2323
24-
# Set common JVM arguments
25-
jvmArgs="-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
24+
totalMemory=0
25+
# How much memory does the OS require?
26+
memoryOverhead=0
2627
2728
case $runnerOS in
2829
macOS)
29-
jvmArgs="-Xmx10g -XX:MaxMetaspaceSize=5g $jvmArgs"
30+
totalMemory=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024+0.5)}')
31+
memoryOverhead=3
3032
;;
3133
Linux)
32-
jvmArgs="-Xmx4g -XX:MaxMetaspaceSize=3g $jvmArgs"
34+
totalMemory=$(awk '/MemTotal/ {print int($2/1024/1024+0.5)}' /proc/meminfo)
35+
memoryOverhead=3
3336
;;
3437
Windows)
35-
jvmArgs="-Xmx3g -XX:MaxMetaspaceSize=756m $jvmArgs"
38+
# Fetch and parse memory in MB, then convert to GB
39+
totalMemory=$(powershell -Command "& { [Math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB) }")
40+
41+
# Check if totalMemory is a valid number
42+
if ! [[ "$totalMemory" =~ ^[0-9]+$ ]]; then
43+
echo "Failed to retrieve or parse total memory: $totalMemory"
44+
exit 1
45+
fi
46+
memoryOverhead=3
3647
;;
3748
*)
3849
echo "Unsupported runner OS: $runnerOS"
3950
exit 1
4051
;;
4152
esac
4253
54+
availableMemory=$((totalMemory - memoryOverhead))
55+
56+
jvmArgs="-Xmx${availableMemory}g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"
57+
4358
propertyArgs="-Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false"
4459
4560
echo "gradle-property-args=$propertyArgs" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)