2 This is a version (aka dlmalloc) of malloc/free/realloc written by
3 Doug Lea and released to the public domain. Use, modify, and
4 redistribute this code without permission or acknowledgement in any
5 way you wish. Send questions, comments, complaints, performance
6 data, etc to dl@cs.oswego.edu
8 VERSION 2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
10 Note: There may be an updated version of this malloc obtainable at
11 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
12 Check before installing!
14 Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
20 /* ------------------------------ mallinfo ------------------------------ */
21 struct mallinfo mallinfo(void)
34 av = get_malloc_state();
35 /* Ensure initialization */
37 __malloc_consolidate(av);
43 avail = chunksize(av->top);
44 nblocks = 1; /* top always exists */
46 /* traverse fastbins */
50 for (i = 0; i < NFASTBINS; ++i) {
51 for (p = av->fastbins[i]; p != 0; p = p->fd) {
53 fastavail += chunksize(p);
59 /* traverse regular bins */
60 for (i = 1; i < NBINS; ++i) {
62 for (p = last(b); p != b; p = p->bk) {
64 avail += chunksize(p);
68 mi.smblks = nfastblocks;
71 mi.uordblks = av->sbrked_mem - avail;
72 mi.arena = av->sbrked_mem;
73 mi.hblks = av->n_mmaps;
74 mi.hblkhd = av->mmapped_mem;
75 mi.fsmblks = fastavail;
76 mi.keepcost = chunksize(av->top);
77 mi.usmblks = av->max_total_mem;
82 void malloc_stats(FILE *file)
91 fprintf(file, "total bytes allocated = %10lu\n", (unsigned int)(mi.arena + mi.hblkhd));
92 fprintf(file, "total bytes in use bytes = %10lu\n", (unsigned int)(mi.uordblks + mi.hblkhd));
93 fprintf(file, "total non-mmapped bytes allocated = %10lu\n", (unsigned int)(mi.arena));
94 fprintf(file, "number of mmapped regions = %10lu\n", (unsigned int)(mi.hblks));
95 fprintf(file, "total allocated mmap space = %10lu\n", (unsigned int)(mi.hblkhd));
96 fprintf(file, "total allocated sbrk space = %10lu\n", (unsigned int)(mi.uordblks));
98 fprintf(file, "number of free chunks = %10lu\n", (unsigned int)(mi.ordblks));
99 fprintf(file, "number of fastbin blocks = %10lu\n", (unsigned int)(mi.smblks));
100 fprintf(file, "space in freed fastbin blocks = %10lu\n", (unsigned int)(mi.fsmblks));
102 fprintf(file, "maximum total allocated space = %10lu\n", (unsigned int)(mi.usmblks));
103 fprintf(file, "total free space = %10lu\n", (unsigned int)(mi.fordblks));
104 fprintf(file, "memory releasable via malloc_trim = %10lu\n", (unsigned int)(mi.keepcost));