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
1 1
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
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:58:23
Showing 1 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /* $Id$
2 2
  *
3
- * Copyright (C) 2001-2003 Fhg Fokus
3
+ * Copyright (C) 2001-2003 FhG Fokus
4 4
  *
5 5
  * This file is part of ser, a free SIP server.
6 6
  *
... ...
@@ -34,7 +34,7 @@
34 34
  *
35 35
  * About:
36 36
  * aggressive, wasteful and very quick malloc library built for
37
- * servers that continuously alocate and release chunks of only
37
+ * servers that continuously allocate and release chunks of only
38 38
  * few sizes:
39 39
  * - free lists are organized by size (which eliminates long list traversal 
40 40
  *   thru short free chunks if a long one is asked)
... ...
@@ -43,17 +43,17 @@
43 43
  *    freeing
44 44
  * - the last bucket holds unlikely, huge, variable length chunks;
45 45
  *   they are maintained as stack growing from the opposite direction
46
- *   of our heap; coalesing is enabled; stack-like first-fit used to
46
+ *   of our heap; coalescing is enabled; stack-like first-fit used to
47 47
  *   find free fragments
48 48
  *
49
- * TODO: possibly, some delayed coalescation wouldn't hurt; also, further
49
+ * TODO: possibly, some delayed coalescence wouldn't hurt; also, further
50 50
  * optimization will certainly speed-up the entire process a lot; using
51 51
  * knowledge of application as well as trying to make pipeline happy
52 52
  * (from which I am sadly far away now)
53 53
  * provides optimization space; trying to use other memory allocators
54 54
  * to compare would be a great thing to do too;
55 55
  *
56
- * also, comparing to other memory allocaters (like Horde) would not
56
+ * also, comparing to other memory allocators (like Horde) would not
57 57
  * be a bad idea: those folks have been doing that for ages and specifically
58 58
  * Horde has been heavily optimized for multi-processor machines
59 59
  *
... ...
@@ -158,7 +158,7 @@ unsigned char size2bucket( struct vqm_block* qm, int *size  )
158 158
 		b = qm->s2b[ real_size ];
159 159
 		*size = qm->s2s[ real_size ];
160 160
 	/* there might be various allocations slightly 1>1k, I still
161
-	   don't want to be too agressive and increase useless 
161
+	   don't want to be too aggressive and increase useless 
162 162
 	   allocations in small steps
163 163
     	*/	
