From b84226543b5cf8dc8a24863fe6869bac6c0572c2 Mon Sep 17 00:00:00 2001 From: "jam.xu" Date: Thu, 9 Jul 2026 10:49:03 +0800 Subject: [PATCH] [CORE] Log error when -Xms equals -Xmx makes JVM heap shrinking ineffective --- .../memtarget/DynamicOffHeapSizingMemoryTarget.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gluten-core/src/main/java/org/apache/gluten/memory/memtarget/DynamicOffHeapSizingMemoryTarget.java b/gluten-core/src/main/java/org/apache/gluten/memory/memtarget/DynamicOffHeapSizingMemoryTarget.java index 5898ae45e2..ed5be45e8b 100644 --- a/gluten-core/src/main/java/org/apache/gluten/memory/memtarget/DynamicOffHeapSizingMemoryTarget.java +++ b/gluten-core/src/main/java/org/apache/gluten/memory/memtarget/DynamicOffHeapSizingMemoryTarget.java @@ -105,6 +105,18 @@ public class DynamicOffHeapSizingMemoryTarget implements MemoryTarget, KnownName ORIGINAL_MIN_HEAP_FREE_RATIO = originalMinHeapFreeRatio; ORIGINAL_MAX_HEAP_FREE_RATIO = originalMaxHeapFreeRatio; + long maxMem = Runtime.getRuntime().maxMemory(); + long initTotalMem = Runtime.getRuntime().totalMemory(); + if (initTotalMem >= maxMem * 0.95) { + LOG.error( + "JVM heap appears fixed or nearly fixed (totalMemory={}, maxMemory={}). " + + "This typically means -Xms is equal or close to -Xmx. " + + "Explicit JVM shrinking will not be effective because the JVM " + + "cannot return committed heap to the OS.", + initTotalMem, + maxMem); + } + if (!isJava9OrLater()) { // For JDK 8, we cannot change MaxHeapFreeRatio programmatically at runtime. LOG.error("Dynamic off-heap sizing is not supported before JDK 9.");