1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// include/sys/malloc.h
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####BSDALTCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// Portions of this software may have been derived from OpenBSD
|
11 |
|
|
// or other sources, and if so are covered by the appropriate copyright
|
12 |
|
|
// and license included herein.
|
13 |
|
|
// -------------------------------------------
|
14 |
|
|
// ####BSDALTCOPYRIGHTEND####
|
15 |
|
|
//==========================================================================
|
16 |
|
|
//#####DESCRIPTIONBEGIN####
|
17 |
|
|
//
|
18 |
|
|
// Author(s): gthomas
|
19 |
|
|
// Contributors: gthomas
|
20 |
|
|
// Date: 2000-01-10
|
21 |
|
|
// Purpose:
|
22 |
|
|
// Description:
|
23 |
|
|
//
|
24 |
|
|
//
|
25 |
|
|
//####DESCRIPTIONEND####
|
26 |
|
|
//
|
27 |
|
|
//==========================================================================
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/* $OpenBSD: malloc.h,v 1.27 1999/12/08 06:50:24 itojun Exp $ */
|
31 |
|
|
/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
|
32 |
|
|
|
33 |
|
|
/*
|
34 |
|
|
* Copyright (c) 1987, 1993
|
35 |
|
|
* The Regents of the University of California. All rights reserved.
|
36 |
|
|
*
|
37 |
|
|
* Redistribution and use in source and binary forms, with or without
|
38 |
|
|
* modification, are permitted provided that the following conditions
|
39 |
|
|
* are met:
|
40 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
41 |
|
|
* notice, this list of conditions and the following disclaimer.
|
42 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
43 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
44 |
|
|
* documentation and/or other materials provided with the distribution.
|
45 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
46 |
|
|
* must display the following acknowledgement:
|
47 |
|
|
* This product includes software developed by the University of
|
48 |
|
|
* California, Berkeley and its contributors.
|
49 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
50 |
|
|
* may be used to endorse or promote products derived from this software
|
51 |
|
|
* without specific prior written permission.
|
52 |
|
|
*
|
53 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
54 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
55 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
56 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
57 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
58 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
59 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
60 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
61 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
62 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
63 |
|
|
* SUCH DAMAGE.
|
64 |
|
|
*
|
65 |
|
|
* @(#)malloc.h 8.5 (Berkeley) 5/3/95
|
66 |
|
|
*/
|
67 |
|
|
|
68 |
|
|
#ifndef _SYS_MALLOC_H_
|
69 |
|
|
#define _SYS_MALLOC_H_
|
70 |
|
|
|
71 |
|
|
/*
|
72 |
|
|
* flags to malloc
|
73 |
|
|
*/
|
74 |
|
|
#define M_WAITOK 0x0000
|
75 |
|
|
#define M_NOWAIT 0x0001
|
76 |
|
|
|
77 |
|
|
/*
|
78 |
|
|
* Types of memory to be allocated
|
79 |
|
|
*/
|
80 |
|
|
#define M_FREE 0 /* should be on free list */
|
81 |
|
|
#define M_MBUF 1 /* mbuf */
|
82 |
|
|
#define M_DEVBUF 2 /* device driver memory */
|
83 |
|
|
#define M_SOCKET 3 /* socket structure */
|
84 |
|
|
#define M_PCB 4 /* protocol control block */
|
85 |
|
|
#define M_RTABLE 5 /* routing tables */
|
86 |
|
|
#define M_HTABLE 6 /* IMP host tables */
|
87 |
|
|
#define M_FTABLE 7 /* fragment reassembly header */
|
88 |
|
|
#define M_ZOMBIE 8 /* zombie proc status */
|
89 |
|
|
#define M_IFADDR 9 /* interface address */
|
90 |
|
|
#define M_SOOPTS 10 /* socket options */
|
91 |
|
|
#define M_SONAME 11 /* socket name */
|
92 |
|
|
#define M_NAMEI 12 /* namei path name buffer */
|
93 |
|
|
#define M_GPROF 13 /* kernel profiling buffer */
|
94 |
|
|
#define M_IOCTLOPS 14 /* ioctl data buffer */
|
95 |
|
|
#define M_MAPMEM 15 /* mapped memory descriptors */
|
96 |
|
|
#define M_CRED 16 /* credentials */
|
97 |
|
|
#define M_PGRP 17 /* process group header */
|
98 |
|
|
#define M_SESSION 18 /* session header */
|
99 |
|
|
#define M_IOV 19 /* large iov's */
|
100 |
|
|
#define M_MOUNT 20 /* vfs mount struct */
|
101 |
|
|
#define M_FHANDLE 21 /* network file handle */
|
102 |
|
|
#define M_NFSREQ 22 /* NFS request header */
|
103 |
|
|
#define M_NFSMNT 23 /* NFS mount structure */
|
104 |
|
|
#define M_NFSNODE 24 /* NFS vnode private part */
|
105 |
|
|
#define M_VNODE 25 /* Dynamically allocated vnodes */
|
106 |
|
|
#define M_CACHE 26 /* Dynamically allocated cache entries */
|
107 |
|
|
#define M_DQUOT 27 /* UFS quota entries */
|
108 |
|
|
#define M_UFSMNT 28 /* UFS mount structure */
|
109 |
|
|
#define M_SHM 29 /* SVID compatible shared memory segments */
|
110 |
|
|
#define M_VMMAP 30 /* VM map structures */
|
111 |
|
|
#define M_VMMAPENT 31 /* VM map entry structures */
|
112 |
|
|
#define M_VMOBJ 32 /* VM object structure */
|
113 |
|
|
#define M_VMOBJHASH 33 /* VM object hash structure */
|
114 |
|
|
#define M_VMPMAP 34 /* VM pmap */
|
115 |
|
|
#define M_VMPVENT 35 /* VM phys-virt mapping entry */
|
116 |
|
|
#define M_VMPAGER 36 /* XXX: VM pager struct */
|
117 |
|
|
#define M_VMPGDATA 37 /* XXX: VM pager private data */
|
118 |
|
|
#define M_FILE 38 /* Open file structure */
|
119 |
|
|
#define M_FILEDESC 39 /* Open file descriptor table */
|
120 |
|
|
#define M_LOCKF 40 /* Byte-range locking structures */
|
121 |
|
|
#define M_PROC 41 /* Proc structures */
|
122 |
|
|
#define M_SUBPROC 42 /* Proc sub-structures */
|
123 |
|
|
#define M_SEGMENT 43 /* Segment for LFS */
|
124 |
|
|
#define M_LFSNODE 44 /* LFS vnode private part */
|
125 |
|
|
#define M_FFSNODE 45 /* FFS vnode private part */
|
126 |
|
|
#define M_MFSNODE 46 /* MFS vnode private part */
|
127 |
|
|
#define M_NQLEASE 47 /* Nqnfs lease */
|
128 |
|
|
#define M_NQMHOST 48 /* Nqnfs host address table */
|
129 |
|
|
#define M_NETADDR 49 /* Export host address structure */
|
130 |
|
|
#define M_NFSSVC 50 /* Nfs server structure */
|
131 |
|
|
#define M_NFSUID 51 /* Nfs uid mapping structure */
|
132 |
|
|
#define M_NFSD 52 /* Nfs server daemon structure */
|
133 |
|
|
#define M_IPMOPTS 53 /* internet multicast options */
|
134 |
|
|
#define M_IPMADDR 54 /* internet multicast address */
|
135 |
|
|
#define M_IFMADDR 55 /* link-level multicast address */
|
136 |
|
|
#define M_MRTABLE 56 /* multicast routing tables */
|
137 |
|
|
#define M_ISOFSMNT 57 /* ISOFS mount structure */
|
138 |
|
|
#define M_ISOFSNODE 58 /* ISOFS vnode private part */
|
139 |
|
|
#define M_MSDOSFSMNT 59 /* MSDOS FS mount structure */
|
140 |
|
|
#define M_MSDOSFSFAT 60 /* MSDOS FS fat table */
|
141 |
|
|
#define M_MSDOSFSNODE 61 /* MSDOS FS vnode private part */
|
142 |
|
|
#define M_TTYS 62 /* allocated tty structures */
|
143 |
|
|
#define M_EXEC 63 /* argument lists & other mem used by exec */
|
144 |
|
|
#define M_MISCFSMNT 64 /* miscfs mount structures */
|
145 |
|
|
#define M_MISCFSNODE 65 /* miscfs vnode private part */
|
146 |
|
|
#define M_ADOSFSMNT 66 /* adosfs mount structures */
|
147 |
|
|
#define M_ADOSFSNODE 67 /* adosfs vnode private part */
|
148 |
|
|
#define M_ANODE 68 /* adosfs anode structures and tables. */
|
149 |
|
|
#define M_IPQ 69 /* IP packet queue entry */
|
150 |
|
|
#define M_AFS 70 /* Andrew File System */
|
151 |
|
|
#define M_ADOSFSBITMAP 71 /* adosfs bitmap */
|
152 |
|
|
#define M_EXT2FSNODE 72 /* EXT2FS vnode private part */
|
153 |
|
|
#define M_PFIL 73 /* packer filter */
|
154 |
|
|
#define M_PFKEY 74 /* pfkey data */
|
155 |
|
|
#define M_TDB 75 /* Transforms database */
|
156 |
|
|
#define M_XDATA 76 /* IPsec data */
|
157 |
|
|
#define M_VFS 77 /* VFS file systems */
|
158 |
|
|
|
159 |
|
|
#define M_PAGEDEP 78 /* File page dependencies */
|
160 |
|
|
#define M_INODEDEP 79 /* Inode dependencies */
|
161 |
|
|
#define M_NEWBLK 80 /* New block allocation */
|
162 |
|
|
#define M_BMSAFEMAP 81 /* Block or frag allocated from cyl group map */
|
163 |
|
|
#define M_ALLOCDIRECT 82 /* Block or frag dependency for an inode */
|
164 |
|
|
#define M_INDIRDEP 83 /* Indirect block dependencies */
|
165 |
|
|
#define M_ALLOCINDIR 84 /* Block dependency for an indirect block */
|
166 |
|
|
#define M_FREEFRAG 85 /* Previously used frag for an inode */
|
167 |
|
|
#define M_FREEBLKS 86 /* Blocks freed from an inode */
|
168 |
|
|
#define M_FREEFILE 87 /* Inode deallocated */
|
169 |
|
|
#define M_DIRADD 88 /* New directory entry */
|
170 |
|
|
#define M_MKDIR 89 /* New directory */
|
171 |
|
|
#define M_DIRREM 90 /* Directory entry deleted */
|
172 |
|
|
#define M_VMPBUCKET 91 /* VM page buckets */
|
173 |
|
|
#define M_VMSWAP 92 /* VM swap structures */
|
174 |
|
|
|
175 |
|
|
#define M_DISCQ 93 /* IPv6 discq */
|
176 |
|
|
#define M_FRAGQ 94 /* IPv6 fragq */
|
177 |
|
|
#define M_SECA 95 /* Sec Assoc */
|
178 |
|
|
#if 0 /* NRL IPv6 */
|
179 |
|
|
#define M_I6IFP 96 /* IPv6 if info */
|
180 |
|
|
#endif
|
181 |
|
|
|
182 |
|
|
#define M_RAIDFRAME 97 /* Raidframe data */
|
183 |
|
|
|
184 |
|
|
#define M_UVMAMAP 98 /* UVM amap and realted */
|
185 |
|
|
#define M_UVMAOBJ 99 /* UVM aobj and realted */
|
186 |
|
|
#define M_POOL 100 /* Pool memory */
|
187 |
|
|
|
188 |
|
|
#define M_USB 101 /* USB general */
|
189 |
|
|
#define M_USBDEV 102 /* USB device driver */
|
190 |
|
|
#define M_USBHC 103 /* USB host controller */
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
/* KAME IPv6 */
|
194 |
|
|
#define M_IP6OPT 123 /* IPv6 options */
|
195 |
|
|
#define M_IP6NDP 124 /* IPv6 Neighbour Discovery */
|
196 |
|
|
#define M_IP6RR 125 /* IPv6 Router Renumbering Prefix */
|
197 |
|
|
#define M_RR_ADDR 126 /* IPv6 Router Renumbering Ifid */
|
198 |
|
|
|
199 |
|
|
#define M_PIPE 104 /* Pipe structures */
|
200 |
|
|
|
201 |
|
|
#define M_MEMDESC 105 /* Memory range */
|
202 |
|
|
|
203 |
|
|
#define M_TEMP 127 /* misc temporary data buffers */
|
204 |
|
|
#define M_LAST 128 /* Must be last type + 1 */
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
#define INITKMEMNAMES { \
|
208 |
|
|
"free", /* 0 M_FREE */ \
|
209 |
|
|
"mbuf", /* 1 M_MBUF */ \
|
210 |
|
|
"devbuf", /* 2 M_DEVBUF */ \
|
211 |
|
|
"socket", /* 3 M_SOCKET */ \
|
212 |
|
|
"pcb", /* 4 M_PCB */ \
|
213 |
|
|
"routetbl", /* 5 M_RTABLE */ \
|
214 |
|
|
"hosttbl", /* 6 M_HTABLE */ \
|
215 |
|
|
"fragtbl", /* 7 M_FTABLE */ \
|
216 |
|
|
"zombie", /* 8 M_ZOMBIE */ \
|
217 |
|
|
"ifaddr", /* 9 M_IFADDR */ \
|
218 |
|
|
"soopts", /* 10 M_SOOPTS */ \
|
219 |
|
|
"soname", /* 11 M_SONAME */ \
|
220 |
|
|
"namei", /* 12 M_NAMEI */ \
|
221 |
|
|
"gprof", /* 13 M_GPROF */ \
|
222 |
|
|
"ioctlops", /* 14 M_IOCTLOPS */ \
|
223 |
|
|
"mapmem", /* 15 M_MAPMEM */ \
|
224 |
|
|
"cred", /* 16 M_CRED */ \
|
225 |
|
|
"pgrp", /* 17 M_PGRP */ \
|
226 |
|
|
"session", /* 18 M_SESSION */ \
|
227 |
|
|
"iov", /* 19 M_IOV */ \
|
228 |
|
|
"mount", /* 20 M_MOUNT */ \
|
229 |
|
|
"fhandle", /* 21 M_FHANDLE */ \
|
230 |
|
|
"NFS req", /* 22 M_NFSREQ */ \
|
231 |
|
|
"NFS mount", /* 23 M_NFSMNT */ \
|
232 |
|
|
"NFS node", /* 24 M_NFSNODE */ \
|
233 |
|
|
"vnodes", /* 25 M_VNODE */ \
|
234 |
|
|
"namecache", /* 26 M_CACHE */ \
|
235 |
|
|
"UFS quota", /* 27 M_DQUOT */ \
|
236 |
|
|
"UFS mount", /* 28 M_UFSMNT */ \
|
237 |
|
|
"shm", /* 29 M_SHM */ \
|
238 |
|
|
"VM map", /* 30 M_VMMAP */ \
|
239 |
|
|
"VM mapent", /* 31 M_VMMAPENT */ \
|
240 |
|
|
"VM object", /* 32 M_VMOBJ */ \
|
241 |
|
|
"VM objhash", /* 33 M_VMOBJHASH */ \
|
242 |
|
|
"VM pmap", /* 34 M_VMPMAP */ \
|
243 |
|
|
"VM pvmap", /* 35 M_VMPVENT */ \
|
244 |
|
|
"VM pager", /* 36 M_VMPAGER */ \
|
245 |
|
|
"VM pgdata", /* 37 M_VMPGDATA */ \
|
246 |
|
|
"file", /* 38 M_FILE */ \
|
247 |
|
|
"file desc", /* 39 M_FILEDESC */ \
|
248 |
|
|
"lockf", /* 40 M_LOCKF */ \
|
249 |
|
|
"proc", /* 41 M_PROC */ \
|
250 |
|
|
"subproc", /* 42 M_SUBPROC */ \
|
251 |
|
|
"LFS segment", /* 43 M_SEGMENT */ \
|
252 |
|
|
"LFS node", /* 44 M_LFSNODE */ \
|
253 |
|
|
"FFS node", /* 45 M_FFSNODE */ \
|
254 |
|
|
"MFS node", /* 46 M_MFSNODE */ \
|
255 |
|
|
"NQNFS Lease", /* 47 M_NQLEASE */ \
|
256 |
|
|
"NQNFS Host", /* 48 M_NQMHOST */ \
|
257 |
|
|
"Export Host", /* 49 M_NETADDR */ \
|
258 |
|
|
"NFS srvsock", /* 50 M_NFSSVC */ \
|
259 |
|
|
"NFS uid", /* 51 M_NFSUID */ \
|
260 |
|
|
"NFS daemon", /* 52 M_NFSD */ \
|
261 |
|
|
"ip_moptions", /* 53 M_IPMOPTS */ \
|
262 |
|
|
"in_multi", /* 54 M_IPMADDR */ \
|
263 |
|
|
"ether_multi", /* 55 M_IFMADDR */ \
|
264 |
|
|
"mrt", /* 56 M_MRTABLE */ \
|
265 |
|
|
"ISOFS mount", /* 57 M_ISOFSMNT */ \
|
266 |
|
|
"ISOFS node", /* 58 M_ISOFSNODE */ \
|
267 |
|
|
"MSDOSFS mount", /* 59 M_MSDOSFSMNT */ \
|
268 |
|
|
"MSDOSFS fat", /* 60 M_MSDOSFSFAT */ \
|
269 |
|
|
"MSDOSFS node", /* 61 M_MSDOSFSNODE */ \
|
270 |
|
|
"ttys", /* 62 M_TTYS */ \
|
271 |
|
|
"exec", /* 63 M_EXEC */ \
|
272 |
|
|
"miscfs mount", /* 64 M_MISCFSMNT */ \
|
273 |
|
|
"miscfs node", /* 65 M_MISCFSNODE */ \
|
274 |
|
|
"adosfs mount", /* 66 M_ADOSFSMNT */ \
|
275 |
|
|
"adosfs node", /* 67 M_ADOSFSNODE */ \
|
276 |
|
|
"adosfs anode", /* 68 M_ANODE */ \
|
277 |
|
|
"IP queue ent", /* 69 M_IPQ */ \
|
278 |
|
|
"afs", /* 70 M_AFS */ \
|
279 |
|
|
"adosfs bitmap", /* 71 M_ADOSFSBITMAP */ \
|
280 |
|
|
"EXT2FS node", /* 72 M_EXT2FSNODE */ \
|
281 |
|
|
"pfil", /* 73 M_PFIL */ \
|
282 |
|
|
"pfkey data", /* 74 M_PFKEY */ \
|
283 |
|
|
"tdb", /* 75 M_TDB */ \
|
284 |
|
|
"xform_data", /* 76 M_XDATA */ \
|
285 |
|
|
"vfs", /* 77 M_VFS */ \
|
286 |
|
|
"pagedep", /* 78 M_PAGEDEP */ \
|
287 |
|
|
"inodedep", /* 79 M_INODEDEP */ \
|
288 |
|
|
"newblk", /* 80 M_NEWBLK */ \
|
289 |
|
|
"bmsafemap", /* 81 M_BMSAFEMAP */ \
|
290 |
|
|
"allocdirect", /* 82 M_ALLOCDIRECT */ \
|
291 |
|
|
"indirdep", /* 83 M_INDIRDEP */ \
|
292 |
|
|
"allocindir", /* 84 M_ALLOCINDIR */ \
|
293 |
|
|
"freefrag", /* 85 M_FREEFRAG */ \
|
294 |
|
|
"freeblks", /* 86 M_FREEBLKS */ \
|
295 |
|
|
"freefile", /* 87 M_FREEFILE */ \
|
296 |
|
|
"diradd", /* 88 M_DIRADD */ \
|
297 |
|
|
"mkdir", /* 89 M_MKDIR */ \
|
298 |
|
|
"dirrem", /* 90 M_DIRREM */ \
|
299 |
|
|
"VM page bucket", /* 91 M_VMPBUCKET */ \
|
300 |
|
|
"VM swap", /* 92 M_VMSWAP */ \
|
301 |
|
|
"IPv6 discq", /* 93 M_DISCQ */ \
|
302 |
|
|
"IPv6 fragq", /* 94 M_FRAGQ */ \
|
303 |
|
|
"Sec Assoc", /* 95 M_SECA */ \
|
304 |
|
|
"IPv6 if info", /* 96 M_I6IFP */ \
|
305 |
|
|
"RaidFrame data", /* 97 M_RAIDFRAME */ \
|
306 |
|
|
"UVM amap", /* 98 M_UVMAMAP */ \
|
307 |
|
|
"UVM aobj", /* 99 M_UVMAOBJ */ \
|
308 |
|
|
"pool", /* 100 M_POOL */ \
|
309 |
|
|
"USB", /* 101 M_USB */ \
|
310 |
|
|
"USB device", /* 102 M_USBDEV */ \
|
311 |
|
|
"USB HC", /* 103 M_USBHC */ \
|
312 |
|
|
"pipe", /* 104 M_PIPE */ \
|
313 |
|
|
"memdesc", /* 105 M_MEMDESC */ \
|
314 |
|
|
NULL, \
|
315 |
|
|
NULL, NULL, NULL, NULL, NULL, \
|
316 |
|
|
NULL, NULL, NULL, NULL, NULL, \
|
317 |
|
|
NULL, NULL, NULL, NULL, NULL, \
|
318 |
|
|
NULL, \
|
319 |
|
|
"ip6_options", /* 123 M_IP6OPT */ \
|
320 |
|
|
"NDP", /* 124 M_IP6NDP */ \
|
321 |
|
|
"ip6rr", /* 125 M_IP6RR */ \
|
322 |
|
|
"rp_addr", /* 126 M_RR_ADDR */ \
|
323 |
|
|
"temp", /* 127 M_TEMP */ \
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
#ifndef __ECOS
|
327 |
|
|
struct kmemstats {
|
328 |
|
|
long ks_inuse; /* # of packets of this type currently in use */
|
329 |
|
|
long ks_calls; /* total packets of this type ever allocated */
|
330 |
|
|
long ks_memuse; /* total memory held in bytes */
|
331 |
|
|
u_short ks_limblocks; /* number of times blocked for hitting limit */
|
332 |
|
|
u_short ks_mapblocks; /* number of times blocked for kernel map */
|
333 |
|
|
long ks_maxused; /* maximum number ever used */
|
334 |
|
|
long ks_limit; /* most that are allowed to exist */
|
335 |
|
|
long ks_size; /* sizes of this thing that are allocated */
|
336 |
|
|
long ks_spare;
|
337 |
|
|
};
|
338 |
|
|
|
339 |
|
|
/*
|
340 |
|
|
* Array of descriptors that describe the contents of each page
|
341 |
|
|
*/
|
342 |
|
|
struct kmemusage {
|
343 |
|
|
short ku_indx; /* bucket index */
|
344 |
|
|
union {
|
345 |
|
|
u_short freecnt;/* for small allocations, free pieces in page */
|
346 |
|
|
u_short pagecnt;/* for large allocations, pages alloced */
|
347 |
|
|
} ku_un;
|
348 |
|
|
};
|
349 |
|
|
#define ku_freecnt ku_un.freecnt
|
350 |
|
|
#define ku_pagecnt ku_un.pagecnt
|
351 |
|
|
|
352 |
|
|
/*
|
353 |
|
|
* Set of buckets for each size of memory block that is retained
|
354 |
|
|
*/
|
355 |
|
|
struct kmembuckets {
|
356 |
|
|
caddr_t kb_next; /* list of free blocks */
|
357 |
|
|
caddr_t kb_last; /* last free block */
|
358 |
|
|
long kb_calls; /* total calls to allocate this size */
|
359 |
|
|
long kb_total; /* total number of blocks allocated */
|
360 |
|
|
long kb_totalfree; /* # of free elements in this bucket */
|
361 |
|
|
long kb_elmpercl; /* # of elements in this sized allocation */
|
362 |
|
|
long kb_highwat; /* high water mark */
|
363 |
|
|
long kb_couldfree; /* over high water mark and could free */
|
364 |
|
|
};
|
365 |
|
|
|
366 |
|
|
#ifdef _KERNEL
|
367 |
|
|
#define MINALLOCSIZE (1 << MINBUCKET)
|
368 |
|
|
#define BUCKETINDX(size) \
|
369 |
|
|
((size) <= (MINALLOCSIZE * 128) \
|
370 |
|
|
? (size) <= (MINALLOCSIZE * 8) \
|
371 |
|
|
? (size) <= (MINALLOCSIZE * 2) \
|
372 |
|
|
? (size) <= (MINALLOCSIZE * 1) \
|
373 |
|
|
? (MINBUCKET + 0) \
|
374 |
|
|
: (MINBUCKET + 1) \
|
375 |
|
|
: (size) <= (MINALLOCSIZE * 4) \
|
376 |
|
|
? (MINBUCKET + 2) \
|
377 |
|
|
: (MINBUCKET + 3) \
|
378 |
|
|
: (size) <= (MINALLOCSIZE* 32) \
|
379 |
|
|
? (size) <= (MINALLOCSIZE * 16) \
|
380 |
|
|
? (MINBUCKET + 4) \
|
381 |
|
|
: (MINBUCKET + 5) \
|
382 |
|
|
: (size) <= (MINALLOCSIZE * 64) \
|
383 |
|
|
? (MINBUCKET + 6) \
|
384 |
|
|
: (MINBUCKET + 7) \
|
385 |
|
|
: (size) <= (MINALLOCSIZE * 2048) \
|
386 |
|
|
? (size) <= (MINALLOCSIZE * 512) \
|
387 |
|
|
? (size) <= (MINALLOCSIZE * 256) \
|
388 |
|
|
? (MINBUCKET + 8) \
|
389 |
|
|
: (MINBUCKET + 9) \
|
390 |
|
|
: (size) <= (MINALLOCSIZE * 1024) \
|
391 |
|
|
? (MINBUCKET + 10) \
|
392 |
|
|
: (MINBUCKET + 11) \
|
393 |
|
|
: (size) <= (MINALLOCSIZE * 8192) \
|
394 |
|
|
? (size) <= (MINALLOCSIZE * 4096) \
|
395 |
|
|
? (MINBUCKET + 12) \
|
396 |
|
|
: (MINBUCKET + 13) \
|
397 |
|
|
: (size) <= (MINALLOCSIZE * 16384) \
|
398 |
|
|
? (MINBUCKET + 14) \
|
399 |
|
|
: (MINBUCKET + 15))
|
400 |
|
|
|
401 |
|
|
/*
|
402 |
|
|
* Turn virtual addresses into kmem map indicies
|
403 |
|
|
*/
|
404 |
|
|
#define kmemxtob(alloc) (kmembase + (alloc) * NBPG)
|
405 |
|
|
#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / NBPG)
|
406 |
|
|
#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> CLSHIFT])
|
407 |
|
|
|
408 |
|
|
/*
|
409 |
|
|
* Macro versions for the usual cases of malloc/free
|
410 |
|
|
*/
|
411 |
|
|
#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(_LKM)
|
412 |
|
|
#define MALLOC(space, cast, size, type, flags) \
|
413 |
|
|
(space) = (cast)malloc((u_long)(size), type, flags)
|
414 |
|
|
#define FREE(addr, type) free((caddr_t)(addr), type)
|
415 |
|
|
|
416 |
|
|
#else /* do not collect statistics */
|
417 |
|
|
#define MALLOC(space, cast, size, type, flags) do { \
|
418 |
|
|
register struct kmembuckets *kbp = &bucket[BUCKETINDX(size)]; \
|
419 |
|
|
long s = splimp(); \
|
420 |
|
|
if (kbp->kb_next == NULL) { \
|
421 |
|
|
(space) = (cast)malloc((u_long)(size), type, flags); \
|
422 |
|
|
} else { \
|
423 |
|
|
(space) = (cast)kbp->kb_next; \
|
424 |
|
|
kbp->kb_next = *(caddr_t *)(space); \
|
425 |
|
|
} \
|
426 |
|
|
splx(s); \
|
427 |
|
|
} while (0)
|
428 |
|
|
|
429 |
|
|
#define FREE(addr, type) do { \
|
430 |
|
|
register struct kmembuckets *kbp; \
|
431 |
|
|
register struct kmemusage *kup = btokup(addr); \
|
432 |
|
|
long s = splimp(); \
|
433 |
|
|
if (1 << kup->ku_indx > MAXALLOCSAVE) { \
|
434 |
|
|
free((caddr_t)(addr), type); \
|
435 |
|
|
} else { \
|
436 |
|
|
kbp = &bucket[kup->ku_indx]; \
|
437 |
|
|
if (kbp->kb_next == NULL) \
|
438 |
|
|
kbp->kb_next = (caddr_t)(addr); \
|
439 |
|
|
else \
|
440 |
|
|
*(caddr_t *)(kbp->kb_last) = (caddr_t)(addr); \
|
441 |
|
|
*(caddr_t *)(addr) = NULL; \
|
442 |
|
|
kbp->kb_last = (caddr_t)(addr); \
|
443 |
|
|
} \
|
444 |
|
|
splx(s); \
|
445 |
|
|
} while(0)
|
446 |
|
|
#endif /* do not collect statistics */
|
447 |
|
|
|
448 |
|
|
extern struct kmemstats kmemstats[];
|
449 |
|
|
extern struct kmemusage *kmemusage;
|
450 |
|
|
extern char *kmembase;
|
451 |
|
|
extern struct kmembuckets bucket[];
|
452 |
|
|
|
453 |
|
|
extern void *malloc __P((unsigned long size, int type, int flags));
|
454 |
|
|
extern void free __P((void *addr, int type));
|
455 |
|
|
|
456 |
|
|
#endif /* _KERNEL */
|
457 |
|
|
#endif // __ECOS
|
458 |
|
|
|
459 |
|
|
#if defined(__ECOS) && defined(_KERNEL)
|
460 |
|
|
extern void *cyg_net_malloc(u_long size, int type, int flags);
|
461 |
|
|
extern void cyg_net_free(caddr_t addr, int type);
|
462 |
|
|
#define MALLOC(space, cast, size, type, flags) \
|
463 |
|
|
(space) = (cast)cyg_net_malloc((u_long)(size), type, flags)
|
464 |
|
|
#define malloc(size, type, flags) cyg_net_malloc((u_long)size, type, flags)
|
465 |
|
|
#define FREE(addr, type) cyg_net_free((caddr_t)(addr), type)
|
466 |
|
|
#define free(addr, type) FREE(addr, type)
|
467 |
|
|
#endif
|
468 |
|
|
|
469 |
|
|
#endif /* !_SYS_MALLOC_H_ */
|