Hi Daniel!
It would be cool if can make an article on the wiki describing shortly which memory managers (difference) should be used when building Kamailio from source (e.g. for production usage, testing systems, memory debugging), and which is used in pre-built binaries. And of course how to use this new features.
Thanks Klaus
On 30.03.2012 09:31, Daniel-Constantin Mierla wrote:
Module: sip-router Branch: master Commit: 1124b8cb29b942172c4aab38119f4a3c5f6e45f3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1124b8cb...
Author: Daniel-Constantin Mierlamiconda@gmail.com Committer: Daniel-Constantin Mierlamiconda@gmail.com Date: Fri Mar 30 09:29:18 2012 +0200
core: mem - use mem_safety for f_malloc when DBG_F_MALLOC defined
- added helper function to join a fragment with the next one when both are free, controlled by define MEM_JOIN_FREE and mem_join parameter
mem/f_malloc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/mem/f_malloc.c b/mem/f_malloc.c index 7beb3e2..4888b6e 100644 --- a/mem/f_malloc.c +++ b/mem/f_malloc.c @@ -445,6 +445,49 @@ found: }
+#ifdef MEM_JOIN_FREE +/**
- join fragment f with next one (if it is free)
- */
+static void fm_join_frag(struct fm_block* qm, struct fm_frag* f) +{
- int hash;
- struct fm_frag **pf;
- struct fm_frag* n;
- n=FRAG_NEXT(f);
- /* check if valid and if in free list */
- if (((char*)n>= (char*)qm->last_frag) || (n->u.nxt_free==NULL))
return;
- /* detach n from the free list */
- hash=GET_HASH(n->size);
- pf=&(qm->free_hash[hash].first);
- /* find it */
- for(;(*pf)&&(*pf!=n); pf=&((*pf)->u.nxt_free)); /*FIXME slow */
- if (*pf==0){
/* not found, bad! */
LM_WARN("could not find %p in free list (hash=%ld)\n", n, GET_HASH(n->size));
return;
- }
- /* detach */
- *pf=n->u.nxt_free;
- qm->free_hash[hash].no--;
+#ifdef F_MALLOC_HASH_BITMAP
- if (qm->free_hash[hash].no==0)
fm_bmp_reset(qm, hash);
+#endif /* F_MALLOC_HASH_BITMAP */
- /* join */
- f->size+=n->size+FRAG_OVERHEAD;
+#if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
- qm->real_used-=FRAG_OVERHEAD;
+#ifdef MALLOC_STATS
- sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
+#endif /* MALLOC_STATS */ +#endif /* DBG_F_MALLOC || MALLOC_STATS*/ +} +#endif /*MEM_JOIN_FREE*/
- /**
- \brief Main memory manager free function
@@ -465,9 +508,11 @@ void fm_free(struct fm_block* qm, void* p) #ifdef DBG_F_MALLOC MDBG("fm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line); if (p>(void*)qm->last_frag || p<(void*)qm->first_frag){
LOG(L_CRIT, "BUG: fm_free: bad pointer %p (out of memory block!) - "
"aborting\n", p);
abort();
LOG(L_CRIT, "BUG: fm_free: bad pointer %p (out of memory block!),"
" called from %s: %s(%d) - aborting\n", p,
file, func, line);
if(likely(cfg_get(core, core_cfg, mem_safety)==0))
} #endif if (p==0) {abort();
@@ -493,6 +538,10 @@ void fm_free(struct fm_block* qm, void* p) f->func=func; f->line=line; #endif +#ifdef MEM_JOIN_FREE
- if(unlikely(cfg_get(core, core_cfg, mem_join)!=0))
fm_join_frag(qm, f);
+#endif /*MEM_JOIN_FREE*/ fm_insert_free(qm, f); }
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev