Module: sip-router
Branch: master
Commit: d89420df21b48440aeb10e8b4b92a4be65203c2b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d89420d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Thu Mar 29 13:57:22 2012 +0200
core: mem - join free packets option can be set from config
- better control over existing code for joining free memory fragments
- existing QM_JOIN_FREE renamed to MEM_JOIN_FREE - to be used in other
memory managers than q_malloc
- new cfg parameter mem_join - if set to 1, q_malloc does join of free
memory fragments. default is 0. in use if MEM_JOIN_FREE is defined
---
Makefile.defs | 3 ++
cfg.lex | 4 ++-
cfg.y | 3 ++
cfg_core.c | 3 ++
cfg_core.h | 1 +
mem/q_malloc.c | 68 ++++++++++++++++++++++++++++----------------------------
ver_defs.h | 6 ++--
7 files changed, 50 insertions(+), 38 deletions(-)
diff --git a/Makefile.defs b/Makefile.defs
index 2a7abbb..1e475d9 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -560,6 +560,8 @@ data_target = $(prefix)/$(data_dir)
# now.
# -DDBG_MALLOC
# issues additional debugging information if lock/unlock is called
+# -DMEM_JOIN_FREE
+# enable the join of free memory chunks (see also mem_join cfg param)
# -DFAST_LOCK
# uses fast arhitecture specific locking (see the arh. specific section)
# -DUSE_SYSV_SEM
@@ -704,6 +706,7 @@ C_DEFS= $(extra_defs) \
ifeq ($(MEMDBG), 1)
C_DEFS+= -DDBG_QM_MALLOC
+ C_DEFS+= -DMEM_JOIN_FREE
else
C_DEFS+= -DF_MALLOC
endif
diff --git a/cfg.lex b/cfg.lex
index f2da3c1..8769cfc 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -398,7 +398,8 @@ SYN_BRANCH syn_branch
MEMLOG "memlog"|"mem_log"
MEMDBG "memdbg"|"mem_dbg"
MEMSUM "mem_summary"
-MEMSAFETY "mem_safety"
+MEMSAFETY "mem_safety"
+MEMJOIN "mem_join"
CORELOG "corelog"|"core_log"
SIP_WARNING sip_warning
SERVER_SIGNATURE server_signature
@@ -799,6 +800,7 @@ IMPORTFILE "import_file"
<INITIAL>{MEMDBG} { count(); yylval.strval=yytext; return MEMDBG; }
<INITIAL>{MEMSUM} { count(); yylval.strval=yytext; return MEMSUM; }
<INITIAL>{MEMSAFETY} { count(); yylval.strval=yytext; return MEMSAFETY; }
+<INITIAL>{MEMJOIN} { count(); yylval.strval=yytext; return MEMJOIN; }
<INITIAL>{CORELOG} { count(); yylval.strval=yytext; return CORELOG; }
<INITIAL>{SIP_WARNING} { count(); yylval.strval=yytext; return SIP_WARNING; }
<INITIAL>{USER} { count(); yylval.strval=yytext; return USER; }
diff --git a/cfg.y b/cfg.y
index ded9ede..99f77a6 100644
--- a/cfg.y
+++ b/cfg.y
@@ -453,6 +453,7 @@ extern char *finame;
%token MEMDBG
%token MEMSUM
%token MEMSAFETY
+%token MEMJOIN
%token CORELOG
%token SIP_WARNING
%token SERVER_SIGNATURE
@@ -962,6 +963,8 @@ assign_stm:
| MEMSUM EQUAL error { yyerror("int value expected"); }
| MEMSAFETY EQUAL intno { default_core_cfg.mem_safety=$3; }
| MEMSAFETY EQUAL error { yyerror("int value expected"); }
+ | MEMJOIN EQUAL intno { default_core_cfg.mem_join=$3; }
+ | MEMJOIN EQUAL error { yyerror("int value expected"); }
| CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
| CORELOG EQUAL error { yyerror("int value expected"); }
| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
diff --git a/cfg_core.c b/cfg_core.c
index 72c0388..55a5638 100644
--- a/cfg_core.c
+++ b/cfg_core.c
@@ -122,6 +122,7 @@ struct cfg_group_core default_core_cfg = {
3, /*!< mem_summary -flags: 0 off, 1 pkg_status, 2 shm_status,
4 pkg_sums, 8 shm_sums, 16 short_status */
0, /*!< mem_safety - 0 disabled */
+ 0, /*!< mem_join - 0 disabled */
L_ERR, /*!< corelog */
L_ERR, /*!< latency log */
0, /*!< latency limit db */
@@ -315,6 +316,8 @@ cfg_def_t core_cfg_def[] = {
" 16 - short status instead of dump" },
{"mem_safety", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"safety level for memory operations"},
+ {"mem_join", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
+ "join free memory fragments"},
{"corelog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"log level for non-critical core error messages"},
{"latency_log", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
diff --git a/cfg_core.h b/cfg_core.h
index 5fc2139..4bfbfbb 100644
--- a/cfg_core.h
+++ b/cfg_core.h
@@ -109,6 +109,7 @@ struct cfg_group_core {
int memlog; /*!< log level for memory status/summary info */
int mem_summary; /*!< display memory status/summary info on exit */
int mem_safety; /*!< memory safety control option */
+ int mem_join; /*!< memory free fragments join option */
int corelog; /*!< log level for non-critcal core error messages */
int latency_log; /*!< log level for latency limits messages */
int latency_limit_db; /*!< alert limit of running db commands */
diff --git a/mem/q_malloc.c b/mem/q_malloc.c
index 9310385..fd93edb 100644
--- a/mem/q_malloc.c
+++ b/mem/q_malloc.c
@@ -428,10 +428,10 @@ void qm_free(struct qm_block* qm, void* p)
{
struct qm_frag* f;
unsigned long size;
-#ifdef QM_JOIN_FREE
+#ifdef MEM_JOIN_FREE
struct qm_frag* next;
struct qm_frag* prev;
-#endif /* QM_JOIN_FREE*/
+#endif /* MEM_JOIN_FREE*/
#ifdef DBG_QM_MALLOC
MDBG("qm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
@@ -446,9 +446,6 @@ void qm_free(struct qm_block* qm, void* p)
LOG(L_WARN, "WARNING:qm_free: free(0) called\n");
return;
}
-#ifdef QM_JOIN_FREE
- next=prev=0;
-#endif /* QM_JOIN_FREE*/
f=(struct qm_frag*) ((char*)p-sizeof(struct qm_frag));
#ifdef DBG_QM_MALLOC
qm_debug_frag(qm, f);
@@ -470,43 +467,46 @@ void qm_free(struct qm_block* qm, void* p)
sr_event_exec(SREV_PKG_SET_REAL_USED, (void*)qm->real_used);
#endif
-#ifdef QM_JOIN_FREE
- /* mark this fragment as used (might fall into the middle of joined frags)
- to give us an extra chance of detecting a double free call (if the joined
- fragment has not yet been reused) */
- f->u.nxt_free=(void*)0x1L; /* bogus value, just to mark it as free */
- /* join packets if possible*/
- next=FRAG_NEXT(f);
- if (((char*)next < (char*)qm->last_frag_end) &&( next->u.is_free)){
+#ifdef MEM_JOIN_FREE
+ if(unlikely(cfg_get(core, core_cfg, mem_join)!=0)) {
+ next=prev=0;
+ /* mark this fragment as used (might fall into the middle of joined frags)
+ to give us an extra chance of detecting a double free call (if the joined
+ fragment has not yet been reused) */
+ f->u.nxt_free=(void*)0x1L; /* bogus value, just to mark it as free */
+ /* join packets if possible*/
+ next=FRAG_NEXT(f);
+ if (((char*)next < (char*)qm->last_frag_end) &&( next->u.is_free)){
/* join */
#ifdef DBG_QM_MALLOC
- qm_debug_frag(qm, next);
+ qm_debug_frag(qm, next);
#endif
- qm_detach_free(qm, next);
- size+=next->size+FRAG_OVERHEAD;
- qm->real_used-=FRAG_OVERHEAD;
- qm->free_hash[GET_HASH(next->size)].no--; /* FIXME slow */
- }
+ qm_detach_free(qm, next);
+ size+=next->size+FRAG_OVERHEAD;
+ qm->real_used-=FRAG_OVERHEAD;
+ qm->free_hash[GET_HASH(next->size)].no--; /* FIXME slow */
+ }
- if (f > qm->first_frag){
- prev=FRAG_PREV(f);
- /* (struct qm_frag*)((char*)f - (struct qm_frag_end*)((char*)f-
+ if (f > qm->first_frag){
+ prev=FRAG_PREV(f);
+ /* (struct qm_frag*)((char*)f - (struct qm_frag_end*)((char*)f-
sizeof(struct qm_frag_end))->size);*/
#ifdef DBG_QM_MALLOC
- qm_debug_frag(qm, prev);
+ qm_debug_frag(qm, prev);
#endif
- if (prev->u.is_free){
- /*join*/
- qm_detach_free(qm, prev);
- size+=prev->size+FRAG_OVERHEAD;
- qm->real_used-=FRAG_OVERHEAD;
- qm->free_hash[GET_HASH(prev->size)].no--; /* FIXME slow */
- f=prev;
+ if (prev->u.is_free){
+ /*join*/
+ qm_detach_free(qm, prev);
+ size+=prev->size+FRAG_OVERHEAD;
+ qm->real_used-=FRAG_OVERHEAD;
+ qm->free_hash[GET_HASH(prev->size)].no--; /* FIXME slow */
+ f=prev;
+ }
}
- }
- f->size=size;
- FRAG_END(f)->size=f->size;
-#endif /* QM_JOIN_FREE*/
+ f->size=size;
+ FRAG_END(f)->size=f->size;
+ } /* if cfg_core->mem_join */
+#endif /* MEM_JOIN_FREE*/
#ifdef DBG_QM_MALLOC
f->file=file;
f->func=func;
diff --git a/ver_defs.h b/ver_defs.h
index 957bb69..a69a4c9 100644
--- a/ver_defs.h
+++ b/ver_defs.h
@@ -303,10 +303,10 @@
#define HAVE_RESOLV_RES_STR ""
#endif
-#ifdef QM_JOIN_FREE
-#define QM_JOIN_FREE_STR ", QM_JOIN_FREE"
+#ifdef MEM_JOIN_FREE
+#define MEM_JOIN_FREE_STR ", MEM_JOIN_FREE"
#else
-#define QM_JOIN_FREE_STR ""
+#define MEM_JOIN_FREE_STR ""
#endif
#ifdef SYSLOG_CALLBACK_SUPPORT