浏览代码

- attempt to properly compute the used w/o overhead info

Andrei Pelinescu-Onciul 18 年之前
父节点
当前提交
6aea241ce8
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      mem/f_malloc.c

+ 6 - 1
mem/f_malloc.c

@@ -59,6 +59,9 @@
 	((struct fm_frag*)((char*)(f)+sizeof(struct fm_frag)+(f)->size ))
 
 #define FRAG_OVERHEAD	(sizeof(struct fm_frag))
+#define INIT_OVERHEAD	\
+	(ROUNDUP(sizeof(struct fm_block))+sizeof(struct fm_frag))
+
 
 
 /* ROUNDTO= 2^k so the following works */
@@ -208,7 +211,7 @@ struct fm_block* fm_malloc_init(char* address, unsigned long size)
 	if (size <(MIN_FRAG_SIZE+FRAG_OVERHEAD)) return 0;
 	size=ROUNDDOWN(size);
 
-	init_overhead=(ROUNDUP(sizeof(struct fm_block))+sizeof(struct fm_frag));
+	init_overhead=INIT_OVERHEAD;
 	
 	
 	if (size < init_overhead)
@@ -596,6 +599,8 @@ void fm_info(struct fm_block* qm, struct mem_info* info)
 	}
 	info->real_used=info->total_size-info->free;
 	info->used=0; /* we don't really now */
+	info->used=info->real_used-total_frags*FRAG_OVERHEAD-INIT_OVERHEAD-
+					FRAG_OVERHEAD;
 	info->max_used=0; /* we don't really now */
 #endif
 	info->total_frags=total_frags;