zhouyuan commented on code in PR #9321:
URL: https://github.com/apache/incubator-gluten/pull/9321#discussion_r2044721919


##########
gluten-core/src/main/java/org/apache/gluten/memory/memtarget/DynamicOffHeapSizingMemoryTarget.java:
##########
@@ -43,22 +43,26 @@ public long borrow(long size) {
       return 0;
     }
 
-    long totalMemory = Runtime.getRuntime().totalMemory();
-    long freeMemory = Runtime.getRuntime().freeMemory();
-    long usedOnHeapBytes = (totalMemory - freeMemory);
+    // Only JVM shrinking can reclaim space from the total JVM memory.
+    // See https://github.com/apache/incubator-gluten/issues/9276.
+    long totalHeapMemory = Runtime.getRuntime().totalMemory();
+    long freeHeapMemory = Runtime.getRuntime().freeMemory();
+
     long usedOffHeapBytesNow = USED_OFFHEAP_BYTES.get();
 
-    if (size + usedOffHeapBytesNow + usedOnHeapBytes > MAX_MEMORY_IN_BYTES) {
+    // Adds the total JVM memory which is the actual memory the JVM occupied 
from the operating
+    // system into the counter.
+    if (size + usedOffHeapBytesNow + totalHeapMemory > MAX_MEMORY_IN_BYTES) {

Review Comment:
   I got the idea and this fix looks correct to me
   Cc: @zhli1142015 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to