1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 #ifndef _SYS_POOL_H_
42 #define _SYS_POOL_H_
43
44
45
46
47
48
49
50 #define KERN_POOL_NPOOLS 1
51 #define KERN_POOL_NAME 2
52 #define KERN_POOL_POOL 3
53
54 #include <sys/lock.h>
55 #include <sys/queue.h>
56 #include <sys/time.h>
57 #include <sys/tree.h>
58
59 struct pool_cache {
60 TAILQ_ENTRY(pool_cache)
61 pc_poollist;
62 TAILQ_HEAD(, pool_cache_group)
63 pc_grouplist;
64 struct pool_cache_group
65 *pc_allocfrom;
66 struct pool_cache_group
67 *pc_freeto;
68 struct pool *pc_pool;
69 struct simplelock pc_slock;
70
71 int (*pc_ctor)(void *, void *, int);
72 void (*pc_dtor)(void *, void *);
73 void *pc_arg;
74
75
76 unsigned long pc_hits;
77 unsigned long pc_misses;
78
79 unsigned long pc_ngroups;
80
81 unsigned long pc_nitems;
82 };
83
84 struct pool_allocator {
85 void *(*pa_alloc)(struct pool *, int);
86 void (*pa_free)(struct pool *, void *);
87 int pa_pagesz;
88
89
90 struct simplelock pa_slock;
91 TAILQ_HEAD(,pool) pa_list;
92 int pa_flags;
93 #define PA_INITIALIZED 0x01
94 #define PA_WANT 0x02
95 int pa_pagemask;
96 int pa_pageshift;
97 };
98
99 LIST_HEAD(pool_pagelist,pool_item_header);
100
101 struct pool {
102 TAILQ_ENTRY(pool)
103 pr_poollist;
104 struct pool_pagelist
105 pr_emptypages;
106 struct pool_pagelist
107 pr_fullpages;
108 struct pool_pagelist
109 pr_partpages;
110 struct pool_item_header *pr_curpage;
111 TAILQ_HEAD(,pool_cache)
112 pr_cachelist;
113 unsigned int pr_size;
114 unsigned int pr_align;
115 unsigned int pr_itemoffset;
116 unsigned int pr_minitems;
117 unsigned int pr_minpages;
118 unsigned int pr_maxpages;
119 unsigned int pr_npages;
120 unsigned int pr_itemsperpage;
121 unsigned int pr_slack;
122 unsigned int pr_nitems;
123 unsigned int pr_nout;
124 unsigned int pr_hardlimit;
125
126 unsigned int pr_serial;
127 struct pool_allocator *pr_alloc;
128 TAILQ_ENTRY(pool) pr_alloc_list;
129 const char *pr_wchan;
130 unsigned int pr_flags;
131 unsigned int pr_roflags;
132 #define PR_MALLOCOK 0x01
133 #define PR_NOWAIT 0x00
134 #define PR_WAITOK 0x02
135 #define PR_WANTED 0x04
136 #define PR_PHINPAGE 0x08
137 #define PR_LOGGING 0x10
138 #define PR_LIMITFAIL 0x20
139 #define PR_DEBUG 0x40
140
141
142
143
144
145
146
147
148
149
150 struct simplelock pr_slock;
151 int pr_ipl;
152
153 SPLAY_HEAD(phtree, pool_item_header) pr_phtree;
154
155 int pr_maxcolor;
156 int pr_curcolor;
157 int pr_phoffset;
158
159
160
161
162
163 const char *pr_hardlimit_warning;
164 struct timeval pr_hardlimit_ratecap;
165 struct timeval pr_hardlimit_warning_last;
166
167
168
169
170 unsigned long pr_nget;
171 unsigned long pr_nfail;
172 unsigned long pr_nput;
173 unsigned long pr_npagealloc;
174 unsigned long pr_npagefree;
175 unsigned int pr_hiwat;
176 unsigned long pr_nidle;
177
178
179
180
181 struct pool_log *pr_log;
182 int pr_curlogentry;
183 int pr_logsize;
184
185 const char *pr_entered_file;
186 long pr_entered_line;
187 };
188
189 #ifdef _KERNEL
190
191 extern struct pool_allocator pool_allocator_oldnointr;
192
193 extern struct pool_allocator pool_allocator_nointr;
194
195 void pool_init(struct pool *, size_t, u_int, u_int, int,
196 const char *, struct pool_allocator *);
197 #ifdef DIAGNOSTIC
198 void pool_setipl(struct pool *, int);
199 #else
200 #define pool_setipl(p, i) do { } while (0)
201 #endif
202 void pool_destroy(struct pool *);
203
204 void *pool_get(struct pool *, int) __malloc;
205 void pool_put(struct pool *, void *);
206 int pool_reclaim(struct pool *);
207
208 #ifdef POOL_DIAGNOSTIC
209
210
211
212 void *_pool_get(struct pool *, int, const char *, long);
213 void _pool_put(struct pool *, void *, const char *, long);
214 int _pool_reclaim(struct pool *, const char *, long);
215 #define pool_get(h, f) _pool_get((h), (f), __FILE__, __LINE__)
216 #define pool_put(h, v) _pool_put((h), (v), __FILE__, __LINE__)
217 #define pool_reclaim(h) _pool_reclaim((h), __FILE__, __LINE__)
218 #endif
219
220 int pool_prime(struct pool *, int);
221 void pool_setlowat(struct pool *, int);
222 void pool_sethiwat(struct pool *, int);
223 int pool_sethardlimit(struct pool *, unsigned, const char *, int);
224
225 #ifdef DDB
226
227
228
229 void pool_printit(struct pool *, const char *,
230 int (*)(const char *, ...));
231 int pool_chk(struct pool *, const char *);
232 #endif
233
234
235
236
237 void pool_cache_init(struct pool_cache *, struct pool *,
238 int (*ctor)(void *, void *, int),
239 void (*dtor)(void *, void *),
240 void *);
241 void pool_cache_destroy(struct pool_cache *);
242 void *pool_cache_get(struct pool_cache *, int);
243 void pool_cache_put(struct pool_cache *, void *);
244 void pool_cache_destruct_object(struct pool_cache *, void *);
245 void pool_cache_invalidate(struct pool_cache *);
246 #endif
247
248 #endif