Deleted Added
full compact
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 159481 2006-06-10 14:34:07Z rwatson $");
29__FBSDID("$FreeBSD: head/sys/kern/kern_mbuf.c 162377 2006-09-17 13:44:32Z andre $");
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>

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

145 */
146uma_zone_t zone_mbuf;
147uma_zone_t zone_clust;
148uma_zone_t zone_pack;
149uma_zone_t zone_jumbop;
150uma_zone_t zone_jumbo9;
151uma_zone_t zone_jumbo16;
152uma_zone_t zone_ext_refcnt;
153uma_zone_t zone_mtag_vlan;
153
154/*
155 * Local prototypes.
156 */
157static int mb_ctor_mbuf(void *, int, void *, int);
158static int mb_ctor_clust(void *, int, void *, int);
159static int mb_ctor_pack(void *, int, void *, int);
160static void mb_dtor_mbuf(void *, int, void *);
161static void mb_dtor_clust(void *, int, void *);
162static void mb_dtor_pack(void *, int, void *);
163static int mb_zinit_pack(void *, int, int);
164static void mb_zfini_pack(void *, int);
166static int mt_zinit_vlan(void *, int, int);
165
166static void mb_reclaim(void *);
167static void mbuf_init(void *);
168
169/* Ensure that MSIZE doesn't break dtom() - it must be a power of 2 */
170CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE);
171
172/*

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

237 if (nmbjumbo16 > 0)
238 uma_zone_set_max(zone_jumbo16, nmbjumbo16);
239
240 zone_ext_refcnt = uma_zcreate(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int),
241 NULL, NULL,
242 NULL, NULL,
243 UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
244
247 zone_mtag_vlan = uma_zcreate("mtag_vlan",
248 sizeof(struct m_tag) + sizeof(u_int),
249 NULL, NULL,
250 mt_zinit_vlan, NULL,
251 UMA_ALIGN_INT, 0);
252
245 /* uma_prealloc() goes here... */
246
247 /*
248 * Hook event handler for low-memory situation, used to
249 * drain protocols and push data back to the caches (UMA
250 * later pushes it back to VM).
251 */
252 EVENTHANDLER_REGISTER(vm_lowmem, mb_reclaim, NULL,

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

312 m->m_type = type;
313 if (flags & M_PKTHDR) {
314 m->m_data = m->m_pktdat;
315 m->m_pkthdr.rcvif = NULL;
316 m->m_pkthdr.len = 0;
317 m->m_pkthdr.header = NULL;
318 m->m_pkthdr.csum_flags = 0;
319 m->m_pkthdr.csum_data = 0;
320 m->m_pkthdr.tso_segsz = 0;
321 m->m_pkthdr.ether_vtag = 0;
322 SLIST_INIT(&m->m_pkthdr.tags);
323#ifdef MAC
324 /* If the label init fails, fail the alloc */
325 error = mac_init_mbuf(m, how);
326 if (error)
327 return (error);
328#endif
329 } else

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

512 m->m_type = type;
513
514 if (flags & M_PKTHDR) {
515 m->m_pkthdr.rcvif = NULL;
516 m->m_pkthdr.len = 0;
517 m->m_pkthdr.header = NULL;
518 m->m_pkthdr.csum_flags = 0;
519 m->m_pkthdr.csum_data = 0;
520 m->m_pkthdr.tso_segsz = 0;
521 m->m_pkthdr.ether_vtag = 0;
522 SLIST_INIT(&m->m_pkthdr.tags);
523#ifdef MAC
524 /* If the label init fails, fail the alloc */
525 error = mac_init_mbuf(m, how);
526 if (error)
527 return (error);
528#endif
529 }
530 /* m_ext is already initialized. */
531
532 return (0);
533}
534
539static void
540mt_vlan_free(struct m_tag *mtag)
541{
542 uma_zfree(zone_mtag_vlan, mtag);
543}
544
545static int
546mt_zinit_vlan(void *mem, int size, int how)
547{
548 struct m_tag *mtag = (struct m_tag *)mem;
549
550 m_tag_setup(mtag, MTAG_VLAN, MTAG_VLAN_TAG, sizeof(u_int));
551 mtag->m_tag_free = mt_vlan_free;
552
553 return (0);
554}
555
535/*
536 * This is the protocol drain routine.
537 *
538 * No locks should be held when this is called. The drain routines have to
539 * presently acquire some locks which raises the possibility of lock order
540 * reversal.
541 */
542static void

--- 13 unchanged lines hidden ---