kern_mbuf.c (193511) | kern_mbuf.c (194454) |
---|---|
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 193511 2009-06-05 14:55:22Z rwatson $"); | 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> | 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> |
|
47#include <vm/vm_page.h> 48#include <vm/uma.h> 49#include <vm/uma_int.h> 50#include <vm/uma_dbg.h> 51 52/* 53 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA 54 * Zones. --- 172 unchanged lines hidden (view full) --- 227static void mb_dtor_clust(void *, int, void *); 228static void mb_dtor_pack(void *, int, void *); 229static int mb_zinit_pack(void *, int, int); 230static void mb_zfini_pack(void *, int); 231 232static void mb_reclaim(void *); 233static void mbuf_init(void *); 234static void *mbuf_jumbo_alloc(uma_zone_t, int, u_int8_t *, int); | 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); |
235static void mbuf_jumbo_free(void *, int, u_int8_t); | |
236 | 237 |
237static MALLOC_DEFINE(M_JUMBOFRAME, "jumboframes", "mbuf jumbo frame buffers"); 238 | |
239/* Ensure that MSIZE doesn't break dtom() - it must be a power of 2 */ 240CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE); 241 242/* 243 * Initialize FreeBSD Network buffer allocation. 244 */ 245SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL); 246static void --- 44 unchanged lines hidden (view full) --- 291 trash_init, trash_fini, 292#else 293 NULL, NULL, 294#endif 295 UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 296 if (nmbjumbo9 > 0) 297 uma_zone_set_max(zone_jumbo9, nmbjumbo9); 298 uma_zone_set_allocf(zone_jumbo9, mbuf_jumbo_alloc); | 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); |
299 uma_zone_set_freef(zone_jumbo9, mbuf_jumbo_free); | |
300 301 zone_jumbo16 = uma_zcreate(MBUF_JUMBO16_MEM_NAME, MJUM16BYTES, 302 mb_ctor_clust, mb_dtor_clust, 303#ifdef INVARIANTS 304 trash_init, trash_fini, 305#else 306 NULL, NULL, 307#endif 308 UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 309 if (nmbjumbo16 > 0) 310 uma_zone_set_max(zone_jumbo16, nmbjumbo16); 311 uma_zone_set_allocf(zone_jumbo16, 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); |
312 uma_zone_set_freef(zone_jumbo16, mbuf_jumbo_free); | |
313 314 zone_ext_refcnt = uma_zcreate(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int), 315 NULL, NULL, 316 NULL, NULL, 317 UMA_ALIGN_PTR, UMA_ZONE_ZINIT); 318 319 /* uma_prealloc() goes here... */ 320 --- 32 unchanged lines hidden (view full) --- 353 * pages. 354 */ 355static void * 356mbuf_jumbo_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait) 357{ 358 359 /* Inform UMA that this allocator uses kernel_map/object. */ 360 *flags = UMA_SLAB_KERNEL; | 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; |
361 return (contigmalloc(bytes, M_JUMBOFRAME, wait, (vm_paddr_t)0, 362 ~(vm_paddr_t)0, 1, 0)); | 358 return ((void *)kmem_alloc_contig(kernel_map, bytes, wait, 359 (vm_paddr_t)0, ~(vm_paddr_t)0, 1, 0)); |
363} 364 365/* | 360} 361 362/* |
366 * UMA backend page deallocator for the jumbo frame zones. 367 */ 368static void 369mbuf_jumbo_free(void *mem, int size, u_int8_t flags) 370{ 371 372 contigfree(mem, size, M_JUMBOFRAME); 373} 374 375/* | |
376 * Constructor for Mbuf master zone. 377 * 378 * The 'arg' pointer points to a mb_args structure which 379 * contains call-specific information required to support the 380 * mbuf allocation API. See mbuf.h. 381 */ 382static int 383mb_ctor_mbuf(void *mem, int size, void *arg, int how) --- 298 unchanged lines hidden --- | 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 --- |