rf_debugMem.h revision 1.2 1 1.2 thorpej /* $NetBSD: rf_debugMem.h,v 1.2 1999/01/14 22:49:05 thorpej Exp $ */
2 1.1 oster /*
3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
4 1.1 oster * All rights reserved.
5 1.1 oster *
6 1.1 oster * Author: Daniel Stodolsky, Mark Holland
7 1.1 oster *
8 1.1 oster * Permission to use, copy, modify and distribute this software and
9 1.1 oster * its documentation is hereby granted, provided that both the copyright
10 1.1 oster * notice and this permission notice appear in all copies of the
11 1.1 oster * software, derivative works or modified versions, and any portions
12 1.1 oster * thereof, and that both notices appear in supporting documentation.
13 1.1 oster *
14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 oster *
18 1.1 oster * Carnegie Mellon requests users of this software to return to
19 1.1 oster *
20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 oster * School of Computer Science
22 1.1 oster * Carnegie Mellon University
23 1.1 oster * Pittsburgh PA 15213-3890
24 1.1 oster *
25 1.1 oster * any improvements or extensions that they make and grant Carnegie the
26 1.1 oster * rights to redistribute these changes.
27 1.1 oster */
28 1.1 oster
29 1.1 oster /*
30 1.1 oster * rf_debugMem.h -- memory leak debugging module
31 1.1 oster *
32 1.1 oster * IMPORTANT: if you put the lock/unlock mutex stuff back in here, you
33 1.1 oster * need to take it out of the routines in debugMem.c
34 1.1 oster *
35 1.1 oster * Log: rf_debugMem.h,v
36 1.1 oster * Revision 1.27 1996/07/18 22:57:14 jimz
37 1.1 oster * port simulator to AIX
38 1.1 oster *
39 1.1 oster * Revision 1.26 1996/06/11 13:46:43 jimz
40 1.1 oster * make bracing consistent around memory allocation macros
41 1.1 oster *
42 1.1 oster * Revision 1.25 1996/06/10 11:55:47 jimz
43 1.1 oster * Straightened out some per-array/not-per-array distinctions, fixed
44 1.1 oster * a couple bugs related to confusion. Added shutdown lists. Removed
45 1.1 oster * layout shutdown function (now subsumed by shutdown lists).
46 1.1 oster *
47 1.1 oster * Revision 1.24 1996/06/05 18:06:02 jimz
48 1.1 oster * Major code cleanup. The Great Renaming is now done.
49 1.1 oster * Better modularity. Better typing. Fixed a bunch of
50 1.1 oster * synchronization bugs. Made a lot of global stuff
51 1.1 oster * per-desc or per-array. Removed dead code.
52 1.1 oster *
53 1.1 oster * Revision 1.23 1996/05/30 11:29:41 jimz
54 1.1 oster * Numerous bug fixes. Stripe lock release code disagreed with the taking code
55 1.1 oster * about when stripes should be locked (I made it consistent: no parity, no lock)
56 1.1 oster * There was a lot of extra serialization of I/Os which I've removed- a lot of
57 1.1 oster * it was to calculate values for the cache code, which is no longer with us.
58 1.1 oster * More types, function, macro cleanup. Added code to properly quiesce the array
59 1.1 oster * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
60 1.1 oster * before. Fixed memory allocation, freeing bugs.
61 1.1 oster *
62 1.1 oster * Revision 1.22 1996/05/27 18:56:37 jimz
63 1.1 oster * more code cleanup
64 1.1 oster * better typing
65 1.1 oster * compiles in all 3 environments
66 1.1 oster *
67 1.1 oster * Revision 1.21 1996/05/23 22:17:40 jimz
68 1.1 oster * fix alloclist macro names for kernel
69 1.1 oster *
70 1.1 oster * Revision 1.20 1996/05/23 21:46:35 jimz
71 1.1 oster * checkpoint in code cleanup (release prep)
72 1.1 oster * lots of types, function names have been fixed
73 1.1 oster *
74 1.1 oster * Revision 1.19 1996/05/23 13:18:23 jimz
75 1.1 oster * include rf_options.h
76 1.1 oster *
77 1.1 oster * Revision 1.18 1996/05/23 00:33:23 jimz
78 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
79 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
80 1.1 oster *
81 1.1 oster * Revision 1.17 1996/05/21 18:51:54 jimz
82 1.1 oster * cleaned up macro args
83 1.1 oster *
84 1.1 oster * Revision 1.16 1996/05/18 19:51:34 jimz
85 1.1 oster * major code cleanup- fix syntax, make some types consistent,
86 1.1 oster * add prototypes, clean out dead code, et cetera
87 1.1 oster *
88 1.1 oster * Revision 1.15 1996/05/01 16:26:22 jimz
89 1.1 oster * get rid of old ccmn stuff
90 1.1 oster *
91 1.1 oster * Revision 1.14 1995/12/01 15:58:09 root
92 1.1 oster * added copyright info
93 1.1 oster *
94 1.1 oster * Revision 1.13 1995/10/11 15:26:03 jimz
95 1.1 oster * zero memory after allocation in kernel (hide effects
96 1.1 oster * of uninitialized structs)
97 1.1 oster *
98 1.1 oster * Revision 1.12 1995/10/06 17:04:15 jimz
99 1.1 oster * make Malloc and Free in kernel use kernel malloc package, not cam
100 1.1 oster * dbufs (which is gross, and was exhausting cam zalloc limit)
101 1.1 oster *
102 1.1 oster * Revision 1.11 1995/05/01 13:28:00 holland
103 1.1 oster * parity range locks, locking disk requests, recon+parityscan in kernel, etc.
104 1.1 oster *
105 1.1 oster * Revision 1.10 1995/04/24 13:25:51 holland
106 1.1 oster * rewrite to move disk queues, recon, & atomic RMW to kernel
107 1.1 oster *
108 1.1 oster * Revision 1.9 1995/02/17 19:39:56 holland
109 1.1 oster * added size param to all calls to Free().
110 1.1 oster * this is ignored at user level, but necessary in the kernel.
111 1.1 oster *
112 1.1 oster * Revision 1.8 1995/02/10 17:34:10 holland
113 1.1 oster * kernelization changes
114 1.1 oster *
115 1.1 oster * Revision 1.7 1995/02/03 22:31:36 holland
116 1.1 oster * many changes related to kernelization
117 1.1 oster *
118 1.1 oster * Revision 1.6 1995/02/01 15:13:05 holland
119 1.1 oster * moved #include of general.h out of raid.h and into each file
120 1.1 oster *
121 1.1 oster * Revision 1.5 1995/02/01 14:25:19 holland
122 1.1 oster * began changes for kernelization:
123 1.1 oster * changed all instances of mutex_t and cond_t to DECLARE macros
124 1.1 oster * converted configuration code to use config structure
125 1.1 oster *
126 1.1 oster * Revision 1.4 1995/01/11 19:27:02 holland
127 1.1 oster * many changes related to performance tuning
128 1.1 oster *
129 1.1 oster * Revision 1.3 1994/11/29 21:34:56 danner
130 1.1 oster * Changed type of redzone_calloc and malloc to void *.
131 1.1 oster *
132 1.1 oster * Revision 1.2 1994/11/28 22:13:23 danner
133 1.1 oster * Many macros converted to functions.
134 1.1 oster *
135 1.1 oster */
136 1.1 oster
137 1.1 oster #ifndef _RF__RF_DEBUGMEM_H_
138 1.1 oster #define _RF__RF_DEBUGMEM_H_
139 1.1 oster
140 1.1 oster #include "rf_archs.h"
141 1.1 oster #include "rf_alloclist.h"
142 1.1 oster #include "rf_options.h"
143 1.1 oster
144 1.1 oster #ifndef KERNEL
145 1.1 oster
146 1.1 oster #ifndef __NetBSD__
147 1.1 oster void *malloc(), *calloc();
148 1.1 oster #endif
149 1.1 oster RF_DECLARE_EXTERN_MUTEX(rf_debug_mem_mutex)
150 1.1 oster
151 1.1 oster /*
152 1.1 oster * redzone malloc, calloc, and free allocate an extra 16 bytes on each
153 1.1 oster * malloc/calloc call to allow tracking of overflows on free.
154 1.1 oster */
155 1.1 oster
156 1.1 oster #if RF_MEMORY_REDZONES > 0
157 1.1 oster #define rf_redzone_malloc(_p_,_size_) _p_ = rf_real_redzone_malloc(_size_)
158 1.1 oster #define rf_redzone_calloc(_p_,_n_,_size_) _p_ = rf_real_redzone_calloc(_n_,_size_)
159 1.1 oster #define rf_redzone_free(_p_) rf_real_redzone_free(_p_, __LINE__, __FILE__)
160 1.1 oster #else /* RF_MEMORY_REDZONES > 0 */
161 1.1 oster #define rf_redzone_malloc(_p_,_size_) _p_ = malloc(_size_)
162 1.1 oster #define rf_redzone_calloc(_p_,_nel_,_size_) _p_ = calloc(_nel_,_size_)
163 1.1 oster #define rf_redzone_free(_ptr_) free(_ptr_)
164 1.1 oster #endif /* RF_MEMORY_REDZONES > 0 */
165 1.1 oster
166 1.1 oster #define RF_Malloc(_p_, _size_, _cast_) { \
167 1.1 oster _p_ = _cast_ rf_real_Malloc(_size_, __LINE__, __FILE__); \
168 1.1 oster }
169 1.1 oster
170 1.1 oster #define RF_MallocAndAdd(_p_, _size_, _cast_, _alist_) { \
171 1.1 oster _p_ = _cast_ rf_real_MallocAndAdd(_size_, _alist_, __LINE__, __FILE__); \
172 1.1 oster }
173 1.1 oster
174 1.1 oster #define RF_Calloc(_p_, _nel_, _elsz_, _cast_) { \
175 1.1 oster _p_ = _cast_ rf_real_Calloc(_nel_, _elsz_, __LINE__, __FILE__); \
176 1.1 oster }
177 1.1 oster
178 1.1 oster #define RF_CallocAndAdd(_p_, _nel_, _elsz_, _cast_, _alist_) { \
179 1.1 oster _p_ = _cast_ rf_real_CallocAndAdd(_nel_, _elsz_, _alist_, __LINE__, __FILE__); \
180 1.1 oster }
181 1.1 oster
182 1.1 oster #define RF_Free(__p_, _sz_) { \
183 1.1 oster rf_real_Free(__p_, _sz_, __LINE__, __FILE__); \
184 1.1 oster }
185 1.1 oster
186 1.1 oster #else /* KERNEL */
187 1.1 oster
188 1.1 oster #include <sys/types.h>
189 1.1 oster #ifdef __NetBSD__
190 1.1 oster typedef u_int32_t U32;
191 1.1 oster #else
192 1.1 oster #include <io/common/iotypes.h> /* just to get defn of U32 */
193 1.1 oster #endif /* __NetBSD__ */
194 1.1 oster #include <sys/malloc.h>
195 1.1 oster
196 1.1 oster
197 1.1 oster #ifdef __NetBSD__
198 1.1 oster
199 1.1 oster #define RF_Malloc(_p_, _size_, _cast_) \
200 1.1 oster { \
201 1.2 thorpej _p_ = _cast_ malloc((u_long)_size_, M_RAIDFRAME, M_WAITOK); \
202 1.1 oster bzero((char *)_p_, _size_); \
203 1.1 oster if (rf_memDebug) rf_record_malloc(_p_, _size_, __LINE__, __FILE__); \
204 1.1 oster }
205 1.1 oster
206 1.1 oster #else
207 1.1 oster
208 1.1 oster #define RF_Malloc(_p_, _size_, _cast_) \
209 1.1 oster { \
210 1.1 oster _p_ = _cast_ malloc((u_long)_size_, BUCKETINDEX(_size_), M_DEVBUF, M_WAITOK); \
211 1.1 oster bzero((char *)_p_, _size_); \
212 1.1 oster if (rf_memDebug) rf_record_malloc(_p_, _size_, __LINE__, __FILE__); \
213 1.1 oster }
214 1.1 oster #endif /* __NetBSD__ */
215 1.1 oster
216 1.1 oster #define RF_MallocAndAdd(__p_, __size_, __cast_, __alist_) \
217 1.1 oster { \
218 1.1 oster RF_Malloc(__p_, __size_, __cast_); \
219 1.1 oster if (__alist_) rf_AddToAllocList(__alist_, __p_, __size_); \
220 1.1 oster }
221 1.1 oster
222 1.1 oster #define RF_Calloc(_p_, _nel_, _elsz_, _cast_) \
223 1.1 oster { \
224 1.1 oster RF_Malloc( _p_, (_nel_) * (_elsz_), _cast_); \
225 1.1 oster bzero( (_p_), (_nel_) * (_elsz_) ); \
226 1.1 oster }
227 1.1 oster
228 1.1 oster #define RF_CallocAndAdd(__p,__nel,__elsz,__cast,__alist) \
229 1.1 oster { \
230 1.1 oster RF_Calloc(__p, __nel, __elsz, __cast); \
231 1.1 oster if (__alist) rf_AddToAllocList(__alist, __p, (__nel)*(__elsz)); \
232 1.1 oster }
233 1.1 oster
234 1.2 thorpej #ifdef __NetBSD__
235 1.2 thorpej #define RF_Free(_p_, _sz_) \
236 1.2 thorpej { \
237 1.2 thorpej free((void *)(_p_), M_RAIDFRAME); \
238 1.2 thorpej if (rf_memDebug) rf_unrecord_malloc(_p_, (U32) (_sz_)); \
239 1.2 thorpej }
240 1.2 thorpej #else
241 1.1 oster #define RF_Free(_p_, _sz_) \
242 1.1 oster { \
243 1.1 oster free((void *)(_p_), M_DEVBUF); \
244 1.1 oster if (rf_memDebug) rf_unrecord_malloc(_p_, (U32) (_sz_)); \
245 1.1 oster }
246 1.2 thorpej #endif /* __NetBSD__ */
247 1.1 oster
248 1.1 oster #endif /* KERNEL */
249 1.1 oster
250 1.1 oster #ifndef KERNEL
251 1.1 oster void *rf_real_redzone_malloc(int size);
252 1.1 oster void *rf_real_redzone_calloc(int n, int size);
253 1.1 oster void rf_real_redzone_free(char *p, int line, char *filen);
254 1.1 oster char *rf_real_Malloc(int size, int line, char *file);
255 1.1 oster char *rf_real_Calloc(int nel, int elsz, int line, char *file);
256 1.1 oster void rf_real_Free(void *p, int sz, int line, char *file);
257 1.1 oster void rf_validate_mh_table(void);
258 1.1 oster #if RF_UTILITY == 0
259 1.1 oster char *rf_real_MallocAndAdd(int size, RF_AllocListElem_t *alist, int line, char *file);
260 1.1 oster char *rf_real_CallocAndAdd(int nel, int elsz, RF_AllocListElem_t *alist, int line, char *file);
261 1.1 oster #endif /* RF_UTILITY == 0 */
262 1.1 oster #endif /* !KERNEL */
263 1.1 oster
264 1.1 oster void rf_record_malloc(void *p, int size, int line, char *filen);
265 1.1 oster void rf_unrecord_malloc(void *p, int sz);
266 1.1 oster void rf_print_unfreed(void);
267 1.1 oster int rf_ConfigureDebugMem(RF_ShutdownList_t **listp);
268 1.1 oster void rf_ReportMaxMem(void);
269 1.1 oster
270 1.1 oster #endif /* !_RF__RF_DEBUGMEM_H_ */
271