Skip to content

Commit f481a75

Browse files
SapMachine SAP#2109: Linux: Configuration of glibc malloc arenas should be possible (SAP#2110)
Introduction of switch "GlibcMallocArenas" with default value 1 for minimized memory utilization.
1 parent 4008c98 commit f481a75

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/hotspot/os/linux/globals_linux.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@
8888
"omitted.\n" \
8989
"Example: \"-XX:HiMemReportExec=GC.class_histogram -all;GC.heap_dump\"") \
9090
\
91+
/* SapMachine 2025-11-24: Configurable limit of malloc arenas */ \
92+
product(int, GlibcMallocArenas, 1, \
93+
"Limit glibc malloc arenas, 0 means use OS default, " \
94+
"1 minimizes memory utilization (our default)") \
95+
\
9196
product(bool, UseCpuAllocPath, false, DIAGNOSTIC, \
9297
"Use CPU_ALLOC code path in os::active_processor_count ") \
93-
\
98+
\
9499
product(bool, DumpPerfMapAtExit, false, DIAGNOSTIC, \
95100
"Write map file for Linux perf tool at exit") \
96101
\

src/hotspot/os/linux/os_linux.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,6 +4550,21 @@ jint os::init_2(void) {
45504550

45514551
Linux::fast_thread_clock_init();
45524552

4553+
// SapMachine 2025-11-24:
4554+
// By default, glibc allocates a new 64 (or 128) MB malloc arena for every
4555+
// thread (up to a certain limit which is typically 8 * processor count).
4556+
// This is good for few threads which perform a lot of concurrent mallocs,
4557+
// but it doesn't fit well to the JVM which has its own memory management
4558+
// and rather allocates fewer and larger chunks.
4559+
// Using only one arena significantly reduces virtual memory footprint and
4560+
// fragmentation. Saving memory seems to be more valuable for the JVM than
4561+
// optimizing concurrent mallocs.
4562+
#ifdef __GLIBC__
4563+
if (GlibcMallocArenas > 0) {
4564+
mallopt(M_ARENA_MAX, GlibcMallocArenas);
4565+
}
4566+
#endif
4567+
45534568
if (PosixSignals::init() == JNI_ERR) {
45544569
return JNI_ERR;
45554570
}

0 commit comments

Comments
 (0)