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