Project

General

Profile

Submit #2721 ยป patch-objcache.txt

dclink, 08/30/2014 10:12 AM

 
1
diff --git a/sys/netbt/bt_proto.c b/sys/netbt/bt_proto.c
2
index 0a1ca9b..54c5eb7 100644
3
--- a/sys/netbt/bt_proto.c
4
+++ b/sys/netbt/bt_proto.c
5
@@ -136,24 +136,24 @@ struct protosw btsw[] = {
6
 static void
7
 netbt_dispose(struct mbuf* m)
8
 {
9
-	zdestroy(l2cap_pdu_pool);
10
-	zdestroy(l2cap_req_pool);
11
-	zdestroy(rfcomm_credit_pool);
12
+	objcache_destroy(l2cap_pdu_pool);
13
+	objcache_destroy(l2cap_req_pool);
14
+	objcache_destroy(rfcomm_credit_pool);
15
 }
16
 
17
 static void
18
 netbt_init(void)
19
 {
20
-	l2cap_pdu_pool = zinit("l2cap_pdu", sizeof(struct l2cap_pdu), 1,
21
-	    ZONE_DESTROYABLE, 1);
22
+	l2cap_pdu_pool = objcache_create_simple(M_L2CAPPDU, 
23
+						sizeof(struct l2cap_pdu));
24
 	if (l2cap_pdu_pool == NULL)
25
 		goto fail;
26
-	l2cap_req_pool = zinit("l2cap_req", sizeof(struct l2cap_req), 1,
27
-	    ZONE_DESTROYABLE, 1);
28
+	l2cap_req_pool = objcache_create_simple(M_L2CAPREQ, 
29
+						sizeof(struct l2cap_req));
30
 	if (l2cap_req_pool == NULL)
31
 		goto fail;
32
-	rfcomm_credit_pool = zinit("rfcomm_credit",
33
-	    sizeof(struct rfcomm_credit), 1, ZONE_DESTROYABLE, 1);
34
+	rfcomm_credit_pool = objcache_create_simple(M_RFCOMMCREDIT,
35
+	    sizeof(struct rfcomm_credit));
36
 	if (rfcomm_credit_pool == NULL)
37
 		goto fail;
38
 	return;
39
diff --git a/sys/netbt/hci_link.c b/sys/netbt/hci_link.c
40
index 8995ff1..68fbdd8 100644
41
--- a/sys/netbt/hci_link.c
42
+++ b/sys/netbt/hci_link.c
43
@@ -549,7 +549,7 @@ hci_acl_send(struct mbuf *m, struct hci_link *link,
44
 		return ENETDOWN;
45
 	}
46
 
47
-	pdu = zalloc(l2cap_pdu_pool);
48
+	pdu = objcache_get(l2cap_pdu_pool, M_WAITOK);
49
 	if (pdu == NULL)
50
 		goto nomem;
51
 
52
@@ -594,7 +594,7 @@ nomem:
53
 	if (m) m_freem(m);
54
 	if (pdu) {
55
 		IF_DRAIN(&pdu->lp_data);
56
-		zfree(l2cap_pdu_pool, pdu);
57
+		objcache_dtor(l2cap_pdu_pool, pdu);
58
 	}
59
 
60
 	return ENOMEM;
61
@@ -740,7 +740,7 @@ hci_acl_complete(struct hci_link *link, int num)
62
 						l2cap_start(chan);
63
 				}
64
 
65
-				zfree(l2cap_pdu_pool, pdu);
66
+				objcache_dtor(l2cap_pdu_pool, pdu);
67
 			}
68
 		} else {
69
 			pdu->lp_pending -= num;
70
@@ -965,7 +965,7 @@ hci_link_free(struct hci_link *link, int err)
71
 		if (pdu->lp_pending)
72
 			link->hl_unit->hci_num_acl_pkts += pdu->lp_pending;
73
 
74
-		zfree(l2cap_pdu_pool, pdu);
75
+		objcache_dtor(l2cap_pdu_pool, pdu);
76
 	}
77
 
78
 	KKASSERT(TAILQ_EMPTY(&link->hl_txq));
79
diff --git a/sys/netbt/l2cap.h b/sys/netbt/l2cap.h
80
index fe2286a..24d1bed 100644
81
--- a/sys/netbt/l2cap.h
82
+++ b/sys/netbt/l2cap.h
83
@@ -72,6 +72,7 @@
84
 #define _NETBT_L2CAP_H_
