Build: Limit default max metaspace for test processes

Some test proceses grow much bigger than max heap size. Metaspace also
should be limited to avoid OOM Killer events.

 #KTI-1609
This commit is contained in:
Vyacheslav Gerasimov
2024-03-02 14:59:19 +01:00
committed by Space Team
parent 4e6451c25e
commit 93e8b18cde
@@ -133,6 +133,7 @@ fun Project.projectTest(
jUnitMode: JUnitMode = JUnitMode.JUnit4, jUnitMode: JUnitMode = JUnitMode.JUnit4,
maxHeapSizeMb: Int? = null, maxHeapSizeMb: Int? = null,
minHeapSizeMb: Int? = null, minHeapSizeMb: Int? = null,
maxMetaspaceSizeMb: Int = 512,
reservedCodeCacheSizeMb: Int = 256, reservedCodeCacheSizeMb: Int = 256,
defineJDKEnvVariables: List<JdkMajorVersion> = emptyList(), defineJDKEnvVariables: List<JdkMajorVersion> = emptyList(),
body: Test.() -> Unit = {}, body: Test.() -> Unit = {},
@@ -211,18 +212,19 @@ fun Project.projectTest(
"-XX:+HeapDumpOnOutOfMemoryError", "-XX:+HeapDumpOnOutOfMemoryError",
"-XX:+UseCodeCacheFlushing", "-XX:+UseCodeCacheFlushing",
"-XX:ReservedCodeCacheSize=${reservedCodeCacheSizeMb}m", "-XX:ReservedCodeCacheSize=${reservedCodeCacheSizeMb}m",
"-XX:MaxMetaspaceSize=${maxMetaspaceSizeMb}m",
"-Djna.nosys=true" "-Djna.nosys=true"
) )
val junit5ParallelTestWorkers = val junit5ParallelTestWorkers =
project.kotlinBuildProperties.junit5NumberOfThreadsForParallelExecution ?: Runtime.getRuntime().availableProcessors() project.kotlinBuildProperties.junit5NumberOfThreadsForParallelExecution ?: Runtime.getRuntime().availableProcessors()
val memoryPerTestProcessMb = maxHeapSizeMb ?: if (jUnitMode == JUnitMode.JUnit5) val memoryPerTestProcessMb = if (jUnitMode == JUnitMode.JUnit5)
totalMaxMemoryForTestsMb.coerceIn(defaultMaxMemoryPerTestWorkerMb, defaultMaxMemoryPerTestWorkerMb * junit5ParallelTestWorkers) totalMaxMemoryForTestsMb.coerceIn(defaultMaxMemoryPerTestWorkerMb, defaultMaxMemoryPerTestWorkerMb * junit5ParallelTestWorkers)
else else
defaultMaxMemoryPerTestWorkerMb defaultMaxMemoryPerTestWorkerMb
maxHeapSize = "${memoryPerTestProcessMb}m" maxHeapSize = "${maxHeapSizeMb ?: (memoryPerTestProcessMb - maxMetaspaceSizeMb)}m"
usesService(concurrencyLimitService) usesService(concurrencyLimitService)
if (minHeapSizeMb != null) { if (minHeapSizeMb != null) {