[sr-dev] git:master:4c2ef7f3: core: new command line options for memory managers selections

Daniel-Constantin Mierla miconda at gmail.com
Mon Sep 14 10:23:12 CEST 2015


Module: kamailio
Branch: master
Commit: 4c2ef7f3eac3c7d18c8d8fc248b5372886c4c12a
URL: https://github.com/kamailio/kamailio/commit/4c2ef7f3eac3c7d18c8d8fc248b5372886c4c12a

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-09-14T10:22:46+02:00

core: new command line options for memory managers selections

- -x name: select the memory manager for shm
- -X name: select the memory manager for pkg
- -f -x is provided but -X is not provided, then pkg uses same memory
  manager as shm
- name can be:
    - fm - fast malloc (f_malloc)
    - qm - quick malloc (q_malloc)
- default memory manager is fm
- other changes: adjustments to init pkg and shm using new memory
  management api

---

Modified: main.c

---

Diff:  https://github.com/kamailio/kamailio/commit/4c2ef7f3eac3c7d18c8d8fc248b5372886c4c12a.diff
Patch: https://github.com/kamailio/kamailio/commit/4c2ef7f3eac3c7d18c8d8fc248b5372886c4c12a.patch

---

diff --git a/main.c b/main.c
index 1ff7f6a..4fd168d 100644
--- a/main.c
+++ b/main.c
@@ -497,6 +497,12 @@ char* pid_file = 0; /* filename as asked by use */
 char* pgid_file = 0;
 
 
+/* memory manager */
+#define SR_MEMMNG_DEFAULT	"fm"
+
+char *sr_memmng_pkg = NULL;
+char *sr_memmng_shm = NULL;
+
 /* call it before exiting; if show_status==1, mem status is displayed */
 void cleanup(show_status)
 {
@@ -504,7 +510,7 @@ void cleanup(show_status)
 	
 	/*clean-up*/
 #ifndef SHM_SAFE_MALLOC
-	if (mem_lock)
+	if (_shm_lock)
 		shm_unlock(); /* hack: force-unlock the shared memory lock in case
 					 some process crashed and let it locked; this will
 					 allow an almost gracious shutdown */
@@ -571,12 +577,12 @@ void cleanup(show_status)
 		}
 	}
 	/* zero all shmem alloc vars that we still use */
-	shm_mem_destroy();
+	shm_destroy_manager();
 #endif
 	destroy_lock_ops();
 	if (pid_file) unlink(pid_file);
 	if (pgid_file) unlink(pgid_file);
-	destroy_pkg_mallocs();
+	pkg_destroy_manager();
 }
 
 
@@ -1807,7 +1813,7 @@ int main(int argc, char** argv)
 	dprint_init_colors();
 
 	/* command line options */
-	options=  ":f:cm:M:dVIhEeb:l:L:n:vKrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:"
+	options=  ":f:cm:M:dVIhEeb:l:L:n:vKrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:x:X:"
 #ifdef STATS
 		"s:"
 #endif
@@ -1841,6 +1847,12 @@ int main(int argc, char** argv)
 						goto error;
 					};
 					break;
+			case 'x':
+					sr_memmng_shm = optarg;
+					break;
+			case 'X':
+					sr_memmng_pkg = optarg;
+					break;
 			default:
 					if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
 						printf("version: %s\n", full_version);
@@ -1850,11 +1862,26 @@ int main(int argc, char** argv)
 					break;
 		}
 	}
-	
+
+	if(sr_memmng_pkg==NULL) {
+		if(sr_memmng_shm!=NULL) {
+			sr_memmng_pkg = sr_memmng_shm;
+		} else {
+			sr_memmng_pkg = SR_MEMMNG_DEFAULT;
+		}
+	}
+	if(sr_memmng_shm==NULL) {
+		sr_memmng_shm = SR_MEMMNG_DEFAULT;
+	}
+	shm_set_mname(sr_memmng_shm);
+	if (pkg_mem_size == 0) {
+		pkg_mem_size = PKG_MEM_POOL_SIZE;
+	}
+
 	/*init pkg mallocs (before parsing cfg or the rest of the cmd line !)*/
 	if (pkg_mem_size)
 		LM_INFO("private (per process) memory: %ld bytes\n", pkg_mem_size );
-	if (init_pkg_mallocs()==-1)
+	if (pkg_init_manager(sr_memmng_pkg)<0)
 		goto error;
 
 #ifdef DBG_MSG_QA
@@ -1873,6 +1900,11 @@ int main(int argc, char** argv)
 	/* switches required before script processing */
 	while((c=getopt(argc,argv,options))!=-1) {
 		switch(c) {
+			case 'M':
+			case 'x':
+			case 'X':
+					/* ignore, they were parsed immediately after startup */
+					break;
 			case 'f':
 					cfg_file=optarg;
 					break;
@@ -1893,10 +1925,6 @@ int main(int argc, char** argv)
 					};
 					LM_INFO("shared memory: %ld bytes\n", shm_mem_size );
 					break;
-			case 'M':
-					/* ignore it, it was parsed immediately after startup,
-					   the pkg mem. is already initialized at this point */
-					break;
 			case 'd':
 					/* ignore it, was parsed immediately after startup */
 					break;
@@ -1997,6 +2025,9 @@ int main(int argc, char** argv)
 					abort();
 		}
 	}
+	if (shm_mem_size == 0) {
+		shm_mem_size = SHM_MEM_POOL_SIZE;
+	}
 
 	if (endianness_sanity_check() != 0){
 		fprintf(stderr, "BUG: endianness sanity tests failed\n");
@@ -2357,6 +2388,8 @@ int main(int argc, char** argv)
 	if (!shm_initialized() && init_shm()<0)
 		goto error;
 #endif /* SHM_MEM */
+	pkg_print_manager();
+	shm_print_manager();
 	if (init_atomic_ops()==-1)
 		goto error;
 	if (init_basex() != 0){




More information about the sr-dev mailing list