Deleted Added
full compact
kern_mbuf.c (141991) kern_mbuf.c (147537)
1/*-
2 * Copyright (c) 2004, 2005,
3 * Bosko Milekic <bmilekic@FreeBSD.org>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004, 2005,
3 * Bosko Milekic <bmilekic@FreeBSD.org>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/kern/kern_mbuf.c 141991 2005-02-16 21:45:59Z bmilekic $");
29__FBSDID("$FreeBSD: head/sys/kern/kern_mbuf.c 147537 2005-06-23 04:33:39Z silby $");
30
31#include "opt_mac.h"
32#include "opt_param.h"
33
34#include <sys/param.h>
35#include <sys/mac.h>
36#include <sys/malloc.h>
37#include <sys/systm.h>
38#include <sys/mbuf.h>
39#include <sys/domain.h>
40#include <sys/eventhandler.h>
41#include <sys/kernel.h>
42#include <sys/protosw.h>
43#include <sys/smp.h>
44#include <sys/sysctl.h>
45
46#include <vm/vm.h>
47#include <vm/vm_page.h>
48#include <vm/uma.h>
30
31#include "opt_mac.h"
32#include "opt_param.h"
33
34#include <sys/param.h>
35#include <sys/mac.h>
36#include <sys/malloc.h>
37#include <sys/systm.h>
38#include <sys/mbuf.h>
39#include <sys/domain.h>
40#include <sys/eventhandler.h>
41#include <sys/kernel.h>
42#include <sys/protosw.h>
43#include <sys/smp.h>
44#include <sys/sysctl.h>
45
46#include <vm/vm.h>
47#include <vm/vm_page.h>
48#include <vm/uma.h>
49#include <vm/uma_int.h>
50#include <vm/uma_dbg.h>
49
50/*
51 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA
52 * Zones.
53 *
54 * Mbuf Clusters (2K, contiguous) are allocated from the Cluster
55 * Zone. The Zone can be capped at kern.ipc.nmbclusters, if the
56 * administrator so desires.

--- 72 unchanged lines hidden (view full) ---

129static void
130mbuf_init(void *dummy)
131{
132
133 /*
134 * Configure UMA zones for Mbufs, Clusters, and Packets.
135 */
136 zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf,
51
52/*
53 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA
54 * Zones.
55 *
56 * Mbuf Clusters (2K, contiguous) are allocated from the Cluster
57 * Zone. The Zone can be capped at kern.ipc.nmbclusters, if the
58 * administrator so desires.

--- 72 unchanged lines hidden (view full) ---

131static void
132mbuf_init(void *dummy)
133{
134
135 /*
136 * Configure UMA zones for Mbufs, Clusters, and Packets.
137 */
138 zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf,
139#ifdef INVARIANTS
140 trash_init, trash_fini, MSIZE - 1, UMA_ZONE_MAXBUCKET);
141#else
137 NULL, NULL, MSIZE - 1, UMA_ZONE_MAXBUCKET);
142 NULL, NULL, MSIZE - 1, UMA_ZONE_MAXBUCKET);
143#endif
138 zone_clust = uma_zcreate("MbufClust", MCLBYTES, mb_ctor_clust,
144 zone_clust = uma_zcreate("MbufClust", MCLBYTES, mb_ctor_clust,
145#ifdef INVARIANTS
146 mb_dtor_clust, trash_init, trash_fini, UMA_ALIGN_PTR, UMA_ZONE_REFCNT);
147#else
139 mb_dtor_clust, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_REFCNT);
148 mb_dtor_clust, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_REFCNT);
149#endif
140 if (nmbclusters > 0)
141 uma_zone_set_max(zone_clust, nmbclusters);
142 zone_pack = uma_zsecond_create("Packet", mb_ctor_pack, mb_dtor_pack,
143 mb_init_pack, mb_fini_pack, zone_mbuf);
144
145 /* uma_prealloc() goes here */
146
147 /*

--- 37 unchanged lines hidden (view full) ---

185 struct mbuf *m;
186 struct mb_args *args;
187#ifdef MAC
188 int error;
189#endif
190 int flags;
191 short type;
192
150 if (nmbclusters > 0)
151 uma_zone_set_max(zone_clust, nmbclusters);
152 zone_pack = uma_zsecond_create("Packet", mb_ctor_pack, mb_dtor_pack,
153 mb_init_pack, mb_fini_pack, zone_mbuf);
154
155 /* uma_prealloc() goes here */
156
157 /*

--- 37 unchanged lines hidden (view full) ---

195 struct mbuf *m;
196 struct mb_args *args;
197#ifdef MAC
198 int error;
199#endif
200 int flags;
201 short type;
202
203#ifdef INVARIANTS
204 trash_ctor(mem, size, arg, how);
205#endif
193 m = (struct mbuf *)mem;
194 args = (struct mb_args *)arg;
195 flags = args->flags;
196 type = args->type;
197
198 m->m_type = type;
199 m->m_next = NULL;
200 m->m_nextpkt = NULL;

--- 21 unchanged lines hidden (view full) ---

222static void
223mb_dtor_mbuf(void *mem, int size, void *arg)
224{
225 struct mbuf *m;
226
227 m = (struct mbuf *)mem;
228 if ((m->m_flags & M_PKTHDR) != 0)
229 m_tag_delete_chain(m, NULL);
206 m = (struct mbuf *)mem;
207 args = (struct mb_args *)arg;
208 flags = args->flags;
209 type = args->type;
210
211 m->m_type = type;
212 m->m_next = NULL;
213 m->m_nextpkt = NULL;

--- 21 unchanged lines hidden (view full) ---

235static void
236mb_dtor_mbuf(void *mem, int size, void *arg)
237{
238 struct mbuf *m;
239
240 m = (struct mbuf *)mem;
241 if ((m->m_flags & M_PKTHDR) != 0)
242 m_tag_delete_chain(m, NULL);
243#ifdef INVARIANTS
244 trash_dtor(mem, size, arg);
245#endif
230 mbstat.m_mbufs -= 1; /* XXX */
231}
232
233/* XXX Only because of stats */
234static void
235mb_dtor_pack(void *mem, int size, void *arg)
236{
237 struct mbuf *m;
238
239 m = (struct mbuf *)mem;
240 if ((m->m_flags & M_PKTHDR) != 0)
241 m_tag_delete_chain(m, NULL);
246 mbstat.m_mbufs -= 1; /* XXX */
247}
248
249/* XXX Only because of stats */
250static void
251mb_dtor_pack(void *mem, int size, void *arg)
252{
253 struct mbuf *m;
254
255 m = (struct mbuf *)mem;
256 if ((m->m_flags & M_PKTHDR) != 0)
257 m_tag_delete_chain(m, NULL);
258#ifdef INVARIANTS
259 trash_dtor(m->m_ext.ext_buf, MCLBYTES, arg);
260#endif
242 mbstat.m_mbufs -= 1; /* XXX */
243 mbstat.m_mclusts -= 1; /* XXX */
244}
245
246/*
247 * The Cluster zone constructor.
248 *
249 * Here the 'arg' pointer points to the Mbuf which we
250 * are configuring cluster storage for.
251 */
252static int
253mb_ctor_clust(void *mem, int size, void *arg, int how)
254{
255 struct mbuf *m;
256
261 mbstat.m_mbufs -= 1; /* XXX */
262 mbstat.m_mclusts -= 1; /* XXX */
263}
264
265/*
266 * The Cluster zone constructor.
267 *
268 * Here the 'arg' pointer points to the Mbuf which we
269 * are configuring cluster storage for.
270 */
271static int
272mb_ctor_clust(void *mem, int size, void *arg, int how)
273{
274 struct mbuf *m;
275
276#ifdef INVARIANTS
277 trash_ctor(mem, size, arg, how);
278#endif
257 m = (struct mbuf *)arg;
258 m->m_ext.ext_buf = (caddr_t)mem;
259 m->m_data = m->m_ext.ext_buf;
260 m->m_flags |= M_EXT;
261 m->m_ext.ext_free = NULL;
262 m->m_ext.ext_args = NULL;
263 m->m_ext.ext_size = MCLBYTES;
264 m->m_ext.ext_type = EXT_CLUSTER;
265 m->m_ext.ref_cnt = NULL; /* Lazy counter assign. */
266 mbstat.m_mclusts += 1; /* XXX */
267 return (0);
268}
269
270/* XXX */
271static void
272mb_dtor_clust(void *mem, int size, void *arg)
273{
279 m = (struct mbuf *)arg;
280 m->m_ext.ext_buf = (caddr_t)mem;
281 m->m_data = m->m_ext.ext_buf;
282 m->m_flags |= M_EXT;
283 m->m_ext.ext_free = NULL;
284 m->m_ext.ext_args = NULL;
285 m->m_ext.ext_size = MCLBYTES;
286 m->m_ext.ext_type = EXT_CLUSTER;
287 m->m_ext.ref_cnt = NULL; /* Lazy counter assign. */
288 mbstat.m_mclusts += 1; /* XXX */
289 return (0);
290}
291
292/* XXX */
293static void
294mb_dtor_clust(void *mem, int size, void *arg)
295{
296#ifdef INVARIANTS
297 trash_dtor(mem, size, arg);
298#endif
274 mbstat.m_mclusts -= 1; /* XXX */
275}
276
277/*
278 * The Packet secondary zone's init routine, executed on the
279 * object's transition from keg slab to zone cache.
280 */
281static int
282mb_init_pack(void *mem, int size, int how)
283{
284 struct mbuf *m;
285
286 m = (struct mbuf *)mem;
287 m->m_ext.ext_buf = NULL;
288 uma_zalloc_arg(zone_clust, m, how);
289 if (m->m_ext.ext_buf == NULL)
290 return (ENOMEM);
299 mbstat.m_mclusts -= 1; /* XXX */
300}
301
302/*
303 * The Packet secondary zone's init routine, executed on the
304 * object's transition from keg slab to zone cache.
305 */
306static int
307mb_init_pack(void *mem, int size, int how)
308{
309 struct mbuf *m;
310
311 m = (struct mbuf *)mem;
312 m->m_ext.ext_buf = NULL;
313 uma_zalloc_arg(zone_clust, m, how);
314 if (m->m_ext.ext_buf == NULL)
315 return (ENOMEM);
316#ifdef INVARIANTS
317 trash_init(m->m_ext.ext_buf, MCLBYTES, how);
318#endif
291 mbstat.m_mclusts -= 1; /* XXX */
292 return (0);
293}
294
295/*
296 * The Packet secondary zone's fini routine, executed on the
297 * object's transition from zone cache to keg slab.
298 */
299static void
300mb_fini_pack(void *mem, int size)
301{
302 struct mbuf *m;
303
304 m = (struct mbuf *)mem;
319 mbstat.m_mclusts -= 1; /* XXX */
320 return (0);
321}
322
323/*
324 * The Packet secondary zone's fini routine, executed on the
325 * object's transition from zone cache to keg slab.
326 */
327static void
328mb_fini_pack(void *mem, int size)
329{
330 struct mbuf *m;
331
332 m = (struct mbuf *)mem;
333#ifdef INVARIANTS
334 trash_fini(m->m_ext.ext_buf, MCLBYTES);
335#endif
305 uma_zfree_arg(zone_clust, m->m_ext.ext_buf, NULL);
306 m->m_ext.ext_buf = NULL;
307 mbstat.m_mclusts += 1; /* XXX */
308}
309
310/*
311 * The "packet" keg constructor.
312 */

