Skip to content

Commit 5082458

Browse files
TheRealMDoerrRealCLanger
authored andcommitted
SapMachine (21) #2109: Linux: Configuration of glibc malloc arenas should be possible
1 parent d89fa88 commit 5082458

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/hotspot/os/linux/globals_linux.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
"omitted.\n" \
113113
"Example: \"-XX:HiMemReportExec=GC.class_histogram -all;GC.heap_dump\"") \
114114
\
115+
/* SapMachine 2025-11-24: Configurable limit of malloc arenas */ \
116+
product(int, GlibcMallocArenas, 0, \
117+
"Limit glibc malloc arenas, 0 means use OS default, " \
118+
"1 minimizes memory utilization (our default in later releases)") \
119+
\
115120
product(bool, UseCpuAllocPath, false, DIAGNOSTIC, \
116121
"Use CPU_ALLOC code path in os::active_processor_count ") \
117122
\

src/hotspot/os/linux/os_linux.cpp

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

46904690
Linux::fast_thread_clock_init();
46914691

4692+
// SapMachine 2025-11-24:
4693+
// By default, glibc allocates a new 64 (or 128) MB malloc arena for every
4694+
// thread (up to a certain limit which is typically 8 * processor count).
4695+
// This is good for few threads which perform a lot of concurrent mallocs,
4696+
// but it doesn't fit well to the JVM which has its own memory management
4697+
// and rather allocates fewer and larger chunks.
4698+
// Using only one arena significantly reduces virtual memory footprint and
4699+
// fragmentation. Saving memory seems to be more valuable for the JVM than
4700+
// optimizing concurrent mallocs.
4701+
#ifdef __GLIBC__
4702+
if (GlibcMallocArenas > 0) {
4703+
mallopt(M_ARENA_MAX, GlibcMallocArenas);
4704+
}
4705+
#endif
4706+
46924707
if (PosixSignals::init() == JNI_ERR) {
46934708
return JNI_ERR;
46944709
}

0 commit comments

Comments
 (0)