1From dcb04c4830b3bb71205a10a4aa84d631aac94222 Mon Sep 17 00:00:00 2001
2From: Matthew Macy <kmacy@freebsd.org>
3Date: Sat, 8 Nov 2014 13:37:10 -0800
4Subject: [PATCH] remap pools to uma zones
5
6(cherry picked from commit 2165c018fc9389723d58881d9f231b544de17915)
7Signed-off-by: Scott K <scott@ixsystems.com>
8---
9 sys/compat/mach/mach_message.c   | 18 ++++++++++--------
10 sys/compat/mach/mach_misc.c      |  1 -
11 sys/compat/mach/mach_port.c      | 28 ++++++++++++++++------------
12 sys/compat/mach/mach_semaphore.c | 33 +++++++++++++++++----------------
13 4 files changed, 43 insertions(+), 37 deletions(-)
14
15diff --git a/sys/compat/mach/mach_message.c b/sys/compat/mach/mach_message.c
16index 0b005e4..92b60d8 100644
17--- a/sys/compat/mach/mach_message.c
18+++ b/sys/compat/mach/mach_message.c
19@@ -40,9 +40,10 @@ __FBSDID("$FreeBSD$");
20 #include <sys/kernel.h>
21 #include <sys/queue.h>
22 #include <sys/malloc.h>
23-#include <sys/pool.h>
24 #include <sys/ktrace.h>
25
26+#include <vm/uma.h>
27+
28 #include <compat/mach/mach_types.h>
29 #include <compat/mach/mach_message.h>
30 #include <compat/mach/mach_port.h>
31@@ -54,8 +55,8 @@ __FBSDID("$FreeBSD$");
32 #include <compat/darwin/darwin_exec.h>
33 #endif
34
35-/* Mach message pool */
36-static struct pool mach_message_pool;
37+/* Mach message zone */
38+static uma_zone_t mach_message_zone;
39
40 static inline
41     int mach_msg_send(struct thread *, mach_msg_header_t *, int *, size_t);
42@@ -1098,9 +1099,10 @@ inline void mach_add_ool_desc(msg, addr, size)
43 void
44 mach_message_init(void)
45 {
46-	pool_init(&mach_message_pool, sizeof (struct mach_message),
47-	    0, 0, 0, "mach_message_pool", NULL, IPL_NONE);
48-	return;
49+
50+	mach_message_zone =
51+		uma_zcreate("mach_message_zone", sizeof (struct mach_message),
52+					NULL, NULL, NULL, 0/* align*/, 0/*flags*/);
53 }
54
55 struct mach_message *
56@@ -1108,7 +1110,7 @@ mach_message_get(mach_msg_header_t *msgh, size_t size, struct mach_port *mp, str
57 {
58 	struct mach_message *mm;
59
60-	mm = (struct mach_message *)pool_get(&mach_message_pool, PR_WAITOK);
61+	mm = uma_zallac(mach_message_zone, M_WAITOK);
62 	memset(mm, 0, sizeof(*mm));
63 	mm->mm_msg = msgh;
64 	mm->mm_size = size;
65@@ -1165,7 +1167,7 @@ mach_message_put_exclocked(struct mach_message *mm)
66 	TAILQ_REMOVE(&mp->mp_msglist, mm, mm_list);
67 	mp->mp_count--;
68
69-	pool_put(&mach_message_pool, mm);
70+	uma_zfree(mach_message_zone, mm);
71
72 	return;
73 }
74diff --git a/sys/compat/mach/mach_misc.c b/sys/compat/mach/mach_misc.c
75index 5df2eb1..1798532 100644
76--- a/sys/compat/mach/mach_misc.c
77+++ b/sys/compat/mach/mach_misc.c
78@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
79 #include <sys/ioctl.h>
80 #include <sys/kernel.h>
81 #include <sys/malloc.h>
82-#include <sys/pool.h>
83 #include <sys/mbuf.h>
84 #include <sys/mman.h>
85 #include <sys/mount.h>
86diff --git a/sys/compat/mach/mach_port.c b/sys/compat/mach/mach_port.c
87index 0b0efc9..2836791 100644
88--- a/sys/compat/mach/mach_port.c
89+++ b/sys/compat/mach/mach_port.c
90@@ -34,11 +34,12 @@ __FBSDID("$FreeBSD$");
91 #include <sys/param.h>
92 #include <sys/systm.h>
93 #include <sys/signal.h>
94-#include <sys/pool.h>
95 #include <sys/queue.h>
96 #include <sys/malloc.h>
97 #include <sys/proc.h>
98
99+#include <vm/uma.h>
100+
101 #include <compat/mach/mach_types.h>
102 #include <compat/mach/mach_message.h>
103 #include <compat/mach/mach_port.h>
104@@ -54,9 +55,9 @@ __FBSDID("$FreeBSD$");
105 #include <compat/darwin/darwin_exec.h>
106 #endif
107
108-/* Right and port pools, list of all rights and its lock */
109-static struct pool mach_port_pool;
110-static struct pool mach_right_pool;
111+/* Right and port zones, list of all rights and its lock */
112+static uma_zone_t mach_port_zone;
113+static uma_zone_t mach_right_zone;
114
115 struct mach_port *mach_bootstrap_port;
116 struct mach_port *mach_clock_port;
117@@ -621,10 +622,13 @@ mach_port_mod_refs(struct mach_trap_args *args)
118 void
119 mach_port_init(void)
120 {
121-	pool_init(&mach_port_pool, sizeof (struct mach_port),
122-	    0, 0, 0, "mach_port_pool", NULL, IPL_NONE);
123-	pool_init(&mach_right_pool, sizeof (struct mach_right),
124-	    0, 0, 0, "mach_right_pool", NULL, IPL_NONE);
125+
126+	mach_port_zone =
127+		uma_zcreate("mach_port_zone", sizeof (struct mach_port),
128+						NULL, NULL, NULL, 0/* align*/, 0/*flags*/);
129+	mach_right_zone =
130+		uma_zcreate("mach_right_zone", sizeof (struct mach_right),
131+						NULL, NULL, NULL, 0/* align*/, 0/*flags*/);
132
133 	mach_bootstrap_port = mach_port_get();
134 	mach_clock_port = mach_port_get();
135@@ -644,7 +648,7 @@ mach_port_get(void)
136 {
137 	struct mach_port *mp;
138
139-	mp = (struct mach_port *)pool_get(&mach_port_pool, PR_WAITOK);
140+	mp = uma_zalloc(mach_port_zone, M_WAITOK);
141 	memset(mp, 0, sizeof(*mp));
142 	mp->mp_recv = NULL;
143 	mp->mp_count = 0;
144@@ -678,7 +682,7 @@ mach_port_put(struct mach_port *mp)
145 	if (mp->mp_flags & MACH_MP_DATA_ALLOCATED)
146 		free(mp->mp_data, M_MACH);
147
148-	pool_put(&mach_port_pool, mp);
149+	uma_zfree(mach_port_zone, mp);
150
151 	return;
152 }
153@@ -717,7 +721,7 @@ mach_right_get(struct mach_port *mp, struct thread *td, int type, mach_port_t hi
154 		}
155 	}
156
157-	mr = pool_get(&mach_right_pool, PR_WAITOK);
158+	mr = uma_zalloc(mach_right_zone, M_WAITOK);
159
160 	mr->mr_port = mp;
161 	mr->mr_lwp = l;
162@@ -875,7 +879,7 @@ mach_right_put_exclocked(struct mach_right *mr, int right)
163
164 		mach_notify_port_destroyed(mr->mr_lwp, mr);
165 		LIST_REMOVE(mr, mr_list);
166-		pool_put(&mach_right_pool, mr);
167+		uma_zfree(mach_right_zone, mr);
168 	}
169 	return;
170 }
171diff --git a/sys/compat/mach/mach_semaphore.c b/sys/compat/mach/mach_semaphore.c
172index 6953b1a..befbd5f 100644
173--- a/sys/compat/mach/mach_semaphore.c
174+++ b/sys/compat/mach/mach_semaphore.c
175@@ -33,12 +33,13 @@ __FBSDID("$FreeBSD$");
176 #include <sys/types.h>
177 #include <sys/param.h>
178 #include <sys/systm.h>
179-#include <sys/signal.h>
180 #include <sys/lock.h>
181 #include <sys/malloc.h>
182-#include <sys/pool.h>
183 #include <sys/proc.h>
184 #include <sys/rwlock.h>
185+#include <sys/signal.h>
186+
187+#include <vm/uma.h>
188
189 #include <compat/mach/mach_types.h>
190 #include <compat/mach/mach_message.h>
191@@ -49,11 +50,11 @@ __FBSDID("$FreeBSD$");
192 #include <compat/mach/mach_services.h>
193 #include <compat/mach/mach_proto.h>
194
195-/* Semaphore list, lock, pools */
196+/* Semaphore list, lock, zones */
197 static LIST_HEAD(mach_semaphore_list, mach_semaphore) mach_semaphore_list;
198-static krwlock_t mach_semaphore_list_lock;
199-static struct pool mach_semaphore_list_pool;
200-static struct pool mach_waiting_lwp_pool;
201+static struct rwlock mach_semaphore_list_lock;
202+static uma_zone_t mach_semaphore_list_zone;
203+static uma_zone_t mach_waiting_lwp_zone;
204
205 /* Function to manipulate them */
206 static struct mach_semaphore *mach_semaphore_get(int, int);
207@@ -199,10 +200,12 @@ mach_semaphore_init(void)
208 {
209 	LIST_INIT(&mach_semaphore_list);
210 	rw_init(&mach_semaphore_list_lock);
211-	pool_init(&mach_semaphore_list_pool, sizeof (struct mach_semaphore),
212-	    0, 0, 0, "mach_sem_pool", NULL, IPL_NONE);
213-	pool_init(&mach_waiting_lwp_pool, sizeof (struct mach_waiting_lwp),
214-	    0, 0, 0, "mach_waitp_pool", NULL, IPL_NONE);
215+	mach_semaphore_list_zone =
216+		uma_zcreate("mach_sem_zone", sizeof (struct mach_semaphore),
217+					NULL, NULL, NULL, 0/* align*/, 0/*flags*/);
218+	mach_waiting_lwp_zone =
219+		uma_zcreate("mach_waitp_zone", sizeof (struct mach_waiting_lwp),
220+					NULL, NULL, NULL, 0/* align*/, 0/*flags*/);
221
222 	return;
223 }
224@@ -212,8 +215,7 @@ mach_semaphore_get(int value, int policy)
225 {
226 	struct mach_semaphore *ms;
227
228-	ms = (struct mach_semaphore *)pool_get(&mach_semaphore_list_pool,
229-	    M_WAITOK);
230+	ms = uma_zalloc(mach_semaphore_list_zone, M_WAITOK);
231 	ms->ms_value = value;
232 	ms->ms_policy = policy;
233 	TAILQ_INIT(&ms->ms_waiting);
234@@ -241,7 +243,7 @@ mach_semaphore_put(struct mach_semaphore *ms)
235 	LIST_REMOVE(ms, ms_list);
236 	rw_exit(&mach_semaphore_list_lock);
237
238-	pool_put(&mach_semaphore_list_pool, ms);
239+	uma_zfree(mach_semaphore_list_zone, ms);
240
241 	return;
242 }
243@@ -251,8 +253,7 @@ mach_waiting_lwp_get(struct thread *td, struct mach_semaphore *ms)
244 {
245 	struct mach_waiting_lwp *mwl;
246
247-	mwl = (struct mach_waiting_lwp *)pool_get(&mach_waiting_lwp_pool,
248-	    M_WAITOK);
249+	mwl = uma_zalloc(mach_waiting_lwp_zone, M_WAITOK);
250 	mwl->mwl_l = l;
251
252 	rw_enter(&ms->ms_lock, RW_WRITER);
253@@ -270,7 +271,7 @@ mach_waiting_lwp_put(struct mach_waiting_lwp *mwl, struct mach_semaphore *ms, in
254 	TAILQ_REMOVE(&ms->ms_waiting, mwl, mwl_list);
255 	if (!locked)
256 		rw_exit(&ms->ms_lock);
257-	pool_put(&mach_waiting_lwp_pool, mwl);
258+	uma_zfree(mach_waiting_lwp_zone, mwl);
259
260 	return;
261 }
262--
2631.8.4.2
264
265