summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-22 17:36:37 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-22 17:36:37 +0200
commit412b7d7df683df5205cf545f248a4fc55478e124 (patch)
tree0c3b3b87ab5db39a9a31f39bf6d2e2544911396d
parent236bdb5cfaf56d9192a9911f140ba3da95b390b6 (diff)
parent8962c6b011f70bb7033d58641c2e4f3a73e7801a (diff)
downloadrsyslog-412b7d7df683df5205cf545f248a4fc55478e124.tar.gz
rsyslog-412b7d7df683df5205cf545f248a4fc55478e124.tar.xz
rsyslog-412b7d7df683df5205cf545f248a4fc55478e124.zip
Merge branch 'omfile' into v5-devel
-rw-r--r--configure.ac2
-rw-r--r--runtime/msg.c18
2 files changed, 19 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index ed45c414..776d7b94 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,7 +98,7 @@ AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRERROR_R
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([flock basename alarm clock_gettime gethostbyname gethostname gettimeofday localtime_r memset mkdir regcomp select setid socket strcasecmp strchr strdup strerror strndup strnlen strrchr strstr strtol strtoul uname ttyname_r epoll_wait getline])
+AC_CHECK_FUNCS([flock basename alarm clock_gettime gethostbyname gethostname gettimeofday localtime_r memset mkdir regcomp select setid socket strcasecmp strchr strdup strerror strndup strnlen strrchr strstr strtol strtoul uname ttyname_r epoll_wait getline malloc_trim])
# Check for MAXHOSTNAMELEN
AC_MSG_CHECKING(for MAXHOSTNAMELEN)
diff --git a/runtime/msg.c b/runtime/msg.c
index 4b7a0ad4..e47f104c 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -35,6 +35,7 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
+#include <malloc.h>
#include "rsyslog.h"
#include "srUtils.h"
#include "stringbuf.h"
@@ -550,6 +551,23 @@ CODESTARTobjDestruct(msg)
MsgUnlock(pThis);
# endif
funcDeleteMutex(pThis);
+ /* now we need to do our own optimization. Testing has shown that at least the glibc
+ * malloc() subsystem returns memory to the OS far too late in our case. So we need
+ * to help it a bit, by calling malloc_trim(), which will tell the alloc subsystem
+ * to consolidate and return to the OS. We keep 128K for our use, as a safeguard
+ * to too-frequent reallocs. But more importantly, we call this hook only every
+ * 100,000 messages (which is an approximation, as we do not work with atomic
+ * operations on the counter. --- rgerhards, 2009-06-22.
+ */
+# if HAVE_MALLOC_TRIM
+ { /* standard C requires a new block for a new variable definition! */
+ static unsigned iTrimCtr = 1;
+ if(iTrimCtr ++ % 100000 == 0) {
+ iTrimCtr = 1;
+ malloc_trim(128*1024);
+ }
+ }
+# endif
} else {
MsgUnlock(pThis);
pThis = NULL; /* tell framework not to destructing the object! */