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
Showing 12 changed files
... ...
@@ -44,7 +44,7 @@
44 44
  */
45 45
 
46 46
 
47
-#if !defined(q_malloc) && !(defined VQ_MALLOC)  && (defined F_MALLOC)
47
+#if !defined(q_malloc)  && (defined F_MALLOC)
48 48
 
49 49
 #include <string.h>
50 50
 #include <stdlib.h>
... ...
@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 
40
-#if !defined(f_malloc_h) && !defined(VQ_MALLOC) 
40
+#if !defined(f_malloc_h)
41 41
 #define f_malloc_h
42 42
 
43 43
 #ifdef DBG_QM_MALLOC
... ...
@@ -39,11 +39,7 @@
39 39
 #include "mem.h"
40 40
 
41 41
 #ifdef PKG_MALLOC
42
-	#ifdef VQ_MALLOC
43
-		#include "vq_malloc.h"
44
-	#else
45
-		#include "q_malloc.h"
46
-	#endif
42
+#include "q_malloc.h"
47 43
 #endif
48 44
 
49 45
 #ifdef SHM_MEM
... ...
@@ -55,9 +51,7 @@
55 55
 	char mem_pool[PKG_MEM_POOL_SIZE];
56 56
 	#endif
57 57
 
58
-	#ifdef VQ_MALLOC
59
-		struct vqm_block* mem_block;
60
-	#elif defined F_MALLOC
58
+	#ifdef F_MALLOC
61 59
 		struct fm_block* mem_block;
62 60
 	#elif defined DL_MALLOC
63 61
 		/* don't need this */
... ...
@@ -71,9 +65,7 @@ int init_pkg_mallocs()
71 71
 {
72 72
 #ifdef PKG_MALLOC
73 73
 	/*init mem*/
74
-	#ifdef VQ_MALLOC
75
-		mem_block=vqm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
76
-	#elif F_MALLOC
74
+	#ifdef F_MALLOC
77 75
 		mem_block=fm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
78 76
 	#elif DL_MALLOC
79 77
 		/* don't need this */
... ...
@@ -55,10 +55,7 @@
55 55
 #endif
56 56
 
57 57
 #ifdef PKG_MALLOC
58
-#	ifdef VQ_MALLOC
59
-#		include "vq_malloc.h"
60
-		extern struct vqm_block* mem_block;
61
-#	elif defined F_MALLOC
58
+#	ifdef F_MALLOC
62 59
 #		include "f_malloc.h"
63 60
 		extern struct fm_block* mem_block;
64 61
 #	elif defined DL_MALLOC
... ...
@@ -75,13 +72,7 @@
75 75
 #ifdef __SUNPRO_C
76 76
 		#define __FUNCTION__ ""  /* gcc specific */
77 77
 #endif
78
-#		ifdef VQ_MALLOC
79
-#			define pkg_malloc(s) vqm_malloc(mem_block, (s),__FILE__, \
80
-				__FUNCTION__, __LINE__)
81
-#			define pkg_free(p)   vqm_free(mem_block, (p), __FILE__,  \
82
-				__FUNCTION__, __LINE__)
83
-#			warn "no proper realloc implementation, use another mem. alloc"
84
-#		elif defined F_MALLOC
78
+#		ifdef F_MALLOC
85 79
 #			define pkg_malloc(s) fm_malloc(mem_block, (s),__FILE__, \
86 80
 				__FUNCTION__, __LINE__)
87 81
 #			define pkg_free(p)   fm_free(mem_block, (p), __FILE__,  \
... ...
@@ -97,10 +88,7 @@
97 97
 				__FUNCTION__, __LINE__)
98 98
 #		endif
99 99
 #	else
100
-#		ifdef VQ_MALLOC
101
-#			define pkg_malloc(s) vqm_malloc(mem_block, (s))
102
-#			define pkg_free(p)   vqm_free(mem_block, (p))
103
-#		elif defined F_MALLOC
100
+#		ifdef F_MALLOC
104 101
 #			define pkg_malloc(s) fm_malloc(mem_block, (s))
105 102
 #			define pkg_realloc(p, s) fm_realloc(mem_block, (p), (s))
106 103
 #			define pkg_free(p)   fm_free(mem_block, (p))
... ...
@@ -114,9 +102,7 @@
114 114
 #			define pkg_free(p)   qm_free(mem_block, (p))
115 115
 #		endif
116 116
 #	endif
117
-#	ifdef VQ_MALLOC
118
-#		define pkg_status()  vqm_status(mem_block)
119
-#	elif defined F_MALLOC
117
+#	ifdef F_MALLOC
120 118
 #		define pkg_status()    fm_status(mem_block)
121 119
 #		define pkg_info(mi)    fm_info(mem_block, mi)
122 120
 #		define pkg_available() fm_available(mem_block)
... ...
@@ -38,21 +38,12 @@
38 38
 
39 39
 #if 0
40 40
 #ifdef PKG_MALLOC
41
-#       ifdef VQ_MALLOC
42
-#               include "vq_malloc.h"
43
-#		define MY_MALLOC vqm_malloc
44
-#		define MY_FREE vqm_free
45
-#		define MY_INIT vqm_malloc_init
46
-#		define MY_BLOCK vqm_block
47
-#		define MY_STATUS vqm_status
48
-#       else
49
-#               include "q_malloc.h"
50
-#		define MY_MALLOC qm_malloc
51
-#		define MY_FREE qm_free
52
-#		define MY_INIT qm_malloc_init
53
-#		define MY_BLOCK qm_block
54
-#		define MY_STATUS qm_status
55
-#       endif
41
+#	include "q_malloc.h"
42
+#	define MY_MALLOC qm_malloc
43
+#	define MY_FREE qm_free
44
+#	define MY_INIT qm_malloc_init
45
+#	define MY_BLOCK qm_block
46
+#	define MY_STATUS qm_status
56 47
 #endif
57 48
 
58 49
 void memtest()
... ...
@@ -44,7 +44,7 @@
44 44
  */
45 45
 
46 46
 
47
-#if !defined(q_malloc) && !(defined VQ_MALLOC) && !(defined F_MALLOC)
47
+#if !defined(q_malloc) && !(defined F_MALLOC)
48 48
 #define q_malloc
49 49
 
50 50
 #include <stdlib.h>
... ...
@@ -36,7 +36,7 @@
36 36
  */
37 37
 
38 38
 
39
-#if !defined(q_malloc_h) && !defined(VQ_MALLOC) && !defined(F_MALLOC)
39
+#if !defined(q_malloc_h) && !defined(F_MALLOC)
40 40
 #define q_malloc_h
41 41
 
42 42
 #include "meminfo.h"
... ...
@@ -73,8 +73,6 @@ static void* shm_mempool=(void*)-1;
73 73
 	struct sfm_block* shm_block;
74 74
 #elif SF_MALLOC
75 75
 	struct sfm_block* shm_block;
76
-#elif VQ_MALLOC
77
-	struct vqm_block* shm_block;
78 76
 #elif F_MALLOC
79 77
 	struct fm_block* shm_block;
80 78
 #elif DL_MALLOC
... ...
@@ -110,26 +108,10 @@ void* _shm_resize( void* p, unsigned int s, const char* file, const char* func,
110 110
 void* _shm_resize( void* p , unsigned int s)
111 111
 #endif
112 112
 {
113
-#ifdef VQ_MALLOC
114
-	struct vqm_frag *f;
115
-#endif
116 113
 	if (p==0) {
117 114
 		DBG("WARNING:vqm_resize: resize(0) called\n");
118 115
 		return shm_malloc( s );
119 116
 	}
120
-#	ifdef DBG_QM_MALLOC
121
-#	ifdef VQ_MALLOC
122
-	f=(struct  vqm_frag*) ((char*)p-sizeof(struct vqm_frag));
123
-	MDBG("_shm_resize(%p, %d), called from %s: %s(%d)\n",  
124
-		p, s, file, func, line);
125
-	VQM_DEBUG_FRAG(shm_block, f);
126
-	if (p>(void *)shm_block->core_end || p<(void*)shm_block->init_core){
127
-		LOG(L_CRIT, "BUG: vqm_free: bad pointer %p (out of memory block!) - "
128
-				"aborting\n", p);
129
-		abort();
130
-	}
131
-#endif
132
-#	endif
133 117
 	return sh_realloc( p, s ); 
134 118
 }
135 119
 
... ...
@@ -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;
146 135
deleted file mode 100644
... ...
@@ -1,477 +0,0 @@
1
-/* $Id$
2
- *
3
- * Copyright (C) 2001-2003 FhG Fokus
4
- *
5
- * This file is part of ser, a free SIP server.
6
- *
7
- * ser is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version
11
- *
12
- * For a license to use the ser software under conditions
13
- * other than those described here, or to purchase support for this
14
- * software, please contact iptel.org by e-mail at the following addresses:
15
- *    info@iptel.org
16
- *
17
- * ser is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License 
23
- * along with this program; if not, write to the Free Software 
24
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
- * History: 
26
- * merged from Andrei's qmalloc and many fragments from Regents 
27
- * University of California NetBSD malloc used; see
28
- * http://www.ajk.tele.fi/libc/stdlib/malloc.c.html#malloc for more
29
- * details including redistribution policy; this policy asks for
30
- * displaying the copyright:
31
- * Copyright (c) 1983 Regents of the University of California.
32
- * All rights reserved.
33
- *
34
- *
35
- * About:
36
- * aggressive, wasteful and very quick malloc library built for
37
- * servers that continuously allocate and release chunks of only
38
- * few sizes:
39
- * - free lists are organized by size (which eliminates long list traversal 
40
- *   thru short free chunks if a long one is asked)
41
- * - quite a few sizes are supported --> this results in more waste
42
- *    (unused place in a chunk) however memory can be well reused after
43
- *    freeing
44
- * - the last bucket holds unlikely, huge, variable length chunks;
45
- *   they are maintained as stack growing from the opposite direction
46
- *   of our heap; coalescing is enabled; stack-like first-fit used to
47
- *   find free fragments
48
- *
49
- * TODO: possibly, some delayed coalescence wouldn't hurt; also, further
50
- * optimization will certainly speed-up the entire process a lot; using
51
- * knowledge of application as well as trying to make pipeline happy
52
- * (from which I am sadly far away now)
53
- * provides optimization space; trying to use other memory allocators
54
- * to compare would be a great thing to do too;
55
- *
56
- * also, comparing to other memory allocators (like Horde) would not
57
- * be a bad idea: those folks have been doing that for ages and specifically
58
- * Horde has been heavily optimized for multi-processor machines
59
- *
60
- * References:
61
- *   - list of malloc implementations: 
62
- *       http://www.cs.colorado.edu/~zorn/Malloc.html
63
- *   - a white-paper: http://g.oswego.edu/dl/html/malloc.html
64
- *   - Paul R. Wilson, Mark S. Johnstone, Michael Neely, and David Boles: 
65
- *      ``Dynamic Storage Allocation: A Survey and Critical Review'' in
66
- *      International Workshop on Memory Management, September 1995, 
67
- *      ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps
68
- *   - ptmalloc: http://www.malloc.de/en/
69
- *   - GNU C-lib malloc:
70
- *      http://www.gnu.org/manual/glibc-2.0.6/html_chapter/libc_3.html
71
- *   - delorie malocs: http://www.delorie.com/djgpp/malloc/
72
- *
73
- */
74
-
75
-
76
-#ifdef VQ_MALLOC
77
-
78
-#include <stdlib.h>
79
-
80
-#include "../config.h"
81
-#include "../globals.h"
82
-#include "vq_malloc.h"
83
-#include "../dprint.h"
84
-#include "../globals.h"
85
-
86
-#define BIG_BUCKET(_qm) ((_qm)->max_small_bucket+1)
87
-#define IS_BIGBUCKET(_qm, _bucket) ((_bucket)==BIG_BUCKET(_qm)) 
88
-
89
-#ifdef DBG_QM_MALLOC
90
-#define ASSERT(a)	\
91
-	my_assert(a, __LINE__, __FILE__, __FUNCTION__ )
92
-#else
93
-#define ASSERT(a)
94
-#endif
95
-
96
-#ifdef DBG_QM_MALLOC
97
-#	define MORE_CORE(_q,_b,_s)\
98
-				(more_core( (_q), (_b), (_s), file, func, line ))
99
-#else
100
-#	define MORE_CORE(_q,_b,_s) (more_core( (_q), (_b), (_s) ))
101
-#endif
102
-
103
-
104
-
105
-/* dimensioning buckets: define the step function constants for size2bucket */
106
-int s2b_step[] = {8, 16, 32, 64, 128, 256, 512, 1024, 1536, 2048, 2560,
107
-					MAX_FIXED_BLOCK, EO_STEP };
108
-
109
-void my_assert( int assertation, int line, char *file, char *function )
110
-{
111
-	if (assertation) return;
112
-
113
-	LOG(L_CRIT,"CRIT: assertation failed in %s (%s:%d)\n",
114
-		function, file, line);
115
-	abort();
116
-}
117
-
118
-#ifdef DBG_QM_MALLOC
119
-void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
120
-{
121
-
122
-
123
-	if (f->check!=ST_CHECK_PATTERN){
124
-		LOG(L_CRIT, "BUG: vqm_*: fragm. %p beginning overwritten(%x)!\n",
125
-				f, f->check);
126
-		vqm_status(qm);
127
-		abort();
128
-	};
129
-	if (memcmp(f->end_check, END_CHECK_PATTERN, END_CHECK_PATTERN_LEN)!=0) {
130
-		LOG(L_CRIT, "BUG: vqm_*: fragm. %p end overwritten(%.*s)!\n",
131
-				f, END_CHECK_PATTERN_LEN, f->end_check );
132
-		vqm_status(qm);
133
-		abort();
134
-	}
135
-}
136
-#endif
137
-
138
-
139
-/* takes  demanded size without overhead as input, returns bucket number
140
-   and changed the demanded size to size really used including all
141
-   possible overhead
142
- */
143
-unsigned char size2bucket( struct vqm_block* qm, int *size  )
144
-{
145
-	unsigned char b;	
146
-	unsigned int real_size;
147
-	unsigned int exceeds;
148
-
149
-	real_size = *size+ VQM_OVERHEAD;
150
-
151
-#ifdef DBG_QM_MALLOC
152
-	real_size+=END_CHECK_PATTERN_LEN;
153
-#endif
154
-	real_size+=((exceeds = (real_size % 8 )) ? 8 - exceeds : 0);
155
-	ASSERT( !(real_size%8) );
156
-	/* "small" chunk sizes <=1k translated using a table */
157
-	if ( real_size < MAX_FIXED_BLOCK ) {
158
-		b = qm->s2b[ real_size ];
159
-		*size = qm->s2s[ real_size ];
160
-	/* there might be various allocations slightly 1>1k, I still
161
-	   don't want to be too aggressive and increase useless 
162
-	   allocations in small steps
163
-    	*/	
164
-	} else {
165
-		b = BIG_BUCKET(qm); 
166
-		*size = MAX_FIXED_BLOCK + 
167
-			(real_size-MAX_FIXED_BLOCK+BLOCK_STEP) 
168
-			/ BLOCK_STEP * BLOCK_STEP;
169
-	}
170
-	/*size must be a multiple of 8*/
171
-	ASSERT( !(*size%8) );
172
-	return b;
173
-}
174
-
175
-
176
-/* init malloc and return a qm_block */
177
-struct vqm_block* vqm_malloc_init(char* address, unsigned int size)
178
-{
179
-	char* start;
180
-	struct vqm_block* qm;
181
-	unsigned int init_overhead;
182
-	unsigned char b;	/* bucket iterator */
183
-	unsigned int s;		/* size iterator */
184
-	char *end;
185
-	
186
-	/* make address and size multiple of 8*/
187
-	start=(char*)( ((unsigned int)address%8)?((unsigned int)address+8)/8*8:
188
-			(unsigned int)address);
189
-	if (size<start-address) return 0;
190
-	size-=(start-address);
191
-	if (size <8) return 0;
192
-	size=(size%8)?(size-8)/8*8:size;
193
-
194
-	init_overhead=sizeof(struct vqm_block);
195
-	if (size < init_overhead)
196
-	{
197
-		/* not enough mem to create our control structures !!!*/
198
-		return 0;
199
-	}
200
-	end = start + size;
201
-	qm=(struct vqm_block*)start;
202
-	memset(qm, 0, sizeof(struct vqm_block));
203
-	size-=init_overhead;
204
-
205
-	/* definition of the size2bucket table */
206
-	for (s=0, b=0; s<MAX_FIXED_BLOCK ; s++) {
207
-		while (s>s2b_step[b]) b++;
208
-		if (b>MAX_BUCKET) {
209
-			LOG(L_CRIT, "CRIT: vqm_malloc_init: attempt to install too"
210
-					" many buckets, s2b_step > MAX_BUCKET\n");
211
-			return 0;
212
-		}
213
-		qm->s2b[s] = b;
214
-		qm->s2s[s] = s2b_step[b];
215
-	}
216
-	qm->max_small_bucket = b;
217
-
218
-	/* from where we will draw memory */
219
-	qm->core = (char *) ( start + sizeof( struct vqm_block ) );
220
-	qm->free_core = size;
221
-	/* remember for bound checking */
222
-	qm->init_core = qm->core;
223
-	qm->core_end = end;
224
-	/* allocate big chunks from end */
225
-	qm->big_chunks = end;
226
-	
227
-	return qm;
228
-}
229
-
230
-
231
-
232
-struct vqm_frag *more_core(	struct vqm_block* qm, 
233
-				unsigned char bucket, unsigned int size
234
-#ifdef DBG_QM_MALLOC
235
-				, char *file, char *func, unsigned int line
236
-#endif
237
-			 ) 
238
-{
239
-	struct vqm_frag *new_chunk;
240
-	struct vqm_frag_end *end;
241
-
242
-	if (qm->free_core<size) return 0;
243
-
244
-	/* update core */
245
-	if (IS_BIGBUCKET(qm, bucket)) {
246
-		qm->big_chunks-=size;
247
-		new_chunk = (struct vqm_frag *) qm->big_chunks ;	
248
-	} else {
249
-		new_chunk = (struct vqm_frag *) qm->core;	
250
-		qm->core+=size;
251
-	}
252
-	qm->free_core-=size;
253
-
254
-	/* initialize the new fragment */
255
-	new_chunk->u.inuse.bucket = bucket;
256
-	new_chunk->size = size;
257
-
258
-	end=FRAG_END( new_chunk );
259
-	end->size=size;
260
-
261
-	return new_chunk;
262
-}
263
-
264
-static inline void vqm_detach_free( struct vqm_block* qm,
265
-									struct vqm_frag* frag)
266
-{
267
-
268
-	struct vqm_frag *prev, *next;
269
-
270
-	prev=FRAG_END(frag)->prv_free; 
271
-	next=frag->u.nxt_free;
272
-
273
-	if (prev) prev->u.nxt_free=next; 
274
-	else qm->next_free[BIG_BUCKET(qm)]=next;
275
-
276
-	if (next) FRAG_END(next)->prv_free=prev; 
277
-	 
278
-}
279
-
280
-
281
-#ifdef DBG_QM_MALLOC
282
-void* vqm_malloc(struct vqm_block* qm, unsigned int size, 
283
-	char* file, char* func, unsigned int line)
284
-#else
285
-void* vqm_malloc(struct vqm_block* qm, unsigned int size)
286
-#endif
287
-{
288
-	struct vqm_frag *new_chunk, *f;
289
-	unsigned char bucket;
290
-	
291
-#ifdef DBG_QM_MALLOC
292
-	unsigned int demanded_size;
293
-	DBG("vqm_malloc(%p, %d) called from %s: %s(%d)\n", qm, size, file,
294
-	 func, line);
295
-	demanded_size = size;
296
-#endif
297
-	new_chunk=0;
298
-    	/* what's the bucket? what's the total size incl. overhead? */
299
-	bucket = size2bucket( qm, &size );
300
-
301
-	if (IS_BIGBUCKET(qm, bucket)) {	/* the kilo-bucket uses first-fit */
302
-#ifdef DBG_QM_MALLOC
303
-		DBG("vqm_malloc: processing a big fragment\n");
304
-#endif
305
-		for (f=qm->next_free[bucket] ; f; f=f->u.nxt_free ) 
306
-			if (f->size>=size) { /* first-fit */
307
-				new_chunk=f;
308
-				VQM_DEBUG_FRAG(qm, f);
309
-				vqm_detach_free(qm,f);
310
-				break;
311
-			}
312
-	} else if (  (new_chunk=qm->next_free[ bucket ]) ) { /*fixed size bucket*/
313
-			VQM_DEBUG_FRAG(qm, new_chunk);
314
-			/*detach it from the head of bucket's free list*/
315
-			qm->next_free[ bucket ] = new_chunk->u.nxt_free;
316
-	}
317
-
318
-	if (!new_chunk) { /* no chunk can be reused; slice one from the core */
319
-		new_chunk=MORE_CORE( qm, bucket, size );
320
-		if (!new_chunk) {
321
-#ifdef DBG_QM_MALLOC
322
-			LOG(L_DBG, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
323
-				qm, size, file, func, line);
324
-#else
325
-			LOG(L_DBG, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
326
-				qm, size);
327
-#endif
328
-			return 0;
329
-		}
330
-	}
331
-	new_chunk->u.inuse.magic = FR_USED;
332
-	new_chunk->u.inuse.bucket=bucket;
333
-#ifdef DBG_QM_MALLOC
334
-	new_chunk->file=file;
335
-	new_chunk->func=func;
336
-	new_chunk->line=line;
337
-	new_chunk->demanded_size=demanded_size;
338
-	qm->usage[ bucket ]++;
339
-	DBG("vqm_malloc( %p, %d ) returns address %p in bucket %d, real-size %d\n",
340
-		qm, demanded_size, (char*)new_chunk+sizeof(struct vqm_frag), 
341
-		bucket, size );
342
-
343
-	new_chunk->end_check=(char*)new_chunk+
344
-							sizeof(struct vqm_frag)+demanded_size;
345
-	memcpy(  new_chunk->end_check, END_CHECK_PATTERN, END_CHECK_PATTERN_LEN );
346
-	new_chunk->check=ST_CHECK_PATTERN;
347
-#endif
348
-	return (char*)new_chunk+sizeof(struct vqm_frag);
349
-}
350
-
351
-#ifdef DBG_QM_MALLOC
352
-void vqm_free(struct vqm_block* qm, void* p, char* file, char* func, 
353
-				unsigned int line)
354
-#else
355
-void vqm_free(struct vqm_block* qm, void* p)
356
-#endif
357
-{
358
-	struct vqm_frag *f, *next, *prev, *first_big;
359
-	unsigned char b;
360
-
361
-#ifdef DBG_QM_MALLOC
362
-	DBG("vqm_free(%p, %p), called from %s: %s(%d)\n", 
363
-		qm, p, file, func, line);
364
-	if (p>(void *)qm->core_end || p<(void*)qm->init_core){
365
-		LOG(L_CRIT, "BUG: vqm_free: bad pointer %p (out of memory block!) - "
366
-				"aborting\n", p);
367
-		abort();
368
-	}
369
-#endif
370
-	if (p==0) {
371
-		DBG("WARNING:vqm_free: free(0) called\n");
372
-		return;
373
-	}
374
-	f=(struct  vqm_frag*) ((char*)p-sizeof(struct vqm_frag));
375
-	b=f->u.inuse.bucket;
376
-#ifdef DBG_QM_MALLOC
377
-	VQM_DEBUG_FRAG(qm, f);
378
-	if ( ! FRAG_ISUSED(f) ) {
379
-		LOG(L_CRIT, "BUG: vqm_free: freeing already freed pointer,"
380
-				" first freed: %s: %s(%d) - aborting\n",
381
-				f->file, f->func, f->line);
382
-		abort();
383
-	}
384
-	if ( b>MAX_BUCKET ) {
385
-		LOG(L_CRIT, "BUG: vqm_free: fragment with too high bucket nr: "
386
-				"%d, allocated: %s: %s(%d) - aborting\n",
387
-				b, f->file, f->func, f->line); 
388
-		abort();
389
-	}
390
-	DBG("vqm_free: freeing %d bucket block alloc'ed from %s: %s(%d)\n", 
391
-		f->u.inuse.bucket, f->file, f->func, f->line);
392
-	f->file=file; f->func=func; f->line=line;
393
-	qm->usage[ f->u.inuse.bucket ]--;
394
-#endif
395
-	if (IS_BIGBUCKET(qm,b)) {
396
-		next=FRAG_NEXT(f);
397
-		if  ((char *)next +sizeof( struct vqm_frag) < qm->core_end) {
398
-			VQM_DEBUG_FRAG(qm, next);
399
-			if (! FRAG_ISUSED(next)) { /* coalesce with next fragment */
400
-				DBG("vqm_free: coalesced with next\n");
401
-				vqm_detach_free(qm, next);
402
-				f->size+=next->size;
403
-				FRAG_END(f)->size=f->size;
404
-			}
405
-		}
406
-		first_big = qm->next_free[b];
407
-		if (first_big &&  f>first_big) {
408
-			prev=FRAG_PREV(f);
409
-			VQM_DEBUG_FRAG(qm, prev);
410
-			if (!FRAG_ISUSED(prev)) { /* coalesce with prev fragment */
411
-				DBG("vqm_free: coalesced with prev\n");
412
-				vqm_detach_free(qm, prev );
413
-				prev->size+=f->size;
414
-				f=prev;
415
-				FRAG_END(f)->size=f->size;
416
-			}
417
-		}
418
-		if ((char *)f==qm->big_chunks) { /* release unused core */
419
-			DBG("vqm_free: big chunk released\n");
420
-			qm->free_core+=f->size;
421
-			qm->big_chunks+=f->size;
422
-			return;
423
-		}		
424
-		first_big = qm->next_free[b];
425
-		/* fix reverse link (used only for BIG_BUCKET */
426
-		if (first_big) FRAG_END(first_big)->prv_free=f;
427
-		FRAG_END(f)->prv_free=0;
428
-	} else first_big = qm->next_free[b];
429
-	f->u.nxt_free = first_big; /* also clobbers magic */
430
-	qm->next_free[b] = f;
431
-}
432
-
433
-void dump_frag( struct vqm_frag* f, int i )
434
-{
435
-	LOG(memlog, "    %3d. address=%p  real size=%d bucket=%d\n", i, 
436
-		(char*)f+sizeof(struct vqm_frag), f->size, f->u.inuse.bucket);
437
-#ifdef DBG_QM_MALLOC
438
-	LOG(memlog, "            demanded size=%d\n", f->demanded_size );
439
-	LOG(memlog, "            alloc'd from %s: %s(%d)\n",
440
-		f->file, f->func, f->line);
441
-	LOG(memlog, "        start check=%x, end check= %.*s\n",
442
-			f->check, END_CHECK_PATTERN_LEN, f->end_check );
443
-#endif
444
-}
445
-
446
-void vqm_status(struct vqm_block* qm)
447
-{
448
-	struct vqm_frag* f;
449
-	unsigned int i,on_list;
450
-
451
-	LOG(memlog, "vqm_status (%p):\n", qm);
452
-	if (!qm) return;
453
-	LOG(memlog, " heap size= %d, available: %d\n", 
454
-		qm->core_end-qm->init_core, qm->free_core );
455
-	
456
-	LOG(memlog, "dumping unfreed fragments:\n");
457
-	for (f=(struct vqm_frag*)qm->init_core, i=0;(char*)f<(char*)qm->core;
458
-		f=FRAG_NEXT(f) ,i++) if ( FRAG_ISUSED(f) ) dump_frag(f, i);
459
-
460
-	LOG(memlog, "dumping unfreed big fragments:\n");
461
-    for (f=(struct vqm_frag*)qm->big_chunks,i=0;(char*)f<(char*)qm->core_end;
462
-		f=FRAG_NEXT(f) ,i++) if ( FRAG_ISUSED(f) ) dump_frag( f, i );
463
-
464
-#ifdef DBG_QM_MALLOC
465
-	DBG("dumping bucket statistics:\n");
466
-	for (i=0; i<=BIG_BUCKET(qm); i++) {
467
-		for(on_list=0, f=qm->next_free[i]; f; f=f->u.nxt_free ) on_list++;
468
-		LOG(L_DBG, "    %3d. bucket: in use: %ld, on free list: %d\n", 
469
-			i, qm->usage[i], on_list );
470
-	}
471
-#endif
472
-	LOG(memlog, "-----------------------------\n");
473
-}
474
-
475
-
476
-
477
-#endif
478 1
deleted file mode 100644
... ...
@@ -1,154 +0,0 @@
1
-/* $Id$
2
- *
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * This file is part of ser, a free SIP server.
7
- *
8
- * ser is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18
- * ser is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License 
24
- * along with this program; if not, write to the Free Software 
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
- */
27
-
28
-
29
-#if !defined(VQ_MALLOC_H) && defined(VQ_MALLOC)
30
-#define VQ_MALLOC_H
31
-
32
-#include "../config.h"
33
-
34
-
35
-/* indicates this fragment is not in use (must not be offset of valid
36
-   aligned fragment beginning
37
-*/
38
-#define	FR_USED		0xef
39
-
40
-/*useful macros*/
41
-#define FRAG_END(f)  \
42
-	((struct vqm_frag_end*)((char*)(f)-sizeof(struct vqm_frag_end)+ \
43
-	(f)->size))
44
-
45
-#define FRAG_NEXT(f) \
46
-	((struct vqm_frag*)((char*)(f)+(f)->size))
47
-
48
-#define PREV_FRAG_END(f) \
49
-	((struct vqm_frag_end*)((char*)(f)-sizeof(struct vqm_frag_end)))
50
-
51
-#define FRAG_PREV(f) \
52
-	( (struct vqm_frag*) ( (char*)(f) - PREV_FRAG_END(f)->size ))
53
-
54
-#define FRAG_ISUSED(f) \
55
-	((f)->u.inuse.magic==FR_USED)
56
-
57
-/* just a bumper for the step function */
58
-#define EO_STEP                         -1
59
-
60
-
61
-#ifdef DBG_QM_MALLOC
62
-#	define ST_CHECK_PATTERN   	0xf0f0f0f0
63
-#	define END_CHECK_PATTERN  	"sExP"
64
-#	define END_CHECK_PATTERN_LEN 	4
65
-#	define VQM_OVERHEAD (sizeof(struct vqm_frag)+ \
66
-							sizeof(struct vqm_frag_end)+END_CHECK_PATTERN_LEN)
67
-#	define VQM_DEBUG_FRAG(qm, f) vqm_debug_frag( (qm), (f))
68
-#else
69
-#	define VQM_DEBUG_FRAG(qm, f)
70
-#	define VQM_OVERHEAD (sizeof(struct vqm_frag)+ sizeof(struct vqm_frag_end))
71
-#endif
72
-
73
-
74
-
75
-struct vqm_frag {
76
-	/* XXX */
77
-	/* total chunk size including all overhead/bellowfoot/roundings/etc */
78
-	/* useless as otherwise size implied by bucket (if I really want to save 
79
-       bytes, I'll remove it  from here */
80
-	unsigned long size;
81
-	union{
82
-		/* pointer to next chunk in a bucket if free */
83
-		struct vqm_frag* nxt_free; 
84
-		struct {   /* or bucket number if busy */
85
-			unsigned char magic;
86
-			unsigned char bucket;
87
-        } inuse;
88
-	} u;
89
-#ifdef DBG_QM_MALLOC
90
-	/* source code info */
91
-	char* file;
92
-	char* func;
93
-	unsigned long line;
94
-	/* your safety is important to us! safety signatures */
95
-	unsigned long check;
96
-	char *end_check;
97
-	/* the size user was originally asking for */
98
-	unsigned long demanded_size;
99
-#endif
100
-};
101
-
102
-struct vqm_frag_end{
103
-	/* total chunk size including all overhead/bellowfoot/roundings/etc */
104
-	unsigned long size; 
105
-	/* XXX */
106
-	/* used only for variable-size chunks; might have different
107
-           data structures for variable/fixed length chunks */
108
-	struct vqm_frag* prv_free;
109
-};
110
-
111
-
112
-struct vqm_block{
113
-	/* size to bucket table */
114
-	unsigned char s2b[ MAX_FIXED_BLOCK ];
115
-	/* size to rounded size */
116
-	unsigned short s2s[ MAX_FIXED_BLOCK ];
117
-	unsigned char max_small_bucket;
118
-
119
-	/* core gained on init ... */
120
-	char *core, *init_core, *core_end;
121
-	/* ... and its available net amount; note that there's lot of
122
-           free memory in buckets too -- this just tells about memory
123
-	   which has not been assigned to chunks  */
124
-	unsigned long free_core;
125
-	/* we allocate huge chunks from the end on; this is the
126
-	   pointer to big chunks
127
-    */
128
-	char *big_chunks;
129
-
130
-	struct vqm_frag* next_free[ MAX_BUCKET +1];
131
-#ifdef DBG_QM_MALLOC
132
-	unsigned long usage[ MAX_BUCKET +1];
133
-#endif
134
-};
135
-
136
-
137
-
138
-struct vqm_block* vqm_malloc_init(char* address, unsigned int size);
139
-
140
-#ifdef DBG_QM_MALLOC
141
-void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f);
142
-void* vqm_malloc(struct vqm_block*, unsigned int size, char* file, char* func, 
143
-					unsigned int line);
144
-void  vqm_free(struct vqm_block*, void* p, char* file, char* func, 
145
-				unsigned int line);
146
-#else
147
-void* vqm_malloc(struct vqm_block*, unsigned int size);
148
-void  vqm_free(struct vqm_block*, void* p);
149
-#endif
150
-
151
-void  vqm_status(struct vqm_block*);
152
-
153
-
154
-#endif
... ...
@@ -131,12 +131,6 @@
131 131
 #define PKG_MALLOC_STR ""
132 132
 #endif
133 133
 
134
-#ifdef VQ_MALLOC
135
-#define VQ_MALLOC_STR ", VQ_MALLOC"
136
-#else
137
-#define VQ_MALLOC_STR ""
138
-#endif
139
-
140 134
 #ifdef F_MALLOC
141 135
 #define F_MALLOC_STR ", F_MALLOC"
142 136
 #else
... ...
@@ -343,7 +337,7 @@
343 343
 	USE_SCTP_STR CORE_TLS_STR TLS_HOOKS_STR \
344 344
 	USE_STUN_STR DISABLE_NAGLE_STR USE_MCAST_STR NO_DEBUG_STR NO_LOG_STR \
345 345
 	NO_SIG_DEBUG_STR DNS_IP_HACK_STR  SHM_MEM_STR SHM_MMAP_STR PKG_MALLOC_STR \
346
-	VQ_MALLOC_STR F_MALLOC_STR DL_MALLOC_STR SF_MALLOC_STR  LL_MALLOC_STR \
346
+	F_MALLOC_STR DL_MALLOC_STR SF_MALLOC_STR  LL_MALLOC_STR \
347 347
 	USE_SHM_MEM_STR \
348 348
 	DBG_QM_MALLOC_STR \
349 349
 	DBG_F_MALLOC_STR DEBUG_DMALLOC_STR DBG_SF_MALLOC_STR DBG_LL_MALLOC_STR \