From ec621137a2314eef19fed1c452b29bece102905b Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Tue, 19 Mar 2024 11:04:57 +0100 Subject: [PATCH] Build: Set MALLOC_ARENA_MAX for test processes to reduce memory overhead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The glibc default number of memory pools on 64bit systems is 8 times the number of CPU cores. Choosing a value MALLOC_ARENA_MAX is generally a tradeoff between performance and memory consumption. Not setting MALLOC_ARENA_MAX gives the best performance, but may mean higher memory use. Setting MALLOC_ARENA_MAX to “2” or “1” makes glibc use fewer memory pools and potentially less memory, but this may reduce performance. #KTI-1609 --- .../buildsrc-compat/src/main/kotlin/tasks.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/tasks.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/tasks.kt index 00a02788932..c9cbc93764a 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/tasks.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/tasks.kt @@ -203,6 +203,13 @@ fun Project.projectTest( dependsOn(":test-instrumenter:jar") } + // The glibc default number of memory pools on 64bit systems is 8 times the number of CPU cores + // Choosing a value MALLOC_ARENA_MAX is generally a tradeoff between performance and memory consumption. + // Not setting MALLOC_ARENA_MAX gives the best performance, but may mean higher memory use. + // Setting MALLOC_ARENA_MAX to “2” or “1” makes glibc use fewer memory pools and potentially less memory, + // but this may reduce performance. + environment("MALLOC_ARENA_MAX", "2") + jvmArgs( "-ea", "-XX:+HeapDumpOnOutOfMemoryError",