EdColeman commented on code in PR #3508:
URL: https://github.com/apache/accumulo/pull/3508#discussion_r1238705061


##########
server/base/src/main/java/org/apache/accumulo/server/mem/LowMemoryDetector.java:
##########
@@ -135,48 +134,55 @@ public void logGCInfo(AccumuloConfiguration conf) {
         prevGcTime.put(gcBean.getName(), time);
       }
 
-      long mem = rt.freeMemory();
-      if (maxIncreaseInCollectionTime == 0) {
-        gcTimeIncreasedCount = 0;
-      } else {
-        gcTimeIncreasedCount++;
-        if (gcTimeIncreasedCount > 3 && mem < rt.maxMemory() * 
freeMemoryPercentage) {
+      Runtime rt = Runtime.getRuntime();
+      final long maxConfiguredMemory = rt.maxMemory();
+      final long allocatedMemory = rt.totalMemory();
+      final long allocatedFreeMemory = rt.freeMemory();
+      final long freeMemory = maxConfiguredMemory - (allocatedMemory - 
allocatedFreeMemory);
+      final double lowMemoryThreshold = maxConfiguredMemory * 
freeMemoryPercentage;
+      LOG.trace("Memory info: max={}, allocated={}, free={}, free 
threshold={}",
+          maxConfiguredMemory, allocatedMemory, freeMemory, (long) 
lowMemoryThreshold);
+
+      if (freeMemory < (long) lowMemoryThreshold) {
+        lowMemCount++;
+        if (lowMemCount > 3 && !runningLowOnMemory) {
           runningLowOnMemory = true;
-          log.warn("Running low on memory");
-          gcTimeIncreasedCount = 0;
+          LOG.warn("Running low on memory: max={}, allocated={}, free={}, free 
threshold={}",
+              maxConfiguredMemory, allocatedMemory, freeMemory, (long) 
lowMemoryThreshold);
+        }
+      } else {
+        // If we were running low on memory, but are not any longer, than log 
at warn
+        // so that it shows up in the logs
+        if (runningLowOnMemory) {
+          LOG.warn("Recovered from low memory condition");
         } else {
-          // If we were running low on memory, but are not any longer, than 
log at warn
-          // so that it shows up in the logs
-          if (runningLowOnMemory) {
-            log.warn("Recovered from low memory condition");
-          } else {
-            log.trace("Not running low on memory");
-          }
-          runningLowOnMemory = false;
+          LOG.trace("Not running low on memory");
         }
+        runningLowOnMemory = false;
+        lowMemCount = 0;
       }
 
-      if (mem != lastMemorySize) {
+      if (freeMemory != lastMemorySize) {
         sawChange = true;
       }
 
       String sign = "+";
-      if (mem - lastMemorySize <= 0) {
+      if (freeMemory - lastMemorySize <= 0) {
         sign = "";
       }
 
-      sb.append(String.format(" freemem=%,d(%s%,d) totalmem=%,d", mem, sign, 
(mem - lastMemorySize),
-          rt.totalMemory()));
+      sb.append(String.format(" freemem=%,d(%s%,d) totalmem=%,d", freeMemory, 
sign,
+          (freeMemory - lastMemorySize), rt.totalMemory()));

Review Comment:
   Addressed in 3ed08fc601



-- 
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]

Reply via email to