--- 8 unchanged lines hidden (view full) ---

321 int flags;
322 short type;
323
324 m = (struct mbuf *)mem;
325 args = (struct mb_args *)arg;
326 flags = args->flags;
327 type = args->type;
328
336 uma_zfree_arg(zone_clust, m->m_ext.ext_buf, NULL);
337 m->m_ext.ext_buf = NULL;
338 mbstat.m_mclusts += 1; /* XXX */
339}
340
341/*
342 * The "packet" keg constructor.
343 */

--- 8 unchanged lines hidden (view full) ---

352 int flags;
353 short type;
354
355 m = (struct mbuf *)mem;
356 args = (struct mb_args *)arg;
357 flags = args->flags;
358 type = args->type;
359
360#ifdef INVARIANTS
361 trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how);
362#endif
329 m->m_type = type;
330 m->m_next = NULL;
331 m->m_nextpkt = NULL;
332 m->m_data = m->m_ext.ext_buf;
333 m->m_flags = flags|M_EXT;
334 m->m_ext.ext_free = NULL;
335 m->m_ext.ext_args = NULL;
336 m->m_ext.ext_size = MCLBYTES;

--- 41 unchanged lines hidden ---
363 m->m_type = type;
364 m->m_next = NULL;
365 m->m_nextpkt = NULL;
366 m->m_data = m->m_ext.ext_buf;
367 m->m_flags = flags|M_EXT;
368 m->m_ext.ext_free = NULL;
369 m->m_ext.ext_args = NULL;
370 m->m_ext.ext_size = MCLBYTES;

--- 41 unchanged lines hidden ---