9e34db6
From 6d6fa2888fc450dd21a36445d9defa93ea2155ee Mon Sep 17 00:00:00 2001
9e34db6
From: Mark Reynolds <mreynolds@redhat.com>
9e34db6
Date: Thu, 6 Sep 2012 13:21:27 -0400
9e34db6
Subject: [PATCH] Ticket 386 - Overconsumption of memory with large cachememsize and heavy use of ldapmodify
9e34db6
9e34db6
Bug Description:  With very large entry cache setting, the memory process grows using just
9e34db6
                  simple ldapmodifies.
9e34db6
9e34db6
Fix Description:  The growth is caused by memory fragmentation.   On Linux, we can set a
9e34db6
                  malloc option that impacts this fragmentation, but impacts performance.
9e34db6
9e34db6
https://fedorahosted.org/389/ticket/386
9e34db6
9e34db6
Reviewed by: richm(Thanks!)
9e34db6
(cherry picked from commit 20dc4bc00b2660e951c1b50008115ef5611a5e24)
9e34db6
---
9e34db6
 ldap/servers/slapd/main.c |   15 ++++++++++++++-
9e34db6
 1 files changed, 14 insertions(+), 1 deletions(-)
9e34db6
9e34db6
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
9e34db6
index 3455852..285cf2c 100644
9e34db6
--- a/ldap/servers/slapd/main.c
9e34db6
+++ b/ldap/servers/slapd/main.c
9e34db6
@@ -40,7 +40,7 @@
9e34db6
 #  include <config.h>
9e34db6
 #endif
9e34db6
 
9e34db6
-
9e34db6
+#include <malloc.h>
9e34db6
 #include <ldap.h>
9e34db6
 #undef OFF
9e34db6
 #undef LITTLE_ENDIAN
9e34db6
@@ -662,6 +662,19 @@ main( int argc, char **argv)
9e34db6
 		ldap_set_option( 0x1, LDAP_OPT_MEMALLOC_FN_PTRS, &memalloc_fns );
9e34db6
 	}
9e34db6
 #endif
9e34db6
+
9e34db6
+#ifdef LINUX
9e34db6
+	char *m = getenv( "SLAPD_MXFAST" );
9e34db6
+	if(m){
9e34db6
+		int val = atoi(m);
9e34db6
+		int max = 80 * (sizeof(size_t) / 4);
9e34db6
+
9e34db6
+		if(val >= 0 && val <= max){
9e34db6
+			mallopt(M_MXFAST, val);
9e34db6
+		}
9e34db6
+	}
9e34db6
+#endif
9e34db6
+
9e34db6
 	/*
9e34db6
 	 * Initialize NSPR very early. NSPR supports implicit initialization,
9e34db6
 	 * but it is not bulletproof -- so it is better to be explicit.
9e34db6
-- 
9e34db6
1.7.1
9e34db6