diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-22 17:35:16 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2009-06-22 17:35:16 +0200 |
commit | 8962c6b011f70bb7033d58641c2e4f3a73e7801a (patch) | |
tree | 1a7c1236e51ec6f5ae3052ffd490026599907efb /runtime | |
parent | 3abf567d2b57014381eda49018a0e2c21fa1b853 (diff) | |
download | rsyslog-8962c6b011f70bb7033d58641c2e4f3a73e7801a.tar.gz rsyslog-8962c6b011f70bb7033d58641c2e4f3a73e7801a.tar.xz rsyslog-8962c6b011f70bb7033d58641c2e4f3a73e7801a.zip |
reduced memory footprint / "memory leak"
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.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.c | 18 |
1 files changed, 18 insertions, 0 deletions
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! */ |