]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/stdlib/malloc-standard/mallinfo.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / stdlib / malloc-standard / mallinfo.c
1 /*
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
7
8   VERSION 2.7.2 Sat Aug 17 09:07:30 2002  Doug Lea  (dl at gee)
9
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!
13
14   Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
15 */
16
17 #include "malloc.h"
18 #include <stdio.h>      /* fprintf */
19
20
21 /* ------------------------------ mallinfo ------------------------------ */
22 struct mallinfo mallinfo(void)
23 {
24     mstate av;
25     struct mallinfo mi;
26     unsigned int i;
27     mbinptr b;
28     mchunkptr p;
29     size_t avail;
30     size_t fastavail;
31     int nblocks;
32     int nfastblocks;
33
34     __MALLOC_LOCK;
35     av = get_malloc_state();
36     /* Ensure initialization */
37     if (av->top == 0)  {
38         __malloc_consolidate(av);
39     }
40
41     check_malloc_state();
42
43     /* Account for top */
44     avail = chunksize(av->top);
45     nblocks = 1;  /* top always exists */
46
47     /* traverse fastbins */
48     nfastblocks = 0;
49     fastavail = 0;
50
51     for (i = 0; i < NFASTBINS; ++i) {
52         for (p = av->fastbins[i]; p != 0; p = p->fd) {
53             ++nfastblocks;
54             fastavail += chunksize(p);
55         }
56     }
57
58     avail += fastavail;
59
60     /* traverse regular bins */
61     for (i = 1; i < NBINS; ++i) {
62         b = bin_at(av, i);
63         for (p = last(b); p != b; p = p->bk) {
64             ++nblocks;
65             avail += chunksize(p);
66         }
67     }
68
69     mi.smblks = nfastblocks;
70     mi.ordblks = nblocks;
71     mi.fordblks = avail;
72     mi.uordblks = av->sbrked_mem - avail;
73     mi.arena = av->sbrked_mem;
74     mi.hblks = av->n_mmaps;
75     mi.hblkhd = av->mmapped_mem;
76     mi.fsmblks = fastavail;
77     mi.keepcost = chunksize(av->top);
78     mi.usmblks = av->max_total_mem;
79     __MALLOC_UNLOCK;
80     return mi;
81 }
82 libc_hidden_def(mallinfo)
83
84 void malloc_stats(FILE *file)
85 {
86     struct mallinfo mi;
87
88     if (file==NULL) {
89         file = stderr;
90     }
91
92     mi = mallinfo();
93     fprintf(file,
94             "total bytes allocated             = %10u\n"
95             "total bytes in use bytes          = %10u\n"
96             "total non-mmapped bytes allocated = %10d\n"
97             "number of mmapped regions         = %10d\n"
98             "total allocated mmap space        = %10d\n"
99             "total allocated sbrk space        = %10d\n"
100 #if 0
101             "number of free chunks             = %10d\n"
102             "number of fastbin blocks          = %10d\n"
103             "space in freed fastbin blocks     = %10d\n"
104 #endif
105             "maximum total allocated space     = %10d\n"
106             "total free space                  = %10d\n"
107             "memory releasable via malloc_trim = %10d\n",
108
109             (unsigned int)(mi.arena + mi.hblkhd),
110             (unsigned int)(mi.uordblks + mi.hblkhd),
111             mi.arena,
112             mi.hblks,
113             mi.hblkhd,
114             mi.uordblks,
115 #if 0
116             mi.ordblks,
117             mi.smblks,
118             mi.fsmblks,
119 #endif
120             mi.usmblks,
121             mi.fordblks,
122             mi.keepcost
123            );
124 }
125