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