Bug 452489 - Fixes OOM predicate on OSSO to use the high water mark. r=bsmedberg
authorDoug Turner <dougt@meer.net>
Fri, 05 Sep 2008 17:21:36 -0700
changeset 18872 1799243b908953cfef4cc2610ffae1e8c90a0680
parent 18871 825b049918201d06b80d89f7f47b583b7b19cb90
child 18873 e24e4d273f8c2bb8809175d3779785c1e619fca8
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs452489
milestone1.9.1b1pre
Bug 452489 - Fixes OOM predicate on OSSO to use the high water mark. r=bsmedberg
xpcom/base/nsMemoryImpl.cpp
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -52,16 +52,19 @@
 #include "nsCOMPtr.h"
 #include "nsString.h"
 
 #if defined(XP_WIN)
 #include <windows.h>
 #define NS_MEMORY_FLUSHER
 #elif defined (NS_OSSO)
 #include <osso-mem.h>
+#include <fcntl.h>
+#include <unistd.h>
+const char* kHighMark = "/sys/kernel/high_watermark";
 #else
 // Need to implement the nsIMemory::IsLowMemory() predicate
 #undef NS_MEMORY_FLUSHER
 #endif
 
 #ifdef NS_MEMORY_FLUSHER
 #include "nsITimer.h"
 #endif
@@ -187,25 +190,25 @@ nsMemoryImpl::IsLowMemory(PRBool *result
     MEMORYSTATUS stat;
     GlobalMemoryStatus(&stat);
     *result = ((float)stat.dwAvailPhys / stat.dwTotalPhys) < 0.1;
 #elif defined(XP_WIN)
     MEMORYSTATUS stat;
     GlobalMemoryStatus(&stat);
     *result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;
 #elif defined(NS_OSSO)
-    osso_mem_usage_t usage;
-    osso_mem_get_usage(&usage);
-    
-    // According to the docs, low memory limit isn't set if it is
-    // zero, or if it is greater than 100%.
-    if (usage.low == 0 || usage.low > usage.total)
-      *result = PR_FALSE;
-    else
-      *result = (PRBool) usage.low <= usage.used;
+    int fd = open (kHighMark, O_RDONLY);
+    if (fd == -1) {
+        *result = PR_FALSE;
+        return NS_OK;
+    }
+    int c = 0;
+    read (fd, &c, 1);
+    close(fd);
+    *result = (c == '1');
 #else
     *result = PR_FALSE;
 #endif
     return NS_OK;
 }
 
 
 /*static*/ nsresult