Browse code

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

Daniel-Constantin Mierla authored on 14/09/2015 07:33:17
Showing 1 changed files
... ...
@@ -497,6 +497,12 @@ char* pid_file = 0; /* filename as asked by use */
497 497
 char* pgid_file = 0;
498 498
 
499 499
 
500
+/* memory manager */
501
+#define SR_MEMMNG_DEFAULT	"fm"
502
+
503
+char *sr_memmng_pkg = NULL;
504
+char *sr_memmng_shm = NULL;
505
+
500 506
 /* call it before exiting; if show_status==1, mem status is displayed */
501 507
 void cleanup(show_status)
502 508
 {
... ...
@@ -504,7 +510,7 @@ void cleanup(show_status)
504 504
 	
505 505
 	/*clean-up*/
506 506
 #ifndef SHM_SAFE_MALLOC
507
-	if (mem_lock)
507
+	if (_shm_lock)
508 508
 		shm_unlock(); /* hack: force-unlock the shared memory lock in case
509 509
 					 some process crashed and let it locked; this will
510 510
 					 allow an almost gracious shutdown */
... ...
@@ -571,12 +577,12 @@ void cleanup(show_status)
571 571
 		}
572 572
 	}
573 573
 	/* zero all shmem alloc vars that we still use */
574
-	shm_mem_destroy();
574
+	shm_destroy_manager();
575 575
 #endif
576 576
 	destroy_lock_ops();
577 577
 	if (pid_file) unlink(pid_file);
578 578
 	if (pgid_file) unlink(pgid_file);
579
-	destroy_pkg_mallocs();
579
+	pkg_destroy_manager();
580 580
 }
581 581
 
582 582
 
... ...
@@ -1807,7 +1813,7 @@ int main(int argc, char** argv)
1807 1807
 	dprint_init_colors();
1808 1808
 
1809 1809
 	/* command line options */
1810
-	options=  ":f:cm:M:dVIhEeb:l:L:n:vKrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:"
1810
+	options=  ":f:cm:M:dVIhEeb:l:L:n:vKrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:x:X:"
1811 1811
 #ifdef STATS
1812 1812
 		"s:"
1813 1813
 #endif
... ...
@@ -1841,6 +1847,12 @@ int main(int argc, char** argv)
1841 1841
 						goto error;
1842 1842
 					};
1843 1843
 					break;
1844
+			case 'x':
1845
+					sr_memmng_shm = optarg;
1846
+					break;
1847
+			case 'X':
1848
+					sr_memmng_pkg = optarg;
1849
+					break;
1844 1850
 			default:
1845 1851
 					if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
1846 1852
 						printf("version: %s\n", full_version);
... ...
@@ -1850,11 +1862,26 @@ int main(int argc, char** argv)
1850 1850
 					break;
1851 1851
 		}
1852 1852
 	}
1853
-	
1853
+
1854
+	if(sr_memmng_pkg==NULL) {
1855
+		if(sr_memmng_shm!=NULL) {
1856
+			sr_memmng_pkg = sr_memmng_shm;
1857
+		} else {
1858
+			sr_memmng_pkg = SR_MEMMNG_DEFAULT;
1859
+		}
1860
+	}
1861
+	if(sr_memmng_shm==NULL) {
1862
+		sr_memmng_shm = SR_MEMMNG_DEFAULT;
1863
+	}
1864
+	shm_set_mname(sr_memmng_shm);
1865
+	if (pkg_mem_size == 0) {
1866
+		pkg_mem_size = PKG_MEM_POOL_SIZE;
1867
+	}
1868
+
1854 1869
 	/*init pkg mallocs (before parsing cfg or the rest of the cmd line !)*/
1855 1870
 	if (pkg_mem_size)
1856 1871
 		LM_INFO("private (per process) memory: %ld bytes\n", pkg_mem_size );
1857
-	if (init_pkg_mallocs()==-1)
1872
+	if (pkg_init_manager(sr_memmng_pkg)<0)
1858 1873
 		goto error;
1859 1874
 
1860 1875
 #ifdef DBG_MSG_QA
... ...
@@ -1873,6 +1900,11 @@ int main(int argc, char** argv)
1873 1873
 	/* switches required before script processing */
1874 1874
 	while((c=getopt(argc,argv,options))!=-1) {
1875 1875
 		switch(c) {
1876
+			case 'M':
1877
+			case 'x':
1878
+			case 'X':
1879
+					/* ignore, they were parsed immediately after startup */
1880
+					break;
1876 1881
 			case 'f':
1877 1882
 					cfg_file=optarg;
1878 1883
 					break;
... ...
@@ -1893,10 +1925,6 @@ int main(int argc, char** argv)
1893 1893
 					};
1894 1894
 					LM_INFO("shared memory: %ld bytes\n", shm_mem_size );
1895 1895
 					break;
1896
-			case 'M':
1897
-					/* ignore it, it was parsed immediately after startup,
1898
-					   the pkg mem. is already initialized at this point */
1899
-					break;
1900 1896
 			case 'd':
1901 1897
 					/* ignore it, was parsed immediately after startup */
1902 1898
 					break;
... ...
@@ -1997,6 +2025,9 @@ int main(int argc, char** argv)
1997 1997
 					abort();
1998 1998
 		}
1999 1999
 	}
2000
+	if (shm_mem_size == 0) {
2001
+		shm_mem_size = SHM_MEM_POOL_SIZE;
2002
+	}
2000 2003
 
2001 2004
 	if (endianness_sanity_check() != 0){
2002 2005
 		fprintf(stderr, "BUG: endianness sanity tests failed\n");
... ...
@@ -2357,6 +2388,8 @@ try_again:
2357 2357
 	if (!shm_initialized() && init_shm()<0)
2358 2358
 		goto error;
2359 2359
 #endif /* SHM_MEM */
2360
+	pkg_print_manager();
2361
+	shm_print_manager();
2360 2362
 	if (init_atomic_ops()==-1)
2361 2363
 		goto error;
2362 2364
 	if (init_basex() != 0){