Browse code

- fixed real_used *realloc accounting - fixed initial size (didn't include overhead => fifo meminfo free was sometime negative)

Andrei Pelinescu-Onciul authored on 12/12/2005 12:18:19
Showing 2 changed files
... ...
@@ -34,6 +34,8 @@
34 34
  *              GET_HASH s/</<=/ (avoids waste of 1 hash cell)   (andrei)
35 35
  *  2004-11-10  support for > 4Gb mem., switched to long (andrei)
36 36
  *  2005-03-02  added fm_info() (andrei)
37
+ *  2005-12-12  fixed realloc shrink real_used accounting (andrei)
38
+ *              fixed initial size (andrei)
37 39
  */
38 40
 
39 41
 
... ...
@@ -213,12 +215,12 @@ struct fm_block* fm_malloc_init(char* address, unsigned long size)
213 213
 	end=start+size;
214 214
 	qm=(struct fm_block*)start;
215 215
 	memset(qm, 0, sizeof(struct fm_block));
216
-	size-=init_overhead;
217 216
 	qm->size=size;
218 217
 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
219 218
 	qm->real_used=init_overhead;
220 219
 	qm->max_real_used=qm->real_used;
221 220
 #endif
221
+	size-=init_overhead;
222 222
 	
223 223
 	qm->first_frag=(struct fm_frag*)(start+ROUNDUP(sizeof(struct fm_block)));
224 224
 	qm->last_frag=(struct fm_frag*)(end-sizeof(struct fm_frag));
... ...
@@ -402,7 +404,7 @@ void* fm_realloc(struct fm_block* qm, void* p, unsigned long size)
402 402
 		fm_split_frag(qm, f, size);
403 403
 #endif
404 404
 #if defined(DBG_F_MALLOC) || defined(MALLOC_STATS)
405
-		qm->real_used-=(orig_size-f->size);
405
+		qm->real_used-=(orig_size-f->size-FRAG_OVERHEAD);
406 406
 		qm->used-=(orig_size-f->size);
407 407
 #endif
408 408
 	}else if (f->size<size){
... ...
@@ -35,6 +35,8 @@
35 35
  *              GET_HASH s/</<=/ (avoids waste of 1 hash cell) (andrei)
36 36
  *  2004-11-10  support for > 4Gb mem., switched to long (andrei)
37 37
  *  2005-03-02  added qm_info() (andrei)
38
+ *  2005-12-12  fixed realloc shrink real_used & used accounting;
39
+ *              fixed initial size (andrei)
38 40
  */
39 41
 
40 42
 
... ...
@@ -216,10 +218,10 @@ struct qm_block* qm_malloc_init(char* address, unsigned long size)
216 216
 	end=start+size;
217 217
 	qm=(struct qm_block*)start;
218 218
 	memset(qm, 0, sizeof(struct qm_block));
219
-	size-=init_overhead;
220 219
 	qm->size=size;
221 220
 	qm->real_used=init_overhead;
222 221
 	qm->max_real_used=qm->real_used;
222
+	size-=init_overhead;
223 223
 	
224 224
 	qm->first_frag=(struct qm_frag*)(start+ROUNDUP(sizeof(struct qm_block)));
225 225
 	qm->last_frag_end=(struct qm_frag_end*)(end-sizeof(struct qm_frag_end));
... ...
@@ -548,6 +550,7 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
548 548
 	/* find first acceptable size */
549 549
 	size=ROUNDUP(size);
550 550
 	if (f->size > size){
551
+		orig_size=f->size;
551 552
 		/* shrink */
552 553
 #ifdef DBG_QM_MALLOC
553 554
 		DBG("qm_realloc: shrinking from %lu to %lu\n", f->size, size);
... ...
@@ -556,9 +559,9 @@ void* qm_realloc(struct qm_block* qm, void* p, unsigned long size)
556 556
 #else
557 557
 		if(split_frag(qm, f, size)!=0){
558 558
 #endif
559
-			/* update used sizes */
560
-			qm->real_used-=(f->size-size);
561
-			qm->used-=(f->size-size);
559
+			/* update used sizes: freed the spitted frag */
560
+			qm->real_used-=(orig_size-f->size-FRAG_OVERHEAD);
561
+			qm->used-=(orig_size-f->size);
562 562
 		}
563 563
 		
564 564
 	}else if (f->size < size){