Browse code

core: mem/q_malloc - updated log macros

Daniel-Constantin Mierla authored on 08/08/2017 10:01:55
Showing 1 changed files
... ...
@@ -116,7 +116,7 @@ static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f,
116 116
 		const char* file, unsigned int line)
117 117
 {
118 118
 	if (f->check!=ST_CHECK_PATTERN){
119
-		LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
119
+		LM_CRIT("BUG: qm: fragm. %p (address %p) "
120 120
 				"beginning overwritten (%lx)! Memory allocator was called "
121 121
 				"from %s:%u. Fragment marked by %s:%lu.\n",
122 122
 				f, (char*)f+sizeof(struct qm_frag),
... ...
@@ -125,8 +125,8 @@ static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f,
125 125
 		abort();
126 126
 	};
127 127
 	if ((FRAG_END(f)->check1!=END_CHECK_PATTERN1)||
128
-		(FRAG_END(f)->check2!=END_CHECK_PATTERN2)){
129
-		LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
128
+			(FRAG_END(f)->check2!=END_CHECK_PATTERN2)){
129
+		LM_CRIT("BUG: qm: fragm. %p (address %p) "
130 130
 				"end overwritten (%lx, %lx)! Memory allocator was called "
131 131
 				"from %s:%u. Fragment marked by %s:%lu.\n",
132 132
 				f, (char*)f+sizeof(struct qm_frag),
... ...
@@ -138,7 +138,7 @@ static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f,
138 138
 	if ((f>qm->first_frag)&&
139 139
 			((PREV_FRAG_END(f)->check1!=END_CHECK_PATTERN1) ||
140 140
 				(PREV_FRAG_END(f)->check2!=END_CHECK_PATTERN2) ) ){
141
-		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%lx, %lx)[%p:%p]! "
141
+		LM_CRIT("BUG: qm: prev. fragm. tail overwritten(%lx, %lx)[%p:%p]! "
142 142
 				"Memory allocator was called from %s:%u. Fragment marked by "
143 143
 				"%s:%lu.\n",
144 144
 				PREV_FRAG_END(f)->check1, PREV_FRAG_END(f)->check2, f,
... ...
@@ -185,11 +185,11 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
185 185
 
186 186
 	/* make address and size multiple of 8*/
187 187
 	start=(char*)ROUNDUP((unsigned long) address);
188
-	DBG("qm_malloc_init: QM_OPTIMIZE=%lu, /ROUNDTO=%lu\n",
188
+	LM_DBG("QM_OPTIMIZE=%lu, /ROUNDTO=%lu\n",
189 189
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
190
-	DBG("qm_malloc_init: QM_HASH_SIZE=%lu, qm_block size=%lu\n",
190
+	LM_DBG("QM_HASH_SIZE=%lu, qm_block size=%lu\n",
191 191
 			QM_HASH_SIZE, (unsigned long)sizeof(struct qm_block));
192
-	DBG("qm_malloc_init(%p, %lu), start=%p\n", address,
192
+	LM_DBG("qm_malloc_init(%p, %lu), start=%p\n", address,
193 193
 			(unsigned long)size, start);
194 194
 	if (size<start-address) return 0;
195 195
 	size-=(start-address);
... ...
@@ -198,13 +198,13 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
198 198
 
199 199
 	init_overhead=ROUNDUP(sizeof(struct qm_block))+sizeof(struct qm_frag)+
200 200
 		sizeof(struct qm_frag_end);
201
-	DBG("qm_malloc_init: size= %lu, init_overhead=%lu\n",
201
+	LM_DBG("size= %lu, init_overhead=%lu\n",
202 202
 			(unsigned long)size, init_overhead);
203 203
 
204 204
 	if (size < init_overhead)
205 205
 	{
206 206
 		/* not enough mem to create our control structures !!!*/
207
-		LOG(L_ERR, "qm_malloc_init(%lu); No memory left to create control structures!\n",
207
+		LM_ERR("qm_malloc_init(%lu); No memory left to create control structures\n",
208 208
 				(unsigned long)size);
209 209
 		return 0;
210 210
 	}
... ...
@@ -249,7 +249,6 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size, int type)
249 249
 }
250 250
 
251 251
 
252
-
253 252
 static inline void qm_detach_free(struct qm_block* qm, struct qm_frag* frag)
254 253
 {
255 254
 	struct qm_frag *prev;
... ...
@@ -262,16 +261,12 @@ static inline void qm_detach_free(struct qm_block* qm, struct qm_frag* frag)
262 261
 }
263 262
 
264 263
 
265
-
266 264
 #ifdef DBG_QM_MALLOC
267 265
 static inline struct qm_frag* qm_find_free(struct qm_block* qm,
268
-											size_t size,
269
-											int *h,
270
-											unsigned int *count)
266
+				size_t size, int *h, unsigned int *count)
271 267
 #else
272 268
 static inline struct qm_frag* qm_find_free(struct qm_block* qm,
273
-											size_t size,
274
-											int* h)
269
+				size_t size, int* h)
275 270
 #endif
276 271
 {
277 272
 	int hash;
... ...
@@ -288,7 +283,7 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
288 283
 	/*try in a bigger bucket*/
289 284
 	}
290 285
 	/* not found */
291
-	LOG(L_ERR, "qm_find_free(%p, %lu); Free fragment not found!\n",
286
+	LM_ERR("qm_find_free(%p, %lu); Free fragment not found!\n",
292 287
 			qm, (unsigned long)size);
293 288
 	return 0;
294 289
 }
... ...
@@ -347,8 +342,8 @@ int split_frag(struct qm_block* qm, struct qm_frag* f, size_t new_size)
347 342
 
348 343
 #ifdef DBG_QM_MALLOC
349 344
 void* qm_malloc(void* qmp, size_t size,
350
-					const char* file, const char* func, unsigned int line,
351
-					const char *mname)
345
+			const char* file, const char* func, unsigned int line,
346
+			const char *mname)
352 347
 #else
353 348
 void* qm_malloc(void* qmp, size_t size)
354 349
 #endif
... ...
@@ -421,10 +416,11 @@ void* qm_malloc(void* qmp, size_t size)
421 416
 	}
422 417
 
423 418
 #ifdef DBG_QM_MALLOC
424
-	LOG(L_ERR, "qm_malloc(%p, %lu) called from %s: %s(%d), module: %s; Free fragment not found!\n",
419
+	LM_ERR("qm_malloc(%p, %lu) called from %s: %s(%d), module: %s;"
420
+			" Free fragment not found!\n",
425 421
 			qm, (unsigned long)size, file, func, line, mname);
426 422
 #else
427
-	LOG(L_ERR, "qm_malloc(%p, %lu); Free fragment not found!\n",
423
+	LM_ERR("qm_malloc(%p, %lu); Free fragment not found!\n",
428 424
 			qm, (unsigned long)size);
429 425
 #endif
430 426
 
... ...
@@ -434,8 +430,8 @@ void* qm_malloc(void* qmp, size_t size)
434 430
 
435 431
 #ifdef DBG_QM_MALLOC
436 432
 void* qm_mallocxz(void* qmp, size_t size,
437
-					const char* file, const char* func, unsigned int line,
438
-					const char *mname)
433
+			const char* file, const char* func, unsigned int line,
434
+			const char *mname)
439 435
 #else
440 436
 void* qm_mallocxz(void* qmp, size_t size)
441 437
 #endif
... ...
@@ -451,13 +447,12 @@ void* qm_mallocxz(void* qmp, size_t size)
451 447
 	if(p) memset(p, 0, size);
452 448
 
453 449
 	return p;
454
-
455 450
 }
456 451
 
457 452
 
458 453
 #ifdef DBG_QM_MALLOC
459 454
 void qm_free(void* qmp, void* p, const char* file, const char* func,
460
-				unsigned int line, const char *mname)
455
+			unsigned int line, const char *mname)
461 456
 #else
462 457
 void qm_free(void* qmp, void* p)
463 458
 #endif
... ...
@@ -478,16 +473,16 @@ void qm_free(void* qmp, void* p)
478 473
 
479 474
 	if (p==0) {
480 475
 #ifdef DBG_QM_MALLOC
481
-		LOG(L_WARN, "WARNING:qm_free: free(0) called from %s: %s(%d)\n", file, func, line);
476
+		LM_WARN("WARNING: free(0) called from %s: %s(%d)\n", file, func, line);
482 477
 #else
483
-		LOG(L_WARN, "WARNING:qm_free: free(0) called\n");
478
+		LM_WARN("WARNING: free(0) called\n");
484 479
 #endif
485 480
 		return;
486 481
 	}
487 482
 
488 483
 #ifdef DBG_QM_MALLOC
489 484
 	if (p>(void*)qm->last_frag_end || p<(void*)qm->first_frag){
490
-		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!)"
485
+		LM_CRIT("BUG: bad pointer %p (out of memory block!)"
491 486
 				" called from %s: %s(%d) - aborting\n", p, file, func, line);
492 487
 		if(likely(cfg_get(core, core_cfg, mem_safety)==0))
493 488
 			abort();
... ...
@@ -500,14 +495,14 @@ void qm_free(void* qmp, void* p)
500 495
 #ifdef DBG_QM_MALLOC
501 496
 	qm_debug_frag(qm, f, file, line);
502 497
 	if (f->u.is_free){
503
-		LOG(L_CRIT, "BUG: qm_free: freeing already freed pointer (%p),"
498
+		LM_CRIT("BUG: freeing already freed pointer (%p),"
504 499
 				" called from %s: %s(%d), first free %s: %s(%ld) - aborting\n",
505 500
 				p, file, func, line, f->file, f->func, f->line);
506 501
 		if(likely(cfg_get(core, core_cfg, mem_safety)==0))
507 502
 			abort();
508 503
 		else return;
509 504
 	}
510
-	MDBG("qm_free: freeing frag. %p alloc'ed from %s: %s(%ld)\n",
505
+	MDBG("freeing frag. %p alloc'ed from %s: %s(%ld)\n",
511 506
 			f, f->file, f->func, f->line);
512 507
 #endif
513 508
 	if (unlikely(f->u.is_free)){
... ...
@@ -599,20 +594,21 @@ void* qm_realloc(void* qmp, void* p, size_t size)
599 594
 	MDBG("qm_realloc(%p, %p, %lu) called from %s: %s(%d)\n",
600 595
 			qm, p, (unsigned long)size,
601 596
 			file, func, line);
602
-	if ((p)&&(p>(void*)qm->last_frag_end || p<(void*)qm->first_frag)){
603
-		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
597
+	if ((p)&&(p>(void*)qm->last_frag_end || p<(void*)qm->first_frag)) {
598
+		LM_CRIT("BUG: bad pointer %p (out of memory block!) - "
604 599
 				"aborting\n", p);
605 600
 		abort();
606 601
 	}
607 602
 #endif
608 603
 
609 604
 	if (size==0) {
610
-		if (p)
605
+		if (p) {
611 606
 #ifdef DBG_QM_MALLOC
612 607
 			qm_free(qm, p, file, func, line, mname);
613 608
 #else
614 609
 			qm_free(qm, p);
615 610
 #endif
611
+		}
616 612
 		return 0;
617 613
 	}
618 614
 	if (p==0)
... ...
@@ -624,10 +620,10 @@ void* qm_realloc(void* qmp, void* p, size_t size)
624 620
 	f=(struct qm_frag*) ((char*)p-sizeof(struct qm_frag));
625 621
 #ifdef DBG_QM_MALLOC
626 622
 	qm_debug_frag(qm, f, file, line);
627
-	MDBG("qm_realloc: realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
623
+	MDBG("realloc'ing frag %p alloc'ed from %s: %s(%ld)\n",
628 624
 			f, f->file, f->func, f->line);
629 625
 	if (f->u.is_free){
630
-		LOG(L_CRIT, "BUG:qm_realloc: trying to realloc an already freed "
626
+		LM_CRIT("BUG: trying to realloc an already freed "
631 627
 				"pointer %p , fragment %p -- aborting\n", p, f);
632 628
 		abort();
633 629
 	}
... ...
@@ -638,10 +634,10 @@ void* qm_realloc(void* qmp, void* p, size_t size)
638 634
 		orig_size=f->size;
639 635
 		/* shrink */
640 636
 #ifdef DBG_QM_MALLOC
641
-		MDBG("qm_realloc: shrinking from %lu to %lu\n",
637
+		MDBG("shrinking from %lu to %lu\n",
642 638
 				f->size, (unsigned long)size);
643 639
 		if(split_frag(qm, f, size, file, "fragm. from qm_realloc", line, mname)!=0){
644
-		MDBG("qm_realloc : shrinked successful\n");
640
+		MDBG("shrinked successful\n");
645 641
 #else
646 642
 		if(split_frag(qm, f, size)!=0){
647 643
 #endif
... ...
@@ -656,7 +652,7 @@ void* qm_realloc(void* qmp, void* p, size_t size)
656 652
 	}else if (f->size < size){
657 653
 		/* grow */
658 654
 #ifdef DBG_QM_MALLOC
659
-		MDBG("qm_realloc: growing from %lu to %lu\n",
655
+		MDBG("growing from %lu to %lu\n",
660 656
 				f->size, (unsigned long)size);
661 657
 #endif
662 658
 			orig_size=f->size;
... ...
@@ -701,10 +697,11 @@ void* qm_realloc(void* qmp, void* p, size_t size)
701 697
 		#endif
702 698
 				} else {
703 699
 #ifdef DBG_QM_MALLOC
704
-					LOG(L_ERR, "qm_realloc(%p, %lu) called from %s: %s(%d), module: %s; qm_malloc() failed!\n",
700
+					LM_ERR("qm_realloc(%p, %lu) called from %s: %s(%d),"
701
+							" module: %s; qm_malloc() failed!\n",
705 702
 							qm, (unsigned long)size, file, func, line, mname);
706 703
 #else
707
-					LOG(L_ERR, "qm_realloc(%p, %lu); qm_malloc() failed!\n",
704
+					LM_ERR("qm_realloc(%p, %lu); qm_malloc() failed!\n",
708 705
 							qm, (unsigned long)size);
709 706
 #endif
710 707
 				}
... ...
@@ -713,12 +710,12 @@ void* qm_realloc(void* qmp, void* p, size_t size)
713 710
 	}else{
714 711
 		/* do nothing */
715 712
 #ifdef DBG_QM_MALLOC
716
-		MDBG("qm_realloc: doing nothing, same size: %lu - %lu\n",
713
+		MDBG("doing nothing, same size: %lu - %lu\n",
717 714
 				f->size, (unsigned long)size);
718 715
 #endif
719 716
 	}
720 717
 #ifdef DBG_QM_MALLOC
721
-	MDBG("qm_realloc: returning %p\n", p);
718
+	MDBG("returning pointer address: %p\n", p);
722 719
 #endif
723 720
 #ifdef MALLOC_STATS
724 721
 	if(qm->type==MEM_TYPE_PKG) {
... ...
@@ -765,14 +762,14 @@ void qm_check(struct qm_block* qm)
765 762
 	int memlog;
766 763
 
767 764
 	memlog=cfg_get(core, core_cfg, memlog);
768
-	LOG(memlog, "DEBUG: qm_check()\n");
765
+	LOG(memlog, "executing qm_check()\n");
769 766
 	f = qm->first_frag;
770 767
 	while ((char*)f < (char*)qm->last_frag_end) {
771 768
 		fcount++;
772 769
 		/* check struct qm_frag */
773 770
 #ifdef DBG_QM_MALLOC
774 771
 		if (f->check!=ST_CHECK_PATTERN){
775
-			LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
772
+			LM_CRIT("BUG: qm: fragm. %p (address %p) "
776 773
 					"beginning overwritten(%lx)!\n",
777 774
 					f, (char*)f + sizeof(struct qm_frag),
778 775
 					f->check);
... ...
@@ -782,7 +779,7 @@ void qm_check(struct qm_block* qm)
782 779
 #endif
783 780
 		if ((char*)f + sizeof(struct qm_frag) + f->size
784 781
 				+ sizeof(struct qm_frag_end) > (char*)qm->first_frag + qm->size) {
785
-			LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
782
+			LM_CRIT("BUG: qm: fragm. %p (address %p) "
786 783
 				"bad size: %lu (frag end: %p > end of block: %p)\n",
787 784
 				f, (char*)f + sizeof(struct qm_frag), f->size,
788 785
 				(char*)f + sizeof(struct qm_frag) + f->size
... ...
@@ -793,7 +790,7 @@ void qm_check(struct qm_block* qm)
793 790
 		}
794 791
 		/* check struct qm_frag_end */
795 792
 		if (FRAG_END(f)->size != f->size) {
796
-			LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
793
+			LM_CRIT("BUG: qm: fragm. %p (address %p) "
797 794
 					"size in qm_frag and qm_frag_end does not match:"
798 795
 					" frag->size=%lu, frag_end->size=%lu)\n",
799 796
 				f, (char*)f + sizeof(struct qm_frag),
... ...
@@ -804,7 +801,7 @@ void qm_check(struct qm_block* qm)
804 801
 #ifdef DBG_QM_MALLOC
805 802
 		if ((FRAG_END(f)->check1 != END_CHECK_PATTERN1) ||
806 803
 			(FRAG_END(f)->check2 != END_CHECK_PATTERN2)) {
807
-			LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p)"
804
+			LM_CRIT("BUG: qm: fragm. %p (address %p)"
808 805
 						" end overwritten(%lx, %lx)!\n",
809 806
 					f, (char*)f + sizeof(struct qm_frag),
810 807
 					FRAG_END(f)->check1, FRAG_END(f)->check2);
... ...
@@ -815,7 +812,7 @@ void qm_check(struct qm_block* qm)
815 812
 		f = FRAG_NEXT(f);
816 813
 	}
817 814
 
818
-	LOG(memlog, "DEBUG: qm_check: %lu fragments OK\n", fcount);
815
+	LOG(memlog, "summary of qm_check: %lu fragments OK\n", fcount);
819 816
 }
820 817
 
821 818
 void qm_status(void* qmp)
... ...
@@ -1108,7 +1105,7 @@ int qm_malloc_init_pkg_manager(void)
1108 1105
 	if (_qm_pkg_pool)
1109 1106
 		_qm_pkg_block=qm_malloc_init(_qm_pkg_pool, pkg_mem_size, MEM_TYPE_PKG);
1110 1107
 	if (_qm_pkg_block==0){
1111
-		LOG(L_CRIT, "could not initialize qm memory pool\n");
1108
+		LM_CRIT("could not initialize qm memory pool\n");
1112 1109
 		fprintf(stderr, "Too much qm pkg memory demanded: %ld bytes\n",
1113 1110
 						pkg_mem_size);
1114 1111
 		return -1;
... ...
@@ -1142,7 +1139,8 @@ static struct qm_block *_qm_shm_block = 0;
1142 1139
 /*SHM wrappers to sync the access to memory block*/
1143 1140
 #ifdef DBG_QM_MALLOC
1144 1141
 void* qm_shm_malloc(void* qmp, size_t size,
1145
-					const char* file, const char* func, unsigned int line, const char* mname)
1142
+		const char* file, const char* func, unsigned int line,
1143
+		const char* mname)
1146 1144
 {
1147 1145
 	void *r;
1148 1146
 	shm_lock();
... ...
@@ -1151,7 +1149,8 @@ void* qm_shm_malloc(void* qmp, size_t size,
1151 1149
 	return r;
1152 1150
 }
1153 1151
 void* qm_shm_mallocxz(void* qmp, size_t size,
1154
-					const char* file, const char* func, unsigned int line, const char* mname)
1152
+		const char* file, const char* func, unsigned int line,
1153
+		const char* mname)
1155 1154
 {
1156 1155
 	void *r;
1157 1156
 	shm_lock();
... ...
@@ -1160,7 +1159,8 @@ void* qm_shm_mallocxz(void* qmp, size_t size,
1160 1159
 	return r;
1161 1160
 }
1162 1161
 void* qm_shm_realloc(void* qmp, void* p, size_t size,
1163
-					const char* file, const char* func, unsigned int line, const char* mname)
1162
+		const char* file, const char* func, unsigned int line,
1163
+		const char* mname)
1164 1164
 {
1165 1165
 	void *r;
1166 1166
 	shm_lock();
... ...
@@ -1169,7 +1169,8 @@ void* qm_shm_realloc(void* qmp, void* p, size_t size,
1169 1169
 	return r;
1170 1170
 }
1171 1171
 void* qm_shm_reallocxf(void* qmp, void* p, size_t size,
1172
-					const char* file, const char* func, unsigned int line, const char* mname)
1172
+		const char* file, const char* func, unsigned int line,
1173
+		const char* mname)
1173 1174
 {
1174 1175
 	void *r;
1175 1176
 	shm_lock();
... ...
@@ -1178,7 +1179,8 @@ void* qm_shm_reallocxf(void* qmp, void* p, size_t size,
1178 1179
 	return r;
1179 1180
 }
1180 1181
 void* qm_shm_resize(void* qmp, void* p, size_t size,
1181
-					const char* file, const char* func, unsigned int line, const char* mname)
1182
+		const char* file, const char* func, unsigned int line,
1183
+		const char* mname)
1182 1184
 {
1183 1185
 	void *r;
1184 1186
 	shm_lock();
... ...
@@ -1188,7 +1190,7 @@ void* qm_shm_resize(void* qmp, void* p, size_t size,
1188 1190
 	return r;
1189 1191
 }
1190 1192
 void qm_shm_free(void* qmp, void* p, const char* file, const char* func,
1191
-				unsigned int line, const char* mname)
1193
+		unsigned int line, const char* mname)
1192 1194
 {
1193 1195
 	shm_lock();
1194 1196
 	qm_free(qmp, p, file, func, line, mname);
... ...
@@ -1292,7 +1294,7 @@ int qm_malloc_init_shm_manager(void)
1292 1294
 	if (_qm_shm_pool)
1293 1295
 		_qm_shm_block=qm_malloc_init(_qm_shm_pool, shm_mem_size, MEM_TYPE_SHM);
1294 1296
 	if (_qm_shm_block==0){
1295
-		LOG(L_CRIT, "could not initialize qm shm memory pool\n");
1297
+		LM_CRIT("could not initialize qm shm memory pool\n");
1296 1298
 		fprintf(stderr, "Too much qm shm memory demanded: %ld bytes\n",
1297 1299
 						shm_mem_size);
1298 1300
 		return -1;