85
 
86
 #include <sys/types.h>
87
+#include <sys/objcache.h>
88
 
89
 /**************************************************************************
90
  **************************************************************************
91
@@ -354,17 +355,18 @@ typedef union {
92
 #define L2CAP_LM_SECURE		(1<<2)	/* want secured link */
93
 
94
 #ifdef _KERNEL
95
-#include <vm/vm_zone.h>
96
 
97
 #include <net/if.h>		/* for struct ifqueue */
98
 
99
 LIST_HEAD(l2cap_channel_list, l2cap_channel);
100
 
101
 /* global variables */
102
+MALLOC_DECLARE(M_L2CAPREQ);
103
+MALLOC_DECLARE(M_L2CAPPDU);
104
 extern struct l2cap_channel_list l2cap_active_list;
105
 extern struct l2cap_channel_list l2cap_listen_list;
106
-extern vm_zone_t l2cap_pdu_pool;
107
-extern vm_zone_t l2cap_req_pool;
108
+extern struct objcache *l2cap_pdu_pool;
109
+extern struct objcache *l2cap_req_pool;
110
 extern const l2cap_qos_t l2cap_default_qos;
111
 
112
 /* sysctl variables */
113
diff --git a/sys/netbt/l2cap_misc.c b/sys/netbt/l2cap_misc.c
114
index 0b63067..21c6216 100644
115
--- a/sys/netbt/l2cap_misc.c
116
+++ b/sys/netbt/l2cap_misc.c
117
@@ -48,8 +48,10 @@ struct l2cap_channel_list
118
 struct l2cap_channel_list
119
 	l2cap_listen_list = LIST_HEAD_INITIALIZER(l2cap_listen_list);
120
 
121
-vm_zone_t l2cap_req_pool;
122
-vm_zone_t l2cap_pdu_pool;
123
+MALLOC_DEFINE(M_L2CAPREQ, "l2cap_req", "l2cap_req objcache");
124
+MALLOC_DEFINE(M_L2CAPPDU, "l2cap_pdu", "l2cap_pdu objcache");
125
+struct objcache *l2cap_req_pool;
126
+struct objcache *l2cap_pdu_pool;
127
 
128
 const l2cap_qos_t l2cap_default_qos = {
129
 	0,			/* flags */
130
@@ -122,7 +124,7 @@ l2cap_request_alloc(struct l2cap_channel *chan, uint8_t code)
131
 	if (req && req->lr_id == next_id)
132
 		return ENFILE;
133
 
134
-	req = zalloc(l2cap_req_pool);
135
+	req = objcache_get(l2cap_req_pool, M_WAITOK);
136
 	if (req == NULL)
137
 		return ENOMEM;
138
 
139
@@ -170,7 +172,7 @@ l2cap_request_free(struct l2cap_req *req)
140
 		return;
141
 
142
 	TAILQ_REMOVE(&link->hl_reqs, req, lr_next);
143
-	zfree(l2cap_req_pool, req);
144
+	objcache_dtor(l2cap_req_pool, req);
145
 }
146
 
147
 /*
148
diff --git a/sys/netbt/l2cap_socket.c b/sys/netbt/l2cap_socket.c
149
index 164bf17..cf5e3e5 100644
150
--- a/sys/netbt/l2cap_socket.c
151
+++ b/sys/netbt/l2cap_socket.c
152
@@ -49,8 +49,6 @@
153
 
154
 #include <sys/msgport2.h>
155
 
156
-#include <vm/vm_zone.h>
157
-
158
 #include <netbt/bluetooth.h>
159
 #include <netbt/hci.h>		/* XXX for EPASSTHROUGH */
160
 #include <netbt/l2cap.h>
161
diff --git a/sys/netbt/rfcomm.h b/sys/netbt/rfcomm.h
162
index ff9c324..591164f 100644
163
--- a/sys/netbt/rfcomm.h
164
+++ b/sys/netbt/rfcomm.h
165
@@ -65,6 +65,7 @@
166
 #define _NETBT_RFCOMM_H_
167
 
168
 #include <sys/types.h>
169
+#include <sys/objcache.h>
170
 
