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 194454 2009-06-18 17:59:04Z alc $"); |
30 31#include "opt_param.h" 32 33#include <sys/param.h> 34#include <sys/malloc.h> 35#include <sys/systm.h> 36#include <sys/mbuf.h> 37#include <sys/domain.h> 38#include <sys/eventhandler.h> 39#include <sys/kernel.h> 40#include <sys/protosw.h> 41#include <sys/smp.h> 42#include <sys/sysctl.h> 43 44#include <security/mac/mac_framework.h> 45 46#include <vm/vm.h> |
47#include <vm/vm_extern.h> 48#include <vm/vm_kern.h> |
49#include <vm/vm_page.h> 50#include <vm/uma.h> 51#include <vm/uma_int.h> 52#include <vm/uma_dbg.h> 53 54/* 55 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA 56 * Zones. --- 172 unchanged lines hidden (view full) --- 229static void mb_dtor_clust(void *, int, void *); 230static void mb_dtor_pack(void *, int, void *); 231static int mb_zinit_pack(void *, int, int); 232static void mb_zfini_pack(void *, int); 233 234static void mb_reclaim(void *); 235static void mbuf_init(void *); 236static void *mbuf_jumbo_alloc(uma_zone_t, int, u_int8_t *, int); |
237 |
238/* Ensure that MSIZE doesn't break dtom() - it must be a power of 2 */ 239CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE); 240 241/* 242 * Initialize FreeBSD Network buffer allocation. 243 */ 244SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL); 245static void --- 44 unchanged lines hidden (view full) --- 290 trash_init, trash_fini, 291#else 292 NULL, NULL, 293#endif 294 UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 295 if (nmbjumbo9 > 0) 296 uma_zone_set_max(zone_jumbo9, nmbjumbo9); 297 uma_zone_set_allocf(zone_jumbo9, mbuf_jumbo_alloc); |
298 299 zone_jumbo16 = uma_zcreate(MBUF_JUMBO16_MEM_NAME, MJUM16BYTES, 300 mb_ctor_clust, mb_dtor_clust, 301#ifdef INVARIANTS 302 trash_init, trash_fini, 303#else 304 NULL, NULL, 305#endif 306 UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 307 if (nmbjumbo16 > 0) 308 uma_zone_set_max(zone_jumbo16, nmbjumbo16); 309 uma_zone_set_allocf(zone_jumbo16, mbuf_jumbo_alloc); |
310 311 zone_ext_refcnt = uma_zcreate(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int), 312 NULL, NULL, 313 NULL, NULL, 314 UMA_ALIGN_PTR, UMA_ZONE_ZINIT); 315 316 /* uma_prealloc() goes here... */ 317 --- 32 unchanged lines hidden (view full) --- 350 * pages. 351 */ 352static void * 353mbuf_jumbo_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait) 354{ 355 356 /* Inform UMA that this allocator uses kernel_map/object. */ 357 *flags = UMA_SLAB_KERNEL; |
358 return ((void *)kmem_alloc_contig(kernel_map, bytes, wait, 359 (vm_paddr_t)0, ~(vm_paddr_t)0, 1, 0)); |
360} 361 362/* |
363 * Constructor for Mbuf master zone. 364 * 365 * The 'arg' pointer points to a mb_args structure which 366 * contains call-specific information required to support the 367 * mbuf allocation API. See mbuf.h. 368 */ 369static int 370mb_ctor_mbuf(void *mem, int size, void *arg, int how) --- 298 unchanged lines hidden --- |