Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,349 +0,0 @@
1
-/*
2
- * shared mem stuff
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Permission to use, copy, modify, and distribute this software for any
9
- * purpose with or without fee is hereby granted, provided that the above
10
- * copyright notice and this permission notice appear in all copies.
11
- *
12
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
- */
20
-
21
-
22
-/**
23
- * \file
24
- * \brief  Shared memory functions
25
- * \ingroup mem
26
- */
27
-
28
-
29
-#ifdef SHM_MEM
30
-
31
-#ifndef shm_mem_h
32
-#define shm_mem_h
33
-
34
-#include "shm.h"
35
-
36
-#if 0
37
-
38
-#include <string.h>
39
-#include <errno.h>
40
-#include <sys/types.h>
41
-#include <sys/ipc.h>
42
-
43
-#ifndef SHM_MMAP
44
-
45
-#include <sys/shm.h>
46
-
47
-#endif
48
-
49
-#include <sys/sem.h>
50
-#include <string.h>
51
-#include <errno.h>
52
-
53
-/* fix DBG MALLOC stuff */
54
-
55
-/* fix debug defines, DBG_F_MALLOC <=> DBG_QM_MALLOC */
56
-#ifdef F_MALLOC
57
-	#ifdef DBG_F_MALLOC
58
-		#ifndef DBG_QM_MALLOC
59
-			#define DBG_QM_MALLOC
60
-		#endif
61
-	#elif defined(DBG_QM_MALLOC)
62
-		#define DBG_F_MALLOC
63
-	#endif
64
-#elif defined TLSF_MALLOC
65
-	#ifdef DBG_TLSF_MALLOC
66
-		#ifndef DBG_QM_MALLOC
67
-			#define DBG_QM_MALLOC
68
-		#endif
69
-	#elif defined(DBG_QM_MALLOC)
70
-		#define DBG_TLSF_MALLOC
71
-	#endif
72
-#endif
73
-
74
-
75
-
76
-#include "../dprint.h"
77
-#include "../lock_ops.h" /* we don't include locking.h on purpose */
78
-
79
-#ifdef LL_MALLOC
80
-#	include "ll_malloc.h"
81
-#	define SHM_SAFE_MALLOC /* no need to lock */
82
-	extern struct sfm_block* shm_block;
83
-#ifdef __SUNPRO_C
84
-#	define shm_malloc(...) sfm_malloc(shm_block, __VA_ARGS__)
85
-#	define shm_free(...) sfm_free(shm_block, __VA_ARGS__)
86
-#	define shm_realloc(...) sfm_malloc(shm_block, __VA_ARGS__)
87
-	/* WARNING: test, especially if switched to real realloc */
88
-#	define shm_resize(...)	sfm_realloc(shm_block, __VA_ARGS__)
89
-#	define shm_info(...) sfm_info(shm_block, __VA_ARGS__)
90
-#else /* __SUNPRO_C */
91
-#	define shm_malloc(args...) sfm_malloc(shm_block, ## args)
92
-#	define shm_free(args...) sfm_free(shm_block, ## args)
93
-#	define shm_realloc(args...) sfm_malloc(shm_block, ## args)
94
-	/* WARNING: test, especially if switched to real realloc */
95
-#	define shm_resize(args...)	sfm_realloc(shm_block, ## args)
96
-#	define shm_info(args...) sfm_info(shm_block, ## args)
97
-#endif /* __SUNPRO_C */
98
-#	define shm_malloc_unsafe  shm_malloc
99
-#	define shm_free_unsafe shm_free
100
-#	define shm_available	sfm_available(shm_block)
101
-#	define shm_status() sfm_status(shm_block)
102
-#	define shm_sums() do{}while(0)
103
-#	define shm_malloc_init sfm_malloc_init
104
-#	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
105
-#	define shm_malloc_on_fork()	sfm_pool_reset()
106
-#elif SF_MALLOC
107
-#	include "sf_malloc.h"
108
-#	define SHM_SAFE_MALLOC /* no need to lock */
109
-	extern struct sfm_block* shm_block;
110
-#ifdef __SUNPRO_C
111
-#	define shm_malloc(...) sfm_malloc(shm_block, __VA_ARGS__)
112
-#	define shm_free(...) sfm_free(shm_block, __VA_ARGS__)
113
-#	define shm_realloc(...) sfm_malloc(shm_block, __VA_ARGS__)
114
-	/* WARNING: test, especially if switched to real realloc */
115
-#	define shm_resize(...)	sfm_realloc(shm_block, __VA_ARGS__)
116
-#	define shm_info(...) sfm_info(shm_block, __VA_ARGS__)
117
-#else /* __SUNPRO_C */
118
-#	define shm_malloc(args...) sfm_malloc(shm_block, ## args)
119
-#	define shm_free(args...) sfm_free(shm_block, ## args)
120
-#	define shm_realloc(args...) sfm_malloc(shm_block, ## args)
121
-	/* WARNING: test, especially if switched to real realloc */
122
-#	define shm_resize(args...)	sfm_realloc(shm_block, ## args)
123
-#	define shm_info(args...) sfm_info(shm_block, ## args)
124
-#endif /* __SUNPRO_C */
125
-#	define shm_malloc_unsafe  shm_malloc
126
-#	define shm_free_unsafe shm_free
127
-#	define shm_available	sfm_available(shm_block)
128
-#	define shm_status() sfm_status(shm_block)
129
-#	define shm_sums() do{}while(0)
130
-#	define shm_malloc_init sfm_malloc_init
131
-#	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
132
-#	define shm_malloc_on_fork()	sfm_pool_reset()
133
-#elif defined F_MALLOC
134
-#	include "f_malloc.h"
135
-	extern struct fm_block* shm_block;
136
-#	define MY_MALLOC fm_malloc
137
-#	define MY_FREE fm_free
138
-#	define MY_REALLOC fm_realloc
139
-#	define MY_STATUS fm_status
140
-#	define MY_MEMINFO	fm_info
141
-#	define MY_SUMS	fm_sums
142
-#	define  shm_malloc_init fm_malloc_init
143
-#	define shm_malloc_destroy(b) do{}while(0)
144
-#	define shm_available() fm_available(shm_block)
145
-#	define shm_malloc_on_fork() do{}while(0)
146
-#elif defined DL_MALLOC
147
-#	include "dl_malloc.h"
148
-	extern mspace shm_block;
149
-#	define MY_MALLOC mspace_malloc
150
-#	define MY_FREE mspace_free
151
-#	define MY_REALLOC mspace_realloc
152
-#	define MY_STATUS(...) 0
153
-#	define MY_SUMS do{}while(0)
154
-#	define MY_MEMINFO	mspace_info
155
-#	define  shm_malloc_init(buf, len, type) create_mspace_with_base(buf, len, 0)
156
-#	define shm_malloc_destroy(b) do{}while(0)
157
-#	define shm_malloc_on_fork() do{}while(0)
158
-#elif defined TLSF_MALLOC
159
-#	include "tlsf.h"
160
-	extern pool_t shm_block;
161
-#	define MY_MALLOC tlsf_malloc
162
-#	define MY_FREE tlsf_free
163
-#	define MY_REALLOC tlsf_realloc
164
-#	define MY_STATUS tlsf_status
165
-#	define MY_MEMINFO	tlsf_meminfo
166
-#	define MY_SUMS tlsf_sums
167
-#	define shm_malloc_init(mem, bytes, type) tlsf_create_with_pool((void*) mem, bytes)
168
-#	define shm_malloc_destroy(b) do{}while(0)
169
-#	define shm_available() tlsf_available(shm_block)
170
-#	define shm_malloc_on_fork() do{}while(0)
171
-#else
172
-#	include "q_malloc.h"
173
-	extern struct qm_block* shm_block;
174
-#	define MY_MALLOC qm_malloc
175
-#	define MY_FREE qm_free
176
-#	define MY_REALLOC qm_realloc
177
-#	define MY_STATUS qm_status
178
-#	define MY_MEMINFO	qm_info
179
-#	define MY_SUMS	qm_sums
180
-#	define  shm_malloc_init qm_malloc_init
181
-#	define shm_malloc_destroy(b) do{}while(0)
182
-#	define shm_available() qm_available(shm_block)
183
-#	define shm_malloc_on_fork() do{}while(0)
184
-#endif
185
-
186
-#ifndef SHM_SAFE_MALLOC
187
-	extern gen_lock_t* mem_lock;
188
-#endif
189
-
190
-
191
-int shm_mem_init(int); /* calls shm_getmem & shm_mem_init_mallocs */
192
-int shm_getmem(void);   /* allocates the memory (mmap or sysv shmap) */
193
-int shm_mem_init_mallocs(void* mempool, unsigned long size); /* initialize
194
-																the mallocs
195
-																& the lock */
196
-void shm_mem_destroy(void);
197
-
198
-
199
-
200
-#ifdef SHM_SAFE_MALLOC
201
-#define shm_lock() do{}while(0)
202
-#define shm_unlock() do{}while(0)
203
-
204
-#else /* ! SHM_SAFE_MALLOC */
205
-
206
-#define shm_lock()    lock_get(mem_lock)
207
-#define shm_unlock()  lock_release(mem_lock)
208
-
209
-#ifdef DBG_QM_MALLOC
210
-
211
-#include "src_loc.h"
212
-
213
-#define shm_malloc_unsafe(_size ) \
214
-	MY_MALLOC(shm_block, (_size), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
215
-
216
-
217
-inline static void* _shm_malloc(unsigned int size, 
218
-	const char *file, const char *function, int line, const char *mname)
219
-{
220
-	void *p;
221
-	
222
-	shm_lock();
223
-	p=MY_MALLOC(shm_block, size, file, function, line, mname);
224
-	shm_unlock();
225
-	return p; 
226
-}
227
-
228
-
229
-inline static void* _shm_realloc(void *ptr, unsigned int size, 
230
-		const char* file, const char* function, int line, const char *mname)
231
-{
232
-	void *p;
233
-	shm_lock();
234
-	p=MY_REALLOC(shm_block, ptr, size, file, function, line, mname);
235
-	shm_unlock();
236
-	return p;
237
-}
238
-
239
-#define shm_malloc( _size ) _shm_malloc((_size), \
240
-	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ , _SRC_MODULE_)
241
-
242
-#define shm_realloc( _ptr, _size ) _shm_realloc( (_ptr), (_size), \
243
-	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
244
-
245
-
246
-
247
-#define shm_free_unsafe( _p  ) \
248
-	MY_FREE( shm_block, (_p), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
249
-
250
-#define shm_free(_p) \
251
-do { \
252
-		shm_lock(); \
253
-		shm_free_unsafe( (_p)); \
254
-		shm_unlock(); \
255
-}while(0)
256
-
257
-
258
-
259
-void* _shm_resize(void* ptr, unsigned int size, const char* f, const char* fn,
260
-					int line, const char *mname);
261
-#define shm_resize(_p, _s ) _shm_resize((_p), (_s), \
262
-		_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
263
-/*#define shm_resize(_p, _s ) shm_realloc( (_p), (_s))*/
264
-
265
-
266
-
267
-#else /*DBQ_QM_MALLOC*/
268
-
269
-
270
-#define shm_malloc_unsafe(_size) MY_MALLOC(shm_block, (_size))
271
-
272
-inline static void* shm_malloc(unsigned int size)
273
-{
274
-	void *p;
275
-	
276
-	shm_lock();
277
-	p=shm_malloc_unsafe(size);
278
-	shm_unlock();
279
-	 return p; 
280
-}
281
-
282
-
283
-inline static void* shm_realloc(void *ptr, unsigned int size)
284
-{
285
-	void *p;
286
-	shm_lock();
287
-	p=MY_REALLOC(shm_block, ptr, size);
288
-	shm_unlock();
289
-	return p;
290
-}
291
-
292
-
293
-
294
-#define shm_free_unsafe( _p ) MY_FREE(shm_block, (_p))
295
-
296
-#define shm_free(_p) \
297
-do { \
298
-		shm_lock(); \
299
-		shm_free_unsafe( _p ); \
300
-		shm_unlock(); \
301
-}while(0)
302
-
303
-
304
-
305
-void* _shm_resize(void* ptr, unsigned int size);
306
-#define shm_resize(_p, _s) _shm_resize( (_p), (_s))
307
-/*#define shm_resize(_p, _s) shm_realloc( (_p), (_s))*/
308
-
309
-
310
-#endif  /* DBG_QM_MALLOC */
311
-
312
-
313
-#define shm_status() \
314
-do { \
315
-		shm_lock(); \
316
-		MY_STATUS(shm_block); \
317
-		shm_unlock(); \
318
-}while(0)
319
-
320
-
321
-#define shm_info(mi) \
322
-do{\
323
-	shm_lock(); \
324
-	MY_MEMINFO(shm_block, mi); \
325
-	shm_unlock(); \
326
-}while(0)
327
-
328
-#ifdef MY_SUMS
329
-#define shm_sums() \
330
-	do { \
331
-		shm_lock(); \
332
-		MY_SUMS(shm_block); \
333
-		shm_unlock(); \
334
-	}while(0)
335
-	
336
-#endif /* MY_SUMS */
337
-
338
-#endif /* ! SHM_SAFE_MALLOC */
339
-
340
-/* multi-process safe version of shm_available()
341
- */
342
-unsigned long shm_available_safe();
343
-
344
-#endif
345
-
346
-#endif /* shm_mem_h */
347
-
348
-#endif /* SHM_MEM */
349
-
Browse code

core: mem - shm common defines to pass the module name

Stefan Mititelu authored on 02/11/2015 12:47:26 • Daniel-Constantin Mierla committed on 02/11/2015 12:47:26
Showing 1 changed files
... ...
@@ -211,41 +211,41 @@ void shm_mem_destroy(void);
211 211
 #include "src_loc.h"
212 212
 
213 213
 #define shm_malloc_unsafe(_size ) \
214
-	MY_MALLOC(shm_block, (_size), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
214
+	MY_MALLOC(shm_block, (_size), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
215 215
 
216 216
 
217 217
 inline static void* _shm_malloc(unsigned int size, 
218
-	const char *file, const char *function, int line )
218
+	const char *file, const char *function, int line, const char *mname)
219 219
 {
220 220
 	void *p;
221 221
 	
222 222
 	shm_lock();
223
-	p=MY_MALLOC(shm_block, size, file, function, line );
223
+	p=MY_MALLOC(shm_block, size, file, function, line, mname);
224 224
 	shm_unlock();
225 225
 	return p; 
226 226
 }
227 227
 
228 228
 
229 229
 inline static void* _shm_realloc(void *ptr, unsigned int size, 
230
-		const char* file, const char* function, int line )
230
+		const char* file, const char* function, int line, const char *mname)
231 231
 {
232 232
 	void *p;
233 233
 	shm_lock();
234
-	p=MY_REALLOC(shm_block, ptr, size, file, function, line);
234
+	p=MY_REALLOC(shm_block, ptr, size, file, function, line, mname);
235 235
 	shm_unlock();
236 236
 	return p;
237 237
 }
238 238
 
239 239
 #define shm_malloc( _size ) _shm_malloc((_size), \
240
-	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
240
+	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ , _SRC_MODULE_)
241 241
 