171
 /*************************************************************************
172
  *************************************************************************
173
@@ -426,7 +427,8 @@ int rfcomm_setopt(struct rfcomm_dlc *, int, void *);
174
 int rfcomm_setopt2(struct rfcomm_dlc *, int, struct socket *, struct sockopt *);
175
 int rfcomm_getopt(struct rfcomm_dlc *, int, void *);
176
 
177
-extern vm_zone_t rfcomm_credit_pool;
178
+MALLOC_DECLARE(M_RFCOMMCREDIT);
179
+extern struct objcache *rfcomm_credit_pool;
180
 #endif /* _KERNEL */
181
 
182
 #endif /* _NETBT_RFCOMM_H_ */
183
diff --git a/sys/netbt/rfcomm_session.c b/sys/netbt/rfcomm_session.c
184
index 58531e3..a0d12f2 100644
185
--- a/sys/netbt/rfcomm_session.c
186
+++ b/sys/netbt/rfcomm_session.c
187
@@ -95,7 +95,9 @@ struct rfcomm_session_list
188
 struct rfcomm_session_list
189
 	rfcomm_session_listen = LIST_HEAD_INITIALIZER(rfcomm_session_listen);
190
 
191
-vm_zone_t rfcomm_credit_pool;
192
+
193
+MALLOC_DEFINE(M_RFCOMMCREDIT, "rfcomm_credit", "rfcomm_credit cache");
194
+struct objcache *rfcomm_credit_pool;
195
 
196
 /*
197
  * RFCOMM System Parameters (see section 5.3)
198
@@ -159,8 +161,9 @@ static const uint8_t crctable[256] = {	/* reversed, 8-bit, poly=0x07 */
199
 void
200
 rfcomm_init(void)
201
 {
202
-	rfcomm_credit_pool = zinit("rfcomm_credit",
203
-	    sizeof(struct rfcomm_credit), 0, 0, 0);
204
+	rfcomm_credit_pool = objcache_create_simple(
205
+				M_RFCOMMCREDIT,
206
+			 	sizeof(struct rfcomm_credit));
207
 }
208
 
209
 /*
210
@@ -242,7 +245,7 @@ rfcomm_session_free(struct rfcomm_session *rs)
211
 	/* throw away any remaining credit notes */
212
 	while ((credit = STAILQ_FIRST(&rs->rs_credits)) != NULL) {
213
 		STAILQ_REMOVE_HEAD(&rs->rs_credits, rc_next);
214
-		zfree(rfcomm_credit_pool, credit);
215
+		objcache_dtor(rfcomm_credit_pool, credit);
216
 	}
217
 
218
 	KKASSERT(STAILQ_EMPTY(&rs->rs_credits));
219
@@ -481,7 +484,7 @@ rfcomm_session_complete(void *arg, int count)
220
 		}
221
 
222
 		STAILQ_REMOVE_HEAD(&rs->rs_credits, rc_next);
223
-		zfree(rfcomm_credit_pool, credit);
224
+		objcache_dtor(rfcomm_credit_pool, credit);
225
 	}
226
 
227
 	/*
228
@@ -1458,13 +1461,13 @@ rfcomm_session_send_frame(struct rfcomm_session *rs, int type, int dlci)
229
 	struct mbuf *m;
230
 	uint8_t fcs, cr;
231
 
232
-	credit = zalloc(rfcomm_credit_pool);
233
+	credit = objcache_get(rfcomm_credit_pool, M_NOWAIT);
234
 	if (credit == NULL)
235
 		return ENOMEM;
236
 
237
 	m = m_gethdr(MB_DONTWAIT, MT_DATA);
238
 	if (m == NULL) {
239
-		zfree(rfcomm_credit_pool, credit);
240
+		objcache_dtor(rfcomm_credit_pool, credit);
241
 		return ENOMEM;
242
 	}
243
 
244
@@ -1529,7 +1532,7 @@ rfcomm_session_send_uih(struct rfcomm_session *rs, struct rfcomm_dlc *dlc,
245
 	/*
246
 	 * Make a credit note for the completion notification
247
 	 */
248
-	credit = zalloc(rfcomm_credit_pool);
249
+	credit = objcache_get(rfcomm_credit_pool, M_NOWAIT);
250
 	if (credit == NULL)
251
 		goto nomem;
252
 
253
@@ -1620,7 +1623,7 @@ nomem:
254
 
255
 fail:
256
 	if (credit != NULL)
257
-		zfree(rfcomm_credit_pool, credit);
258
+		objcache_dtor(rfcomm_credit_pool, credit);
259
 
260
 	return err;
261
 }
