Blob Blame Raw
From 9369164f45ba19519158286590aaefae1c64ef05 Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Thu, 5 Oct 2017 09:54:48 +1000
Subject: [PATCH] Ticket 49392 - memavailable not available

Bug Description:  On certain linux platforms memAvailable is
not actually available! This means that the value was 0, so
cgroup max was read instead, setting the system ram to:

9223372036854771712

That's a bit excessive, and can cause memory allocations to fail.

Fix Description:  If memavail can't be found, fall back to
memtotal instead.

https://pagure.io/389-ds-base/issue/49392

Author: wibrown

Review by: mreynolds (Thanks!)
---
 ldap/servers/slapd/slapi_pal.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ldap/servers/slapd/slapi_pal.c b/ldap/servers/slapd/slapi_pal.c
index 38c178cfa..600d03d4d 100644
--- a/ldap/servers/slapd/slapi_pal.c
+++ b/ldap/servers/slapd/slapi_pal.c
@@ -155,7 +155,16 @@ spal_meminfo_get()
 
     /* Both memtotal and memavail are in kb */
     memtotal = memtotal * 1024;
-    memavail = memavail * 1024;
+
+    /*
+     * Oracle Enterprise Linux doesn't provide a valid memavail value, so fall
+     * back to 80% of memtotal.
+     */
+    if (memavail == 0) {
+        memavail = memtotal * 0.8;
+    } else {
+        memavail = memavail * 1024;
+    }
 
     /* If it's possible, get our cgroup info */
     uint64_t cg_mem_soft = 0;
-- 
2.13.6