242 242
 #define shm_realloc( _ptr, _size ) _shm_realloc( (_ptr), (_size), \
243
-	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
243
+	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
244 244
 
245 245
 
246 246
 
247 247
 #define shm_free_unsafe( _p  ) \
248
-	MY_FREE( shm_block, (_p), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
248
+	MY_FREE( shm_block, (_p), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
249 249
 
250 250
 #define shm_free(_p) \
251 251
 do { \
... ...
@@ -257,9 +257,9 @@ do { \
257 257
 
258 258
 
259 259
 void* _shm_resize(void* ptr, unsigned int size, const char* f, const char* fn,
260
-					int line);
260
+					int line, const char *mname);
261 261
 #define shm_resize(_p, _s ) _shm_resize((_p), (_s), \
262
-		_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
262
+		_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_, _SRC_MODULE_)
263 263
 /*#define shm_resize(_p, _s ) shm_realloc( (_p), (_s))*/
264 264
 
265 265
 
Browse code

mem: old shm management disabled

Daniel-Constantin Mierla authored on 14/09/2015 07:24:00
Showing 1 changed files
... ...
@@ -31,6 +31,10 @@
31 31
 #ifndef shm_mem_h
32 32
 #define shm_mem_h
33 33
 
34
+#include "shm.h"
35
+
36
+#if 0
37
+
34 38
 #include <string.h>
35 39
 #include <errno.h>
36 40
 #include <sys/types.h>
... ...
@@ -337,6 +341,7 @@ do{\
337 341
  */
338 342
 unsigned long shm_available_safe();
339 343
 
344
+#endif
340 345
 
341 346
 #endif /* shm_mem_h */
342 347
 
Browse code

mem: TLSF memory summary and sums implementation

TLSF now has a debug mode, that will dump every memory block when xxx_status()
is called, and a summary of still allocated blocks when xxx_sums() is called.

configure build with

make MEMDBG=1 MEMMNG=2 cfg

to enable maximum debuging informations (source location of mallocs and frees)

Camille Oudot authored on 19/05/2015 17:58:57
Showing 1 changed files
... ...
@@ -57,6 +57,14 @@
57 57
 	#elif defined(DBG_QM_MALLOC)
58 58
 		#define DBG_F_MALLOC
59 59
 	#endif
60
+#elif defined TLSF_MALLOC
61
+	#ifdef DBG_TLSF_MALLOC
62
+		#ifndef DBG_QM_MALLOC
63
+			#define DBG_QM_MALLOC
64
+		#endif
65
+	#elif defined(DBG_QM_MALLOC)
66
+		#define DBG_TLSF_MALLOC
67
+	#endif
60 68
 #endif
61 69
 
62 70
 
... ...
@@ -149,9 +157,9 @@
149 157
 #	define MY_MALLOC tlsf_malloc
150 158
 #	define MY_FREE tlsf_free
151 159
 #	define MY_REALLOC tlsf_realloc
152
-#	define MY_STATUS(...) ((void) 0)
160
+#	define MY_STATUS tlsf_status
153 161
 #	define MY_MEMINFO	tlsf_meminfo
154
-#	define MY_SUMS(...) ((void) 0)
162
+#	define MY_SUMS tlsf_sums
155 163
 #	define shm_malloc_init(mem, bytes, type) tlsf_create_with_pool((void*) mem, bytes)
156 164
 #	define shm_malloc_destroy(b) do{}while(0)
157 165
 #	define shm_available() tlsf_available(shm_block)
Browse code

mem: fix shm_available() def for TLSF

Camille Oudot authored on 22/04/2015 09:48:41
Showing 1 changed files
... ...
@@ -154,7 +154,7 @@
154 154
 #	define MY_SUMS(...) ((void) 0)
155 155
 #	define shm_malloc_init(mem, bytes, type) tlsf_create_with_pool((void*) mem, bytes)
156 156
 #	define shm_malloc_destroy(b) do{}while(0)
157
-#	define shm_available() qm_available(shm_block)
157
+#	define shm_available() tlsf_available(shm_block)
158 158
 #	define shm_malloc_on_fork() do{}while(0)
159 159
 #else
160 160
 #	include "q_malloc.h"
Browse code

mem: TLSF allocator integration in kamailio

- kamailio memory counters for statistics
- use
MEMMNG=1 MEMDBG=0 extra_defs='-DTLSF_MALLOC=1
to enable
- support for > 4GB memory (current limit is now 1TB)

Camille Oudot authored on 21/04/2015 15:03:06
Showing 1 changed files
... ...
@@ -143,6 +143,19 @@
143 143
 #	define  shm_malloc_init(buf, len, type) create_mspace_with_base(buf, len, 0)
144 144
 #	define shm_malloc_destroy(b) do{}while(0)
145 145
 #	define shm_malloc_on_fork() do{}while(0)
146
+#elif defined TLSF_MALLOC
147
+#	include "tlsf.h"
148
+	extern pool_t shm_block;
149
+#	define MY_MALLOC tlsf_malloc
150
+#	define MY_FREE tlsf_free
151
+#	define MY_REALLOC tlsf_realloc
152
+#	define MY_STATUS(...) ((void) 0)
153
+#	define MY_MEMINFO	tlsf_meminfo
154
+#	define MY_SUMS(...) ((void) 0)
155
+#	define shm_malloc_init(mem, bytes, type) tlsf_create_with_pool((void*) mem, bytes)
156
+#	define shm_malloc_destroy(b) do{}while(0)
157
+#	define shm_available() qm_available(shm_block)
158
+#	define shm_malloc_on_fork() do{}while(0)
146 159
 #else
147 160
 #	include "q_malloc.h"
148 161
 	extern struct qm_block* shm_block;
Browse code

tls: removed inline specifier and renamed safe_shm_available()

- became shm_available_safe() to have the shm_ prefix which common for
shm functions
- declaring inline in c header file and implementing in c source file
makes clang throw compile warnings

Daniel-Constantin Mierla authored on 15/04/2015 09:22:36
Showing 1 changed files
... ...
@@ -314,7 +314,7 @@ do{\
314 314
 
315 315
 /* multi-process safe version of shm_available()
316 316
  */
317
-inline unsigned long safe_shm_available();
317
+unsigned long shm_available_safe();
318 318
 
319 319
 
320 320
 #endif /* shm_mem_h */
Browse code

mem: add a multiprocess-safe shm_available()

new safe_shm_available() function secured with shm_lock()

Camille Oudot authored on 14/04/2015 17:38:14
Showing 1 changed files
... ...
@@ -312,6 +312,11 @@ do{\
312 312
 
313 313
 #endif /* ! SHM_SAFE_MALLOC */
314 314
 
315
+/* multi-process safe version of shm_available()
316
+ */
317
+inline unsigned long safe_shm_available();
318
+
319
+
315 320
 #endif /* shm_mem_h */
316 321
 
317 322
 #endif /* SHM_MEM */
Browse code

mem Remove SVN ID, remove history

Olle E. Johansson authored on 25/02/2015 08:12:38
Showing 1 changed files
... ...
@@ -3,7 +3,7 @@
3 3
  *
4 4
  * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6
- * This file is part of sip-router, a free SIP server.
6
+ * This file is part of Kamailio, a free SIP server.
7 7
  *
8 8
  * Permission to use, copy, modify, and distribute this software for any
9 9
  * purpose with or without fee is hereby granted, provided that the above
... ...
@@ -18,16 +18,6 @@
18 18
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 19
  */
20 20
 
21
-/*
22
- * History:
23
- * --------
24
- *  2003-06-29  added shm_realloc & replaced shm_resize (andrei)
25
- *  2003-11-19  reverted shm_resize to the old version, using
26
- *               realloc causes terrible fragmentation  (andrei)
27
- *  2005-03-02   added shm_info() & re-eneabled locking on shm_status (andrei)
28
- *  2007-02-23   added shm_available() (andrei)
29
- *  2007-06-10   support for sf_malloc (andrei)
30
- */
31 21
 
32 22
 /**
33 23
  * \file
Browse code

core/mem: set shm type when initializing shared memory pool

Daniel-Constantin Mierla authored on 03/05/2014 18:02:06
Showing 1 changed files
... ...
@@ -150,7 +150,7 @@
150 150
 #	define MY_STATUS(...) 0
151 151
 #	define MY_SUMS do{}while(0)
152 152
 #	define MY_MEMINFO	mspace_info
153
-#	define  shm_malloc_init(buf, len) create_mspace_with_base(buf, len, 0)
153
+#	define  shm_malloc_init(buf, len, type) create_mspace_with_base(buf, len, 0)
154 154
 #	define shm_malloc_destroy(b) do{}while(0)
155 155
 #	define shm_malloc_on_fork() do{}while(0)
156 156
 #else
Browse code

mem: small def./decl. fix for a bunch of internal functions, use void argument

Henning Westerholt authored on 13/07/2011 22:16:38
Showing 1 changed files
... ...
@@ -174,11 +174,11 @@
174 174
 
175 175
 
176 176
 int shm_mem_init(int); /* calls shm_getmem & shm_mem_init_mallocs */
177
-int shm_getmem();   /* allocates the memory (mmap or sysv shmap) */
177
+int shm_getmem(void);   /* allocates the memory (mmap or sysv shmap) */
178 178
 int shm_mem_init_mallocs(void* mempool, unsigned long size); /* initialize
179 179
 																the mallocs
180 180
 																& the lock */
181
-void shm_mem_destroy();
181
+void shm_mem_destroy(void);
182 182
 
183 183
 
184 184
 
Browse code

mem: initial doxygen documentation for MM, small whitespace changes

Henning Westerholt authored on 13/07/2011 22:11:48
Showing 1 changed files
... ...
@@ -1,5 +1,4 @@
1
-/* $Id$*
2
- *
1
+/*
3 2
  * shared mem stuff
4 3
  *
5 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -18,6 +17,7 @@
18 17
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 18
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 19
  */
20
+
21 21
 /*
22 22
  * History:
23 23
  * --------
... ...
@@ -29,6 +29,12 @@
29 29
  *  2007-06-10   support for sf_malloc (andrei)
30 30
  */
31 31
 
32
+/**
33
+ * \file
34
+ * \brief  Shared memory functions
35
+ * \ingroup mem
36
+ */
37
+
32 38
 
33 39
 #ifdef SHM_MEM
34 40
 
Browse code

mem: include the module name in the debugging info

- use <module_name: file> when recording the filename information
for debugging (DBQ_QM_MALLOC defined)
- added a new file that should define in a portable way the
various location info (file, function, a.s.o.)

Andrei Pelinescu-Onciul authored on 08/10/2009 09:33:25
Showing 1 changed files
... ...
@@ -187,12 +187,10 @@ void shm_mem_destroy();
187 187
 
188 188
 #ifdef DBG_QM_MALLOC
189 189
 
190
-#ifdef __SUNPRO_C
191
-		#define __FUNCTION__ ""  /* gcc specific */
192
-#endif
190
+#include "src_loc.h"
193 191
 
194 192
 #define shm_malloc_unsafe(_size ) \
195
-	MY_MALLOC(shm_block, (_size), __FILE__, __FUNCTION__, __LINE__ )
193
+	MY_MALLOC(shm_block, (_size), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
196 194
 
197 195
 
198 196
 inline static void* _shm_malloc(unsigned int size, 
... ...
@@ -218,15 +216,15 @@ inline static void* _shm_realloc(void *ptr, unsigned int size,
218 216
 }
219 217
 
220 218
 #define shm_malloc( _size ) _shm_malloc((_size), \
221
-	__FILE__, __FUNCTION__, __LINE__ )
219
+	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
222 220
 
223 221
 #define shm_realloc( _ptr, _size ) _shm_realloc( (_ptr), (_size), \
224
-	__FILE__, __FUNCTION__, __LINE__ )
222
+	_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
225 223
 
226 224
 
227 225
 
228 226
 #define shm_free_unsafe( _p  ) \
229
-	MY_FREE( shm_block, (_p), __FILE__, __FUNCTION__, __LINE__ )
227
+	MY_FREE( shm_block, (_p), _SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
230 228
 
231 229
 #define shm_free(_p) \
232 230
 do { \
... ...
@@ -240,7 +238,7 @@ do { \
240 238
 void* _shm_resize(void* ptr, unsigned int size, const char* f, const char* fn,
241 239
 					int line);
242 240
 #define shm_resize(_p, _s ) _shm_resize((_p), (_s), \
243
-		__FILE__, __FUNCTION__, __LINE__ )
241
+		_SRC_LOC_, _SRC_FUNCTION_, _SRC_LINE_ )
244 242
 /*#define shm_resize(_p, _s ) shm_realloc( (_p), (_s))*/
245 243
 
246 244
 
Browse code

core: mem dbg options updates + cleanups

- memlog and memdbg can now be changed at runtime
- double define warning fix for fm_malloc (when compiled with -DF_MALLOC)
- nicer qm_status() & qm_sums() output
- BSD licence for mem/*

Andrei Pelinescu-Onciul authored on 29/09/2009 13:25:50
Showing 1 changed files
... ...
@@ -4,26 +4,19 @@
4 4
  *
5 5
  * Copyright (C) 2001-2003 FhG Fokus
6 6
  *
7
- * This file is part of ser, a free SIP server.
7
+ * This file is part of sip-router, a free SIP server.
8 8
  *
9
- * ser is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version
9
+ * Permission to use, copy, modify, and distribute this software for any
10
+ * purpose with or without fee is hereby granted, provided that the above
11
+ * copyright notice and this permission notice appear in all copies.
13 12
  *
14
- * For a license to use the ser software under conditions
15
- * other than those described here, or to purchase support for this
16
- * software, please contact iptel.org by e-mail at the following addresses:
17
- *    info@iptel.org
18
- *
19
- * ser is distributed in the hope that it will be useful,
20
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
- * GNU General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License 
25
- * along with this program; if not, write to the Free Software 
26
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
13
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 20
  */
28 21
 /*
29 22
  * History:
Browse code

core: remove VQ_MALLOC memory manager

attached patch removes the VQ_MALLOC memory manager from the
sip-router core. As discussed some time ago, this memory manager
doesn't provide a realloc implementation, and is thus not really
usable for the modules, as some of them needs this. We removed
this in kamailio in the last year, so far nobody missed it.

Signed-off-by: Andrei Pelinescu-Onciul <andrei@iptel.org>

Henning Westerholt authored on 17/03/2009 12:24:42 • Andrei Pelinescu-Onciul committed on 29/09/2009 17:03:41
Showing 1 changed files
... ...
@@ -129,17 +129,6 @@
129 129
 #	define shm_malloc_init sfm_malloc_init
130 130
 #	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
131 131
 #	define shm_malloc_on_fork()	sfm_pool_reset()
132
-#elif VQ_MALLOC
133
-#	include "vq_malloc.h"
134
-	extern struct vqm_block* shm_block;
135
-#	define MY_MALLOC vqm_malloc
136
-#	define MY_FREE vqm_free
137
-#	define MY_STATUS vqm_status
138
-#	define MY_SUMS do{}while(0)
139
-#	define  shm_malloc_init vqm_malloc_init
140
-#	define shm_malloc_destroy(b) do{}while(0)
141
-#	define shm_malloc_on_fork() do{}while(0)
142
-#	warn "no proper vq_realloc implementation, try another memory allocator"
143 132
 #elif defined F_MALLOC
144 133
 #	include "f_malloc.h"
145 134
 	extern struct fm_block* shm_block;
Browse code

mem: summarize in-use memory on exit

Additional qm_sums and fm_sums as extension to qm_status/fm_status, with
summarized values per allocation source.
Slightly modified SER-224 patch version (no locking, sr changes --andrei).

Closes SER-224.

Signed-off-by: Andrei Pelinescu-Onciul <andrei@iptel.org>

Dragos Vingarzan authored on 28/09/2009 20:01:17 • Andrei Pelinescu-Onciul committed on 29/09/2009 17:03:40
Showing 1 changed files
... ...
@@ -98,6 +98,7 @@
98 98
 #	define shm_free_unsafe shm_free
99 99
 #	define shm_available	sfm_available(shm_block)
100 100
 #	define shm_status() sfm_status(shm_block)
101
+#	define shm_sums() do{}while(0)
101 102
 #	define shm_malloc_init sfm_malloc_init
102 103
 #	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
103 104
 #	define shm_malloc_on_fork()	sfm_pool_reset()
... ...
@@ -124,6 +125,7 @@
124 125
 #	define shm_free_unsafe shm_free
125 126
 #	define shm_available	sfm_available(shm_block)
126 127
 #	define shm_status() sfm_status(shm_block)
128
+#	define shm_sums() do{}while(0)
127 129
 #	define shm_malloc_init sfm_malloc_init
128 130
 #	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
129 131
 #	define shm_malloc_on_fork()	sfm_pool_reset()
... ...
@@ -133,6 +135,7 @@
133 135
 #	define MY_MALLOC vqm_malloc
134 136
 #	define MY_FREE vqm_free
135 137
 #	define MY_STATUS vqm_status
138
+#	define MY_SUMS do{}while(0)
136 139
 #	define  shm_malloc_init vqm_malloc_init
137 140
 #	define shm_malloc_destroy(b) do{}while(0)
138 141
 #	define shm_malloc_on_fork() do{}while(0)
... ...
@@ -145,6 +148,7 @@
145 148
 #	define MY_REALLOC fm_realloc
146 149
 #	define MY_STATUS fm_status
147 150
 #	define MY_MEMINFO	fm_info
151
+#	define MY_SUMS	fm_sums
148 152
 #	define  shm_malloc_init fm_malloc_init
149 153
 #	define shm_malloc_destroy(b) do{}while(0)
150 154
 #	define shm_available() fm_available(shm_block)
... ...
@@ -156,6 +160,7 @@
156 160
 #	define MY_FREE mspace_free
157 161
 #	define MY_REALLOC mspace_realloc
158 162
 #	define MY_STATUS(...) 0
163
+#	define MY_SUMS do{}while(0)
159 164
 #	define MY_MEMINFO	mspace_info
160 165
 #	define  shm_malloc_init(buf, len) create_mspace_with_base(buf, len, 0)
161 166
 #	define shm_malloc_destroy(b) do{}while(0)
... ...
@@ -168,6 +173,7 @@
168 173
 #	define MY_REALLOC qm_realloc
169 174
 #	define MY_STATUS qm_status
170 175
 #	define MY_MEMINFO	qm_info
176
+#	define MY_SUMS	qm_sums
171 177
 #	define  shm_malloc_init qm_malloc_init
172 178
 #	define shm_malloc_destroy(b) do{}while(0)
173 179
 #	define shm_available() qm_available(shm_block)
... ...
@@ -318,6 +324,16 @@ do{\
318 324
 	shm_unlock(); \
319 325
 }while(0)
320 326
 
327
+#ifdef MY_SUMS
328
+#define shm_sums() \
329
+	do { \
330
+		shm_lock(); \
331
+		MY_SUMS(shm_block); \
332
+		shm_unlock(); \
333
+	}while(0)
334
+	
335
+#endif /* MY_SUMS */
336
+
321 337
 #endif /* ! SHM_SAFE_MALLOC */
322 338
 
323 339
 #endif /* shm_mem_h */
Browse code

- added sf_malloc: a multi-process safe (internal locking), multi-pool f_malloc version. Should perform better on lots of CPU once properly tunned (experimental for now) - added ll_malloc: same as above but most operation are lockless (except for "big" fragment handling). For now needs tunning and it still keeps too many debugging statistics. (experimental for now)

Andrei Pelinescu-Onciul authored on 12/06/2007 18:07:12
Showing 1 changed files
... ...
@@ -33,6 +33,7 @@
33 33
  *               realloc causes terrible fragmentation  (andrei)
34 34
  *  2005-03-02   added shm_info() & re-eneabled locking on shm_status (andrei)
35 35
  *  2007-02-23   added shm_available() (andrei)
36
+ *  2007-06-10   support for sf_malloc (andrei)
36 37
  */
37 38
 
38 39
 
... ...
@@ -74,13 +75,67 @@
74 75
 #include "../dprint.h"
75 76
 #include "../lock_ops.h" /* we don't include locking.h on purpose */
76 77
 
77
-#ifdef VQ_MALLOC
78
+#ifdef LL_MALLOC
79
+#	include "ll_malloc.h"
80
+#	define SHM_SAFE_MALLOC /* no need to lock */
81
+	extern struct sfm_block* shm_block;
82
+#ifdef __SUNPRO_C
83
+#	define shm_malloc(...) sfm_malloc(shm_block, __VA_ARGS__)
84
+#	define shm_free(...) sfm_free(shm_block, __VA_ARGS__)
85
+#	define shm_realloc(...) sfm_malloc(shm_block, __VA_ARGS__)
86
+	/* WARNING: test, especially if switched to real realloc */
87
+#	define shm_resize(...)	sfm_realloc(shm_block, __VA_ARGS__)
88
+#	define shm_info(...) sfm_info(shm_block, __VA_ARGS__)
89
+#else /* __SUNPRO_C */
90
+#	define shm_malloc(args...) sfm_malloc(shm_block, ## args)
91
+#	define shm_free(args...) sfm_free(shm_block, ## args)
92
+#	define shm_realloc(args...) sfm_malloc(shm_block, ## args)
93
+	/* WARNING: test, especially if switched to real realloc */
94
+#	define shm_resize(args...)	sfm_realloc(shm_block, ## args)
95
+#	define shm_info(args...) sfm_info(shm_block, ## args)
96
+#endif /* __SUNPRO_C */
97
+#	define shm_malloc_unsafe  shm_malloc
98
+#	define shm_free_unsafe shm_free
99
+#	define shm_available	sfm_available(shm_block)
100
+#	define shm_status() sfm_status(shm_block)
101
+#	define shm_malloc_init sfm_malloc_init
102
+#	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
103
+#	define shm_malloc_on_fork()	sfm_pool_reset()
104
+#elif SF_MALLOC
105
+#	include "sf_malloc.h"
106
+#	define SHM_SAFE_MALLOC /* no need to lock */
107
+	extern struct sfm_block* shm_block;
108
+#ifdef __SUNPRO_C
109
+#	define shm_malloc(...) sfm_malloc(shm_block, __VA_ARGS__)
110
+#	define shm_free(...) sfm_free(shm_block, __VA_ARGS__)
111
+#	define shm_realloc(...) sfm_malloc(shm_block, __VA_ARGS__)
112
+	/* WARNING: test, especially if switched to real realloc */
113
+#	define shm_resize(...)	sfm_realloc(shm_block, __VA_ARGS__)
114
+#	define shm_info(...) sfm_info(shm_block, __VA_ARGS__)
115
+#else /* __SUNPRO_C */
116
+#	define shm_malloc(args...) sfm_malloc(shm_block, ## args)
117
+#	define shm_free(args...) sfm_free(shm_block, ## args)
118
+#	define shm_realloc(args...) sfm_malloc(shm_block, ## args)
119
+	/* WARNING: test, especially if switched to real realloc */
120
+#	define shm_resize(args...)	sfm_realloc(shm_block, ## args)
121
+#	define shm_info(args...) sfm_info(shm_block, ## args)
122
+#endif /* __SUNPRO_C */
123
+#	define shm_malloc_unsafe  shm_malloc
124
+#	define shm_free_unsafe shm_free
125
+#	define shm_available	sfm_available(shm_block)
126
+#	define shm_status() sfm_status(shm_block)
127
+#	define shm_malloc_init sfm_malloc_init
128
+#	define shm_malloc_destroy(b) sfm_malloc_destroy(b)
129
+#	define shm_malloc_on_fork()	sfm_pool_reset()
130
+#elif VQ_MALLOC
78 131
 #	include "vq_malloc.h"
79 132
 	extern struct vqm_block* shm_block;
80 133
 #	define MY_MALLOC vqm_malloc
81 134
 #	define MY_FREE vqm_free
82 135
 #	define MY_STATUS vqm_status
83 136
 #	define  shm_malloc_init vqm_malloc_init
137
+#	define shm_malloc_destroy(b) do{}while(0)
138
+#	define shm_malloc_on_fork() do{}while(0)
84 139
 #	warn "no proper vq_realloc implementation, try another memory allocator"
85 140
 #elif defined F_MALLOC
86 141
 #	include "f_malloc.h"
... ...
@@ -91,7 +146,9 @@
91 146
 #	define MY_STATUS fm_status
92 147
 #	define MY_MEMINFO	fm_info
93 148
 #	define  shm_malloc_init fm_malloc_init
149
+#	define shm_malloc_destroy(b) do{}while(0)
94 150
 #	define shm_available() fm_available(shm_block)
151
+#	define shm_malloc_on_fork() do{}while(0)
95 152
 #elif defined DL_MALLOC
96 153
 #	include "dl_malloc.h"
97 154
 	extern mspace shm_block;
... ...
@@ -101,6 +158,8 @@
101 158
 #	define MY_STATUS(...) 0
102 159
 #	define MY_MEMINFO	mspace_info
103 160
 #	define  shm_malloc_init(buf, len) create_mspace_with_base(buf, len, 0)
161
+#	define shm_malloc_destroy(b) do{}while(0)
162
+#	define shm_malloc_on_fork() do{}while(0)
104 163
 #else
105 164
 #	include "q_malloc.h"
106 165
 	extern struct qm_block* shm_block;
... ...
@@ -110,11 +169,14 @@
110 169
 #	define MY_STATUS qm_status
111 170
 #	define MY_MEMINFO	qm_info
112 171
 #	define  shm_malloc_init qm_malloc_init
172
+#	define shm_malloc_destroy(b) do{}while(0)
113 173
 #	define shm_available() qm_available(shm_block)
174
+#	define shm_malloc_on_fork() do{}while(0)
114 175
 #endif
115 176
 
116
-	
177
+#ifndef SHM_SAFE_MALLOC
117 178
 	extern gen_lock_t* mem_lock;
179
+#endif
118 180
 
119 181
 
120 182
 int shm_mem_init(int); /* calls shm_getmem & shm_mem_init_mallocs */
... ...
@@ -126,17 +188,21 @@ void shm_mem_destroy();
126 188
 
127 189
 
128 190
 
191
+#ifdef SHM_SAFE_MALLOC
192
+#define shm_lock() do{}while(0)
193
+#define shm_unlock() do{}while(0)
194
+
195
+#else /* ! SHM_SAFE_MALLOC */
196
+
129 197
 #define shm_lock()    lock_get(mem_lock)
130 198
 #define shm_unlock()  lock_release(mem_lock)
131 199
 
132
-
133 200
 #ifdef DBG_QM_MALLOC
134 201
 
135 202
 #ifdef __SUNPRO_C
136 203
 		#define __FUNCTION__ ""  /* gcc specific */
137 204
 #endif
138 205
 
139
-
140 206
 #define shm_malloc_unsafe(_size ) \
141 207
 	MY_MALLOC(shm_block, (_size), __FILE__, __FUNCTION__, __LINE__ )
142 208
 
... ...
@@ -234,7 +300,7 @@ void* _shm_resize(void* ptr, unsigned int size);
234 300
 /*#define shm_resize(_p, _s) shm_realloc( (_p), (_s))*/
235 301
 
236 302
 
237
-#endif
303
+#endif  /* DBG_QM_MALLOC */
238 304
 
239 305
 
240 306
 #define shm_status() \
... ...
@@ -252,8 +318,9 @@ do{\
252 318