262
diff --git a/sys/netbt/rfcomm_socket.c b/sys/netbt/rfcomm_socket.c
263
index 3357d13..5f68c2c 100644
264
--- a/sys/netbt/rfcomm_socket.c
265
+++ b/sys/netbt/rfcomm_socket.c
266
@@ -50,8 +50,6 @@
267
 
268
 #include <sys/msgport2.h>
269
 
270
-#include <vm/vm_zone.h>
271
-
272
 #include <netbt/bluetooth.h>
273
 #include <netbt/hci.h>		/* XXX for EPASSTHROUGH */
274
 #include <netbt/rfcomm.h>
275
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
276
index 3181c89..a45c9c8 100644
277
--- a/sys/vm/swap_pager.c
278
+++ b/sys/vm/swap_pager.c
279
@@ -107,6 +107,7 @@
280
 #include <sys/blist.h>
281
 #include <sys/lock.h>
282
 #include <sys/thread2.h>
283
+#include <sys/objcache.h>
284
 
285
 #include "opt_swap.h"
286
 #include <vm/vm.h>
287
@@ -116,7 +117,6 @@
288
 #include <vm/vm_pageout.h>
289
 #include <vm/swap_pager.h>
290
 #include <vm/vm_extern.h>
291
-#include <vm/vm_zone.h>
292
 #include <vm/vnode_pager.h>
293
 
294
 #include <sys/buf2.h>
295
@@ -191,7 +191,11 @@ SYSCTL_INT(_vm, OID_AUTO, swap_size,
296
 SYSCTL_INT(_vm, OID_AUTO, report_swap_allocs,
297
         CTLFLAG_RW, &vm_report_swap_allocs, 0, "");
298
 
299
-vm_zone_t		swap_zone;
300
+MALLOC_DEFINE(M_SWAPZONE, "SWAP ZONE", "SWAP ZONE objcache");
301
+struct objcache_malloc_args	swap_zone_malloc_args = {
302
+	sizeof(struct swblock), M_SWAPZONE
303
+};
304
+struct objcache			*swap_zone;
305
 
306
 /*
307
  * Red-Black tree for swblock entries
308
@@ -390,12 +394,13 @@ swap_pager_swap_init(void)
309
 	n2 = n;
310
 
311
 	do {
312
-		swap_zone = zinit(
313
-			"SWAPMETA", 
314
-			sizeof(struct swblock), 
315
-			n,
316
-			ZONE_INTERRUPT, 
317
-			1);
318
+		swap_zone = objcache_create(
319
+			"SWAPMETA",
320
+			0,
321
+			n, NULL, NULL, NULL,
322
+			objcache_malloc_alloc,
323
+			objcache_malloc_free,
324
+			&swap_zone_malloc_args);
325
 		if (swap_zone != NULL)
326
 			break;
327
 		/*
328
@@ -2166,7 +2171,7 @@ retry:
329
 	if (swap == NULL) {
330
 		int i;
331
 
332
-		swap = zalloc(swap_zone);
333
+		swap = objcache_get(swap_zone, M_WAITOK);
334
 		if (swap == NULL) {
335
 			vm_wait(0);
336
 			goto retry;
337
@@ -2295,7 +2300,7 @@ swp_pager_meta_free_callback(struct swblock *swap, void *data)
338
 			--mycpu->gd_vmtotal.t_vm;
339
 			if (--swap->swb_count == 0) {
340
 				swp_pager_remove(object, swap);
341
-				zfree(swap_zone, swap);
342
+				objcache_dtor(swap_zone, swap);
343
 				--object->swblock_count;
344
 				break;
345
 			}
346
@@ -2341,7 +2346,7 @@ swp_pager_meta_free_all(vm_object_t object)
347
 		}
348
 		if (swap->swb_count != 0)
349
 			panic("swap_pager_meta_free_all: swb_count != 0");
350
-		zfree(swap_zone, swap);
351
+		objcache_dtor(swap_zone, swap);	
352
 		--object->swblock_count;
353
 		lwkt_yield();
354
 	}
355
@@ -2392,7 +2397,7 @@ swp_pager_meta_ctl(vm_object_t object, vm_pindex_t index, int flags)
356
 				--mycpu->gd_vmtotal.t_vm;
357
 				if (--swap->swb_count == 0) {
358
 					swp_pager_remove(object, swap);
359
-					zfree(swap_zone, swap);
360
+					objcache_dtor(swap_zone, swap);
361
 					--object->swblock_count;
362
 				}
363
 			} 
    (1-1/1)