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 243999 2012-12-07 22:30:30Z pjd $");
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>
--- 4 unchanged lines hidden (view full) ---
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.
57 *
--- 41 unchanged lines hidden (view full) ---
99int nmbufs; /* limits number of mbufs */
100int nmbclusters; /* limits number of mbuf clusters */
101int nmbjumbop; /* limits number of page size jumbo clusters */
102int nmbjumbo9; /* limits number of 9k jumbo clusters */
103int nmbjumbo16; /* limits number of 16k jumbo clusters */
104struct mbstat mbstat;
105
106/*
107 * tunable_mbinit() has to be run before init_maxsockets() thus
108 * the SYSINIT order below is SI_ORDER_MIDDLE while init_maxsockets()
109 * runs at SI_ORDER_ANY.
110 *
111 * NB: This has to be done before VM init.
112 */
113static void
114tunable_mbinit(void *dummy)
115{
116
117 TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
118 if (nmbclusters == 0)
119 nmbclusters = maxmbufmem / MCLBYTES / 4;
120
121 TUNABLE_INT_FETCH("kern.ipc.nmbjumbop", &nmbjumbop);
122 if (nmbjumbop == 0)
123 nmbjumbop = maxmbufmem / MJUMPAGESIZE / 4;
124
--- 9 unchanged lines hidden (view full) ---
134 * We need at least as many mbufs as we have clusters of
135 * the various types added together.
136 */
137 TUNABLE_INT_FETCH("kern.ipc.nmbufs", &nmbufs);
138 if (nmbufs < nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16)
139 nmbufs = lmax(maxmbufmem / MSIZE / 5,
140 nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16);
141}
142SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
143
144static int
145sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
146{
147 int error, newnmbclusters;
148
149 newnmbclusters = nmbclusters;
150 error = sysctl_handle_int(oidp, &newnmbclusters, 0, req);
--- 123 unchanged lines hidden (view full) ---
274static int mb_ctor_pack(void *, int, void *, int);
275static void mb_dtor_mbuf(void *, int, void *);
276static void mb_dtor_clust(void *, int, void *);
277static void mb_dtor_pack(void *, int, void *);
278static int mb_zinit_pack(void *, int, int);
279static void mb_zfini_pack(void *, int);
280
281static void mb_reclaim(void *);
282static void mbuf_init(void *);
283static void *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int);
284
285/* Ensure that MSIZE must be a power of 2. */
286CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE);
287
288/*
289 * Initialize FreeBSD Network buffer allocation.
290 */
291SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL);
292static void
293mbuf_init(void *dummy)
294{
295
296 /*
297 * Configure UMA zones for Mbufs, Clusters, and Packets.
298 */
299 zone_mbuf = uma_zcreate(MBUF_MEM_NAME, MSIZE,
--- 91 unchanged lines hidden (view full) ---
391 mbstat.m_mlen = MLEN;
392 mbstat.m_mhlen = MHLEN;
393 mbstat.m_numtypes = MT_NTYPES;
394
395 mbstat.m_mcfail = mbstat.m_mpfail = 0;
396 mbstat.sf_iocnt = 0;
397 mbstat.sf_allocwait = mbstat.sf_allocfail = 0;
398}
399
400/*
401 * UMA backend page allocator for the jumbo frame zones.
402 *
403 * Allocates kernel virtual memory that is backed by contiguous physical
404 * pages.
405 */
406static void *
--- 342 unchanged lines hidden ---
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 243999 2012-12-07 22:30:30Z pjd $");
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>
--- 4 unchanged lines hidden (view full) ---
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.
57 *
--- 41 unchanged lines hidden (view full) ---
99int nmbufs; /* limits number of mbufs */
100int nmbclusters; /* limits number of mbuf clusters */
101int nmbjumbop; /* limits number of page size jumbo clusters */
102int nmbjumbo9; /* limits number of 9k jumbo clusters */
103int nmbjumbo16; /* limits number of 16k jumbo clusters */
104struct mbstat mbstat;
105
106/*
107 * tunable_mbinit() has to be run before init_maxsockets() thus
108 * the SYSINIT order below is SI_ORDER_MIDDLE while init_maxsockets()
109 * runs at SI_ORDER_ANY.
110 *
111 * NB: This has to be done before VM init.
112 */
113static void
114tunable_mbinit(void *dummy)
115{
116
117 TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
118 if (nmbclusters == 0)
119 nmbclusters = maxmbufmem / MCLBYTES / 4;
120
121 TUNABLE_INT_FETCH("kern.ipc.nmbjumbop", &nmbjumbop);
122 if (nmbjumbop == 0)
123 nmbjumbop = maxmbufmem / MJUMPAGESIZE / 4;
124
--- 9 unchanged lines hidden (view full) ---
134 * We need at least as many mbufs as we have clusters of
135 * the various types added together.
136 */
137 TUNABLE_INT_FETCH("kern.ipc.nmbufs", &nmbufs);
138 if (nmbufs < nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16)
139 nmbufs = lmax(maxmbufmem / MSIZE / 5,
140 nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16);
141}
142SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
143
144static int
145sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
146{
147 int error, newnmbclusters;
148
149 newnmbclusters = nmbclusters;
150 error = sysctl_handle_int(oidp, &newnmbclusters, 0, req);
--- 123 unchanged lines hidden (view full) ---
274static int mb_ctor_pack(void *, int, void *, int);
275static void mb_dtor_mbuf(void *, int, void *);
276static void mb_dtor_clust(void *, int, void *);
277static void mb_dtor_pack(void *, int, void *);
278static int mb_zinit_pack(void *, int, int);
279static void mb_zfini_pack(void *, int);
280
281static void mb_reclaim(void *);
282static void mbuf_init(void *);
283static void *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int);
284
285/* Ensure that MSIZE must be a power of 2. */
286CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE);
287
288/*
289 * Initialize FreeBSD Network buffer allocation.
290 */
291SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL);
292static void
293mbuf_init(void *dummy)
294{
295
296 /*
297 * Configure UMA zones for Mbufs, Clusters, and Packets.
298 */
299 zone_mbuf = uma_zcreate(MBUF_MEM_NAME, MSIZE,
--- 91 unchanged lines hidden (view full) ---
391 mbstat.m_mlen = MLEN;
392 mbstat.m_mhlen = MHLEN;
393 mbstat.m_numtypes = MT_NTYPES;
394
395 mbstat.m_mcfail = mbstat.m_mpfail = 0;
396 mbstat.sf_iocnt = 0;
397 mbstat.sf_allocwait = mbstat.sf_allocfail = 0;
398}
399
400/*
401 * UMA backend page allocator for the jumbo frame zones.
402 *
403 * Allocates kernel virtual memory that is backed by contiguous physical
404 * pages.
405 */
406static void *
--- 342 unchanged lines hidden ---