andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From e14789eed0ef35b8c469909ad7c15c7909cf5bd6 Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@redhat.com>
dc8c34
Date: Fri, 7 Feb 2014 16:39:52 -0800
dc8c34
Subject: [PATCH 161/225] Ticket #47693 - Environment variables are not passed
dc8c34
 when DS is started via service
dc8c34
dc8c34
Description: Environment variables (except TERM and LANG) are ignored
dc8c34
if a program is started via service.
dc8c34
dc8c34
If it is started with systemctl, it takes this COMMAND and the values
dc8c34
are correctly passed to the server.
dc8c34
systemctl set-environment SLAPD_MXFAST=0 MALLOC_TRIM_THRESHOLD_=4096
dc8c34
dc8c34
To control them explicitly and to provide the same instructions to
dc8c34
the service and systemctl, it'd be good to have some variables
dc8c34
(SLAPD_MXFAST, MALLOC_TRIM_THRESHOLD_ and MALLOC_MMAP_THRESHOLD_ in
dc8c34
this patch) configurable.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47693
dc8c34
dc8c34
Reviewed by rmeggins@redhat.com (Thank you, Rich!!)
dc8c34
(cherry picked from commit 02169effb14ea082cdfed5377244b4ffedb7c437)
dc8c34
(cherry picked from commit 476a1930ab5cbe2fbee9f94586c000980089ebf2)
dc8c34
(cherry picked from commit ae2e7f4d277a608e8c2a893f15eb9b4c397284cc)
dc8c34
(cherry picked from commit 57199b34c9cbe4a703e537633fbe6beab9a94e81)
dc8c34
---
dc8c34
 ldap/servers/slapd/libglobs.c   | 161 ++++++++++++++++++++++++++++++++++++++++
dc8c34
 ldap/servers/slapd/proto-slap.h |  11 +++
dc8c34
 ldap/servers/slapd/slap.h       |  12 +++
dc8c34
 3 files changed, 184 insertions(+)
dc8c34
dc8c34
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
dc8c34
index 8352fc7..903d38b 100644
dc8c34
--- a/ldap/servers/slapd/libglobs.c
dc8c34
+++ b/ldap/servers/slapd/libglobs.c
dc8c34
@@ -81,6 +81,9 @@
dc8c34
 #endif /* USE_SYSCONF */
dc8c34
 #include "slap.h"
dc8c34
 #include "plhash.h"
dc8c34
+#if defined(LINUX)
dc8c34
+#include <malloc.h>
dc8c34
+#endif
dc8c34
 
dc8c34
 #define REMOVE_CHANGELOG_CMD "remove"
dc8c34
 #define DEFAULT_SASL_MAXBUFSIZE "65536"
dc8c34
@@ -700,6 +703,20 @@ static struct config_get_and_set {
dc8c34
 		NULL, 0,
dc8c34
 		(void**)&global_slapdFrontendConfig.listen_backlog_size, CONFIG_INT,
dc8c34
 		(ConfigGetFunc)config_get_listen_backlog_size},
dc8c34
+#if defined(LINUX)
dc8c34
+	{CONFIG_MALLOC_MXFAST, config_set_malloc_mxfast,
dc8c34
+		NULL, 0,
dc8c34
+		(void**)&global_slapdFrontendConfig.malloc_mxfast,
dc8c34
+		CONFIG_INT, (ConfigGetFunc)config_get_malloc_mxfast},
dc8c34
+	{CONFIG_MALLOC_TRIM_THRESHOLD, config_set_malloc_trim_threshold,
dc8c34
+		NULL, 0,
dc8c34
+		(void**)&global_slapdFrontendConfig.malloc_trim_threshold,
dc8c34
+		CONFIG_INT, (ConfigGetFunc)config_get_malloc_trim_threshold},
dc8c34
+	{CONFIG_MALLOC_MMAP_THRESHOLD, config_set_malloc_mmap_threshold,
dc8c34
+		NULL, 0,
dc8c34
+		(void**)&global_slapdFrontendConfig.malloc_mmap_threshold,
dc8c34
+		CONFIG_INT, (ConfigGetFunc)config_get_malloc_mmap_threshold},
dc8c34
+#endif
dc8c34
 	{CONFIG_IGNORE_TIME_SKEW, config_set_ignore_time_skew,
dc8c34
 		NULL, 0,
dc8c34
 		(void**)&global_slapdFrontendConfig.ignore_time_skew,
dc8c34
@@ -1108,6 +1125,12 @@ FrontendConfig_init () {
dc8c34
 
dc8c34
   cfg->listen_backlog_size = DAEMON_LISTEN_SIZE;
dc8c34
   cfg->ignore_time_skew = LDAP_OFF;
dc8c34
+#if defined(LINUX)
dc8c34
+  cfg->malloc_mxfast = DEFAULT_MALLOC_UNSET;
dc8c34
+  cfg->malloc_trim_threshold = DEFAULT_MALLOC_UNSET;
dc8c34
+  cfg->malloc_mmap_threshold = DEFAULT_MALLOC_UNSET;
dc8c34
+#endif
dc8c34
+
dc8c34
 #ifdef MEMPOOL_EXPERIMENTAL
dc8c34
   cfg->mempool_switch = LDAP_ON;
dc8c34
   cfg->mempool_maxfreelist = 1024;
dc8c34
@@ -6633,6 +6656,144 @@ config_set_auditlog_enabled(int value){
dc8c34
     CFG_UNLOCK_WRITE(slapdFrontendConfig);
dc8c34
 }
dc8c34
 
dc8c34
+#if defined(LINUX)
dc8c34
+int
dc8c34
+config_set_malloc_mxfast(const char *attrname, char *value, char *errorbuf, int apply)
dc8c34
+{
dc8c34
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+    int max = 80 * (sizeof(size_t) / 4);
dc8c34
+    int mxfast;
dc8c34
+    char *endp = NULL;
dc8c34
+
dc8c34
+    if (config_value_is_null(attrname, value, errorbuf, 0)) {
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+    errno = 0;
dc8c34
+    mxfast = strtol(value, &endp, 10);
dc8c34
+    if ((*endp != '\0') || (errno == ERANGE)) {
dc8c34
+        PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
dc8c34
+                    "limit \"%s\" is invalid, %s must range from 0 to %d",
dc8c34
+                    value, CONFIG_MALLOC_MXFAST, max);
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+    CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
dc8c34
+    slapdFrontendConfig->malloc_mxfast = mxfast;
dc8c34
+    CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig);
dc8c34
+
dc8c34
+    if ((mxfast >= 0) && (mxfast <= max)) {
dc8c34
+        mallopt(M_MXFAST, mxfast);
dc8c34
+    } else if (DEFAULT_MALLOC_UNSET != mxfast) {
dc8c34
+        slapi_log_error(SLAPI_LOG_FATAL, "config",
dc8c34
+                        "%s: Invalid value %d will be ignored\n",
dc8c34
+                        CONFIG_MALLOC_MXFAST, mxfast);
dc8c34
+    }
dc8c34
+    return LDAP_SUCCESS;
dc8c34
+}
dc8c34
+
dc8c34
+int
dc8c34
+config_get_malloc_mxfast()
dc8c34
+{
dc8c34
+  slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+  int retVal;
dc8c34
+
dc8c34
+  retVal = slapdFrontendConfig->malloc_mxfast;
dc8c34
+  return retVal; 
dc8c34
+}
dc8c34
+
dc8c34
+int
dc8c34
+config_set_malloc_trim_threshold(const char *attrname, char *value, char *errorbuf, int apply)
dc8c34
+{
dc8c34
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+    int trim_threshold;
dc8c34
+    char *endp = NULL;
dc8c34
+
dc8c34
+    if (config_value_is_null(attrname, value, errorbuf, 0)) {
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+    errno = 0;
dc8c34
+    trim_threshold = strtol(value, &endp, 10);
dc8c34
+    if ((*endp != '\0') || (errno == ERANGE)) {
dc8c34
+        PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
dc8c34
+                    "limit \"%s\" is invalid, %s must range from 0 to %lld",
dc8c34
+                    value, CONFIG_MALLOC_TRIM_THRESHOLD, (long long int)LONG_MAX);
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+
dc8c34
+    CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
dc8c34
+    slapdFrontendConfig->malloc_trim_threshold = trim_threshold;
dc8c34
+    CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig);
dc8c34
+
dc8c34
+    if (trim_threshold >= -1) {
dc8c34
+        mallopt(M_TRIM_THRESHOLD, trim_threshold);
dc8c34
+    } else if (DEFAULT_MALLOC_UNSET != trim_threshold) {
dc8c34
+        slapi_log_error(SLAPI_LOG_FATAL, "config",
dc8c34
+                        "%s: Invalid value %d will be ignored\n",
dc8c34
+                        CONFIG_MALLOC_TRIM_THRESHOLD, trim_threshold);
dc8c34
+    }
dc8c34
+    return LDAP_SUCCESS;
dc8c34
+}
dc8c34
+
dc8c34
+int
dc8c34
+config_get_malloc_trim_threshold()
dc8c34
+{
dc8c34
+  slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+  int retVal;
dc8c34
+
dc8c34
+  retVal = slapdFrontendConfig->malloc_trim_threshold;
dc8c34
+  return retVal; 
dc8c34
+}
dc8c34
+
dc8c34
+int
dc8c34
+config_set_malloc_mmap_threshold(const char *attrname, char *value, char *errorbuf, int apply)
dc8c34
+{
dc8c34
+    slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+    int max;
dc8c34
+    int mmap_threshold;
dc8c34
+    char *endp = NULL;
dc8c34
+
dc8c34
+    if (config_value_is_null(attrname, value, errorbuf, 0)) {
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+    if (sizeof(char *) == 8) {
dc8c34
+        max = 33554432; /* 4*1024*1024*sizeof(long) on 64-bit systems */
dc8c34
+    } else {
dc8c34
+        max = 524288; /* 512*1024 on 32-bit systems */
dc8c34
+    }
dc8c34
+
dc8c34
+    errno = 0;
dc8c34
+    mmap_threshold = strtol(value, &endp, 10);
dc8c34
+    if ((*endp != '\0') || (errno == ERANGE)) {
dc8c34
+        PR_snprintf(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
dc8c34
+                    "limit \"%s\" is invalid, %s must range from 0 to %d",
dc8c34
+                    value, CONFIG_MALLOC_MMAP_THRESHOLD, max);
dc8c34
+        return LDAP_OPERATIONS_ERROR;
dc8c34
+    }
dc8c34
+
dc8c34
+    CFG_ONOFF_LOCK_WRITE(slapdFrontendConfig);
dc8c34
+    slapdFrontendConfig->malloc_mmap_threshold = mmap_threshold;
dc8c34
+    CFG_ONOFF_UNLOCK_WRITE(slapdFrontendConfig);
dc8c34
+
dc8c34
+    if ((mmap_threshold >= 0) && (mmap_threshold <= max)) {
dc8c34
+        mallopt(M_MMAP_THRESHOLD, mmap_threshold);
dc8c34
+    } else if (DEFAULT_MALLOC_UNSET != mmap_threshold) {
dc8c34
+        slapi_log_error(SLAPI_LOG_FATAL, "config",
dc8c34
+                        "%s: Invalid value %d will be ignored\n",
dc8c34
+                        CONFIG_MALLOC_MMAP_THRESHOLD, mmap_threshold);
dc8c34
+    }
dc8c34
+    return LDAP_SUCCESS;
dc8c34
+}
dc8c34
+
dc8c34
+int
dc8c34
+config_get_malloc_mmap_threshold()
dc8c34
+{
dc8c34
+  slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
+  int retVal;
dc8c34
+
dc8c34
+  retVal = slapdFrontendConfig->malloc_mmap_threshold;
dc8c34
+  return retVal; 
dc8c34
+}
dc8c34
+#endif
dc8c34
+
dc8c34
 char *
dc8c34
 slapi_err2string(int result)
dc8c34
 {
dc8c34
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
dc8c34
index 71a912e..7a20bdf 100644
dc8c34
--- a/ldap/servers/slapd/proto-slap.h
dc8c34
+++ b/ldap/servers/slapd/proto-slap.h
dc8c34
@@ -394,6 +394,11 @@ int config_set_auditlog_unhashed_pw(const char *attrname, char *value, char *err
dc8c34
 int config_set_sasl_maxbufsize(const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
 int config_set_listen_backlog_size(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
 int config_set_ignore_time_skew(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
+#if defined(LINUX)
dc8c34
+int config_set_malloc_mxfast(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
+int config_set_malloc_trim_threshold(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
+int config_set_malloc_mmap_threshold(const char *attrname, char *value, char *errorbuf, int apply);
dc8c34
+#endif
dc8c34
 
dc8c34
 #if !defined(_WIN32) && !defined(AIX)
dc8c34
 int config_set_maxdescriptors( const char *attrname, char *value, char *errorbuf, int apply );
dc8c34
@@ -552,6 +557,12 @@ int config_get_sasl_maxbufsize();
dc8c34
 int config_get_listen_backlog_size(void);
dc8c34
 int config_get_ignore_time_skew();
dc8c34
 
dc8c34
+#if defined(LINUX)
dc8c34
+int config_get_malloc_mxfast();
dc8c34
+int config_get_malloc_trim_threshold();
dc8c34
+int config_get_malloc_mmap_threshold();
dc8c34
+#endif
dc8c34
+
dc8c34
 int is_abspath(const char *);
dc8c34
 char* rel2abspath( char * );
dc8c34
 char* rel2abspath_ext( char *, char * );
dc8c34
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
dc8c34
index 5394455..9a05da9 100644
dc8c34
--- a/ldap/servers/slapd/slap.h
dc8c34
+++ b/ldap/servers/slapd/slap.h
dc8c34
@@ -2008,6 +2008,13 @@ typedef struct _slapdEntryPoints {
dc8c34
 #define CONFIG_LISTEN_BACKLOG_SIZE	"nsslapd-listen-backlog-size"
dc8c34
 #define CONFIG_IGNORE_TIME_SKEW "nsslapd-ignore-time-skew"
dc8c34
 
dc8c34
+/* getenv alternative */
dc8c34
+#define CONFIG_MALLOC_MXFAST "nsslapd-malloc-mxfast"
dc8c34
+#define CONFIG_MALLOC_TRIM_THRESHOLD "nsslapd-malloc-trim-threshold"
dc8c34
+#define CONFIG_MALLOC_MMAP_THRESHOLD "nsslapd-malloc-mmap-threshold"
dc8c34
+
dc8c34
+#define DEFAULT_MALLOC_UNSET (-10)
dc8c34
+
dc8c34
 /*
dc8c34
  * Define the backlog number for use in listen() call.
dc8c34
  * We use the same definition as in ldapserver/include/base/systems.h
dc8c34
@@ -2252,6 +2259,11 @@ typedef struct _slapdFrontendConfig {
dc8c34
   int disk_grace_period;
dc8c34
   int disk_logging_critical;
dc8c34
   int ignore_time_skew;
dc8c34
+#if defined(LINUX)
dc8c34
+  int malloc_mxfast;            /* mallopt M_MXFAST */
dc8c34
+  int malloc_trim_threshold;    /* mallopt M_TRIM_THRESHOLD */
dc8c34
+  int malloc_mmap_threshold;    /* mallopt M_MMAP_THRESHOLD */
dc8c34
+#endif
dc8c34
 } slapdFrontendConfig_t;
dc8c34
 
dc8c34
 /* possible values for slapdFrontendConfig_t.schemareplace */
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34