164 164
 	} else {
... ...
@@ -396,8 +396,8 @@ void vqm_free(struct vqm_block* qm, void* p)
396 396
 		next=FRAG_NEXT(f);
397 397
 		if  ((char *)next +sizeof( struct vqm_frag) < qm->core_end) {
398 398
 			VQM_DEBUG_FRAG(qm, next);
399
-			if (! FRAG_ISUSED(next)) { /* coalescate with next fragment */
400
-				DBG("vqm_free: coalescated with next\n");
399
+			if (! FRAG_ISUSED(next)) { /* coalesce with next fragment */
400
+				DBG("vqm_free: coalesced with next\n");
401 401
 				vqm_detach_free(qm, next);
402 402
 				f->size+=next->size;
403 403
 				FRAG_END(f)->size=f->size;
... ...
@@ -407,8 +407,8 @@ void vqm_free(struct vqm_block* qm, void* p)
407 407
 		if (first_big &&  f>first_big) {
408 408
 			prev=FRAG_PREV(f);
409 409
 			VQM_DEBUG_FRAG(qm, prev);
410
-			if (!FRAG_ISUSED(prev)) { /* coalescate with prev fragment */
411
-				DBG("vqm_free: coalescated with prev\n");
410
+			if (!FRAG_ISUSED(prev)) { /* coalesce with prev fragment */
411
+				DBG("vqm_free: coalesced with prev\n");
412 412
 				vqm_detach_free(qm, prev );
413 413
 				prev->size+=f->size;
414 414
 				f=prev;
Browse code

- cosmetic changes (lines too long a.s.o)

Andrei Pelinescu-Onciul authored on 20/09/2002 09:29:07
Showing 1 changed files
... ...
@@ -58,14 +58,16 @@
58 58
  * Horde has been heavily optimized for multi-processor machines
59 59
  *
60 60
  * References:
61
- *   - list of malloc implementations: http://www.cs.colorado.edu/~zorn/Malloc.html
61
+ *   - list of malloc implementations: 
62
+ *       http://www.cs.colorado.edu/~zorn/Malloc.html
62 63
  *   - a white-paper: http://g.oswego.edu/dl/html/malloc.html
63 64
  *   - Paul R. Wilson, Mark S. Johnstone, Michael Neely, and David Boles: 
64
-       ``Dynamic Storage Allocation: A Survey and Critical Review'' in International 
65
-       Workshop on Memory Management, September 1995, 
66
-       ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps
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
67 68
  *   - ptmalloc: http://www.malloc.de/en/
68
- *   - GNU C-lib malloc: http://www.gnu.org/manual/glibc-2.0.6/html_chapter/libc_3.html
69
+ *   - GNU C-lib malloc:
70
+ *      http://www.gnu.org/manual/glibc-2.0.6/html_chapter/libc_3.html
69 71
  *   - delorie malocs: http://www.delorie.com/djgpp/malloc/
70 72
  *
71 73
  */
... ...
@@ -92,7 +94,8 @@
92 94
 #endif
93 95
 
94 96
 #ifdef DBG_QM_MALLOC
95
-#	define MORE_CORE(_q,_b,_s) (more_core( (_q), (_b), (_s), file, func, line ))
97
+#	define MORE_CORE(_q,_b,_s)\
98
+				(more_core( (_q), (_b), (_s), file, func, line ))
96 99
 #else
97 100
 #	define MORE_CORE(_q,_b,_s) (more_core( (_q), (_b), (_s) ))
98 101
 #endif
... ...
@@ -100,7 +103,8 @@
100 103
 
101 104
 
102 105
 /* dimensioning buckets: define the step function constants for size2bucket */
103
-int s2b_step[] = {8, 16, 32, 64, 128, 256, 512, 1024, 1536, 2048, 2560, MAX_FIXED_BLOCK, EO_STEP };
106
+int s2b_step[] = {8, 16, 32, 64, 128, 256, 512, 1024, 1536, 2048, 2560,
107
+					MAX_FIXED_BLOCK, EO_STEP };
104 108
 
105 109
 void my_assert( int assertation, int line, char *file, char *function )
106 110
 {
... ...
@@ -202,8 +206,8 @@ struct vqm_block* vqm_malloc_init(char* address, unsigned int size)
202 206
 	for (s=0, b=0; s<MAX_FIXED_BLOCK ; s++) {
203 207
 		while (s>s2b_step[b]) b++;
204 208
 		if (b>MAX_BUCKET) {
205
-			LOG(L_CRIT, "CRIT: vqm_malloc_init: attempt to install too many buckets,"
206
-				"s2b_step > MAX_BUCKET\n");
209
+			LOG(L_CRIT, "CRIT: vqm_malloc_init: attempt to install too"
210
+					" many buckets, s2b_step > MAX_BUCKET\n");
207 211
 			return 0;
208 212
 		}
209 213
 		qm->s2b[s] = b;
... ...
@@ -257,7 +261,8 @@ struct vqm_frag *more_core(	struct vqm_block* qm,
257 261
 	return new_chunk;
258 262
 }
259 263
 
260
-static inline void vqm_detach_free( struct vqm_block* qm, struct vqm_frag* frag)
264
+static inline void vqm_detach_free( struct vqm_block* qm,
265
+									struct vqm_frag* frag)
261 266
 {
262 267
 
263 268
 	struct vqm_frag *prev, *next;
... ...
@@ -331,11 +336,12 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
331 336
 	new_chunk->line=line;
332 337
 	new_chunk->demanded_size=demanded_size;
333 338
 	qm->usage[ bucket ]++;
334
-	DBG("vqm_malloc( %p, %d ) returns address %p in bucket %d, real-size %d \n",
339
+	DBG("vqm_malloc( %p, %d ) returns address %p in bucket %d, real-size %d\n",
335 340
 		qm, demanded_size, (char*)new_chunk+sizeof(struct vqm_frag), 
336 341
 		bucket, size );
337 342
 
338
-	new_chunk->end_check=(char*)new_chunk+sizeof(struct vqm_frag)+demanded_size;
343
+	new_chunk->end_check=(char*)new_chunk+
344
+							sizeof(struct vqm_frag)+demanded_size;
339 345
 	memcpy(  new_chunk->end_check, END_CHECK_PATTERN, END_CHECK_PATTERN_LEN );
340 346
 	new_chunk->check=ST_CHECK_PATTERN;
341 347
 #endif
Browse code

GPLization banner introduced to *.[hc] files

Jiri Kuthan authored on 19/09/2002 12:23:52
Showing 1 changed files
... ...
@@ -1,5 +1,27 @@
1 1
 /* $Id$
2 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
3 25
  * History: 
4 26
  * merged from Andrei's qmalloc and many fragments from Regents 
5 27
  * University of California NetBSD malloc used; see
... ...
@@ -45,8 +67,10 @@
45 67
  *   - ptmalloc: http://www.malloc.de/en/
46 68
  *   - GNU C-lib malloc: http://www.gnu.org/manual/glibc-2.0.6/html_chapter/libc_3.html
47 69
  *   - delorie malocs: http://www.delorie.com/djgpp/malloc/
70
+ *
48 71
  */
49 72
 
73
+
50 74
 #ifdef VQ_MALLOC
51 75
 
52 76
 #include <stdlib.h>
Browse code

memlog option introduced

Jiri Kuthan authored on 10/09/2002 10:40:54
Showing 1 changed files
... ...
@@ -55,6 +55,7 @@
55 55
 #include "../globals.h"
56 56
 #include "vq_malloc.h"
57 57
 #include "../dprint.h"
58
+#include "../globals.h"
58 59
 
59 60
 #define BIG_BUCKET(_qm) ((_qm)->max_small_bucket+1)
60 61
 #define IS_BIGBUCKET(_qm, _bucket) ((_bucket)==BIG_BUCKET(_qm)) 
... ...
@@ -401,13 +402,13 @@ void vqm_free(struct vqm_block* qm, void* p)
401 402
 
402 403
 void dump_frag( struct vqm_frag* f, int i )
403 404
 {
404
-	LOG(L_INFO, "    %3d. address=%p  real size=%d bucket=%d\n", i, 
405
+	LOG(memlog, "    %3d. address=%p  real size=%d bucket=%d\n", i, 
405 406
 		(char*)f+sizeof(struct vqm_frag), f->size, f->u.inuse.bucket);
406 407
 #ifdef DBG_QM_MALLOC
407
-	LOG(L_INFO, "            demanded size=%d\n", f->demanded_size );
408
-	LOG(L_INFO, "            alloc'd from %s: %s(%d)\n",
408
+	LOG(memlog, "            demanded size=%d\n", f->demanded_size );
409
+	LOG(memlog, "            alloc'd from %s: %s(%d)\n",
409 410
 		f->file, f->func, f->line);
410
-	LOG(L_INFO, "        start check=%x, end check= %.*s\n",
411
+	LOG(memlog, "        start check=%x, end check= %.*s\n",
411 412
 			f->check, END_CHECK_PATTERN_LEN, f->end_check );
412 413
 #endif
413 414
 }
... ...
@@ -417,16 +418,16 @@ void vqm_status(struct vqm_block* qm)
417 418
 	struct vqm_frag* f;
418 419
 	unsigned int i,on_list;
419 420
 
420
-	LOG(L_INFO, "vqm_status (%p):\n", qm);
421
+	LOG(memlog, "vqm_status (%p):\n", qm);
421 422
 	if (!qm) return;
422
-	LOG(L_INFO, " heap size= %d, available: %d\n", 
423
+	LOG(memlog, " heap size= %d, available: %d\n", 
423 424
 		qm->core_end-qm->init_core, qm->free_core );
424 425
 	
425
-	LOG(L_INFO, "dumping unfreed fragments:\n");
426
+	LOG(memlog, "dumping unfreed fragments:\n");
426 427
 	for (f=(struct vqm_frag*)qm->init_core, i=0;(char*)f<(char*)qm->core;
427 428
 		f=FRAG_NEXT(f) ,i++) if ( FRAG_ISUSED(f) ) dump_frag(f, i);
428 429
 
429
-	LOG(L_INFO, "dumping unfreed big fragments:\n");
430
+	LOG(memlog, "dumping unfreed big fragments:\n");
430 431
     for (f=(struct vqm_frag*)qm->big_chunks,i=0;(char*)f<(char*)qm->core_end;
431 432
 		f=FRAG_NEXT(f) ,i++) if ( FRAG_ISUSED(f) ) dump_frag( f, i );
432 433
 
... ...
@@ -438,7 +439,7 @@ void vqm_status(struct vqm_block* qm)
438 439
 			i, qm->usage[i], on_list );
439 440
 	}
440 441
 #endif
441
-	LOG(L_INFO, "-----------------------------\n");
442
+	LOG(memlog, "-----------------------------\n");
442 443
 }
443 444
 
444 445
 
Browse code

- added aliases (names that ser will think are his own) - now the offical name will be put in sock_info[r] and the aliases in the. host_alias list. - added new script config. parameter: alias=

Andrei Pelinescu-Onciul authored on 20/08/2002 09:34:12
Showing 1 changed files
... ...
@@ -98,7 +98,7 @@ void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
98 98
 		abort();
99 99
 	};
100 100
 	if (memcmp(f->end_check, END_CHECK_PATTERN, END_CHECK_PATTERN_LEN)!=0) {
101
-		LOG(L_CRIT, "BUG: vqm_*: fragm. %p end overwritten(%*s)!\n",
101
+		LOG(L_CRIT, "BUG: vqm_*: fragm. %p end overwritten(%.*s)!\n",
102 102
 				f, END_CHECK_PATTERN_LEN, f->end_check );
103 103
 		vqm_status(qm);
104 104
 		abort();
Browse code

output noise reduced

Jiri Kuthan authored on 18/08/2002 19:18:49
Showing 1 changed files
... ...
@@ -269,7 +269,9 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
269 269
 	bucket = size2bucket( qm, &size );
270 270
 
271 271
 	if (IS_BIGBUCKET(qm, bucket)) {	/* the kilo-bucket uses first-fit */
272
+#ifdef DBG_QM_MALLOC
272 273
 		DBG("vqm_malloc: processing a big fragment\n");
274
+#endif
273 275
 		for (f=qm->next_free[bucket] ; f; f=f->u.nxt_free ) 
274 276
 			if (f->size>=size) { /* first-fit */
275 277
 				new_chunk=f;
... ...
@@ -286,8 +288,13 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
286 288
 	if (!new_chunk) { /* no chunk can be reused; slice one from the core */
287 289
 		new_chunk=MORE_CORE( qm, bucket, size );
288 290
 		if (!new_chunk) {
289
-			LOG(L_ERR, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
291
+#ifdef DBG_QM_MALLOC
292
+			LOG(L_DBG, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
290 293
 				qm, size, file, func, line);
294
+#else
295
+			LOG(L_DBG, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
296
+				qm, size);
297
+#endif
291 298
 			return 0;
292 299
 		}
293 300
 	}
Browse code

bignag change -- lot of things primarily added in relationship with refurbushing TM; see [sr] archive (2002-08-14) -- "ser update" and "TM update" for a long list of details

Jiri Kuthan authored on 15/08/2002 08:13:29
Showing 1 changed files
... ...
@@ -49,6 +49,8 @@
49 49
 
50 50
 #ifdef VQ_MALLOC
51 51
 
52
+#include <stdlib.h>
53
+
52 54
 #include "../config.h"
53 55
 #include "../globals.h"
54 56
 #include "vq_malloc.h"
... ...
@@ -79,7 +81,7 @@ void my_assert( int assertation, int line, char *file, char *function )
79 81
 {
80 82
 	if (assertation) return;
81 83
 
82
-	LOG(L_CRIT,"CRIT: assertation failed in $s (%s:%d)\n",
84
+	LOG(L_CRIT,"CRIT: assertation failed in %s (%s:%d)\n",
83 85
 		function, file, line);
84 86
 	abort();
85 87
 }
... ...
@@ -88,16 +90,15 @@ void my_assert( int assertation, int line, char *file, char *function )
88 90
 void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
89 91
 {
90 92
 
91
-	int r;
92 93
 
93 94
 	if (f->check!=ST_CHECK_PATTERN){
94
-		LOG(L_CRIT, "BUG: vqm_*: fragm. %x beginning overwritten(%x)!\n",
95
+		LOG(L_CRIT, "BUG: vqm_*: fragm. %p beginning overwritten(%x)!\n",
95 96
 				f, f->check);
96 97
 		vqm_status(qm);
97 98
 		abort();
98 99
 	};
99 100
 	if (memcmp(f->end_check, END_CHECK_PATTERN, END_CHECK_PATTERN_LEN)!=0) {
100
-		LOG(L_CRIT, "BUG: vqm_*: fragm. %x end overwritten(%*s)!\n",
101
+		LOG(L_CRIT, "BUG: vqm_*: fragm. %p end overwritten(%*s)!\n",
101 102
 				f, END_CHECK_PATTERN_LEN, f->end_check );
102 103
 		vqm_status(qm);
103 104
 		abort();
... ...
@@ -235,7 +236,6 @@ static inline void vqm_detach_free( struct vqm_block* qm, struct vqm_frag* frag)
235 236
 {
236 237
 
237 238
 	struct vqm_frag *prev, *next;
238
-	struct vqm_frag_end *end;
239 239
 
240 240
 	prev=FRAG_END(frag)->prv_free; 
241 241
 	next=frag->u.nxt_free;
... ...
@@ -260,8 +260,8 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
260 260
 	
261 261
 #ifdef DBG_QM_MALLOC
262 262
 	unsigned int demanded_size;
263
-	DBG("vqm_malloc(%x, %d) called from %s: %s(%d)\n", qm, size, file, func,
264
-			line);
263
+	DBG("vqm_malloc(%p, %d) called from %s: %s(%d)\n", qm, size, file,
264
+	 func, line);
265 265
 	demanded_size = size;
266 266
 #endif
267 267
 	new_chunk=0;
... ...
@@ -285,7 +285,11 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
285 285
 
286 286
 	if (!new_chunk) { /* no chunk can be reused; slice one from the core */
287 287
 		new_chunk=MORE_CORE( qm, bucket, size );
288
-		if (!new_chunk) return 0;
288
+		if (!new_chunk) {
289
+			LOG(L_ERR, "vqm_malloc(%p, %d) called from %s: %s(%d)\n", 
290
+				qm, size, file, func, line);
291
+			return 0;
292
+		}
289 293
 	}
290 294
 	new_chunk->u.inuse.magic = FR_USED;
291 295
 	new_chunk->u.inuse.bucket=bucket;
... ...
@@ -295,7 +299,7 @@ void* vqm_malloc(struct vqm_block* qm, unsigned int size)
295 299
 	new_chunk->line=line;
296 300
 	new_chunk->demanded_size=demanded_size;
297 301
 	qm->usage[ bucket ]++;
298
-	DBG("vqm_malloc( %x, %d ) returns address %x in bucket %d, real-size %d \n",
302
+	DBG("vqm_malloc( %p, %d ) returns address %p in bucket %d, real-size %d \n",
299 303
 		qm, demanded_size, (char*)new_chunk+sizeof(struct vqm_frag), 
300 304
 		bucket, size );
301 305
 
... ...
@@ -317,9 +321,10 @@ void vqm_free(struct vqm_block* qm, void* p)
317 321
 	unsigned char b;
318 322
 
319 323
 #ifdef DBG_QM_MALLOC
320
-	DBG("vqm_free(%x, %x), called from %s: %s(%d)\n", qm, p, file, func, line);
324
+	DBG("vqm_free(%p, %p), called from %s: %s(%d)\n", 
325
+		qm, p, file, func, line);
321 326
 	if (p>(void *)qm->core_end || p<(void*)qm->init_core){
322
-		LOG(L_CRIT, "BUG: vqm_free: bad pointer %x (out of memory block!) - "
327
+		LOG(L_CRIT, "BUG: vqm_free: bad pointer %p (out of memory block!) - "
323 328
 				"aborting\n", p);
324 329
 		abort();
325 330
 	}
... ...
@@ -389,13 +394,13 @@ void vqm_free(struct vqm_block* qm, void* p)
389 394
 
390 395
 void dump_frag( struct vqm_frag* f, int i )
391 396
 {
392
-	LOG(L_INFO, "    %3d. address=%x  real size=%d bucket=%d\n", i, 
397
+	LOG(L_INFO, "    %3d. address=%p  real size=%d bucket=%d\n", i, 
393 398
 		(char*)f+sizeof(struct vqm_frag), f->size, f->u.inuse.bucket);
394 399
 #ifdef DBG_QM_MALLOC
395 400
 	LOG(L_INFO, "            demanded size=%d\n", f->demanded_size );
396 401
 	LOG(L_INFO, "            alloc'd from %s: %s(%d)\n",
397 402
 		f->file, f->func, f->line);
398
-	LOG(L_INFO, "        start check=%x, end check= %*s\n",
403
+	LOG(L_INFO, "        start check=%x, end check= %.*s\n",
399 404
 			f->check, END_CHECK_PATTERN_LEN, f->end_check );
400 405
 #endif
401 406
 }
... ...
@@ -403,9 +408,9 @@ void dump_frag( struct vqm_frag* f, int i )
403 408
 void vqm_status(struct vqm_block* qm)
404 409
 {
405 410
 	struct vqm_frag* f;
406
-	unsigned int i,j,on_list;
411
+	unsigned int i,on_list;
407 412
 
408
-	LOG(L_INFO, "vqm_status (%x):\n", qm);
413
+	LOG(L_INFO, "vqm_status (%p):\n", qm);
409 414
 	if (!qm) return;
410 415
 	LOG(L_INFO, " heap size= %d, available: %d\n", 
411 416
 		qm->core_end-qm->init_core, qm->free_core );
... ...
@@ -422,7 +427,7 @@ void vqm_status(struct vqm_block* qm)
422 427
 	DBG("dumping bucket statistics:\n");
423 428
 	for (i=0; i<=BIG_BUCKET(qm); i++) {
424 429
 		for(on_list=0, f=qm->next_free[i]; f; f=f->u.nxt_free ) on_list++;
425
-		LOG(L_DBG, "    %3d. bucket: in use: %d, on free list: %d\n", 
430
+		LOG(L_DBG, "    %3d. bucket: in use: %ld, on free list: %d\n", 
426 431
 			i, qm->usage[i], on_list );
427 432
 	}
428 433
 #endif
Browse code

reduction of lock/malloc calls

Jiri Kuthan authored on 11/01/2002 03:32:18
Showing 1 changed files
... ...
@@ -85,7 +85,7 @@ void my_assert( int assertation, int line, char *file, char *function )
85 85
 }
86 86
 
87 87
 #ifdef DBG_QM_MALLOC
88
-static  void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
88
+void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
89 89
 {
90 90
 
91 91
 	int r;
... ...
@@ -110,15 +110,14 @@ static  void vqm_debug_frag(struct vqm_block* qm, struct vqm_frag* f)
110 110
    and changed the demanded size to size really used including all
111 111
    possible overhead
112 112
  */
113
-unsigned char size2bucket( struct vqm_block* qm, int *size )
113
+unsigned char size2bucket( struct vqm_block* qm, int *size  )
114 114
 {
115 115
 	unsigned char b;	
116 116
 	unsigned int real_size;
117 117
 	unsigned int exceeds;
118 118
 
119
+	real_size = *size+ VQM_OVERHEAD;
119 120