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
9 * notice unmodified, this list of conditions and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
--- 9 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 243639 2012-11-27 23:16:56Z andre $");
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>
--- 33 unchanged lines hidden (view full) ---
71 * m_clget() m_getcl()
72 * | |
73 * | .------------>[(Packet Cache)] m_get(), m_gethdr()
74 * | | [ Packet ] |
75 * [(Cluster Cache)] [ Secondary ] [ (Mbuf Cache) ]
76 * [ Cluster Zone ] [ Zone ] [ Mbuf Master Zone ]
77 * | \________ |
78 * [ Cluster Keg ] \ /
79 * | [ Mbuf Keg ]
80 * [ Cluster Slabs ] |
81 * | [ Mbuf Slabs ]
82 * \____________(VM)_________________/
83 *
84 *
85 * Whenever an object is allocated with uma_zalloc() out of
86 * one of the Zones its _ctor_ function is executed. The same
87 * for any deallocation through uma_zfree() the _dtor_ function
--- 55 unchanged lines hidden (view full) ---
143SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
144
145static int
146sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
147{
148 int error, newnmbclusters;
149
150 newnmbclusters = nmbclusters;
151 error = sysctl_handle_int(oidp, &newnmbclusters, 0, req);
152 if (error == 0 && req->newptr) {
153 if (newnmbclusters > nmbclusters &&
154 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
155 nmbclusters = newnmbclusters;
156 uma_zone_set_max(zone_clust, nmbclusters);
157 nmbclusters = uma_zone_get_max(zone_clust);
158 EVENTHANDLER_INVOKE(nmbclusters_change);
159 } else
--- 6 unchanged lines hidden (view full) ---
166 "Maximum number of mbuf clusters allowed");
167
168static int
169sysctl_nmbjumbop(SYSCTL_HANDLER_ARGS)
170{
171 int error, newnmbjumbop;
172
173 newnmbjumbop = nmbjumbop;
174 error = sysctl_handle_int(oidp, &newnmbjumbop, 0, req);
175 if (error == 0 && req->newptr) {
176 if (newnmbjumbop > nmbjumbop &&
177 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
178 nmbjumbop = newnmbjumbop;
179 uma_zone_set_max(zone_jumbop, nmbjumbop);
180 nmbjumbop = uma_zone_get_max(zone_jumbop);
181 } else
182 error = EINVAL;
183 }
184 return (error);
185}
186SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbop, CTLTYPE_INT|CTLFLAG_RW,
187&nmbjumbop, 0, sysctl_nmbjumbop, "IU",
188 "Maximum number of mbuf page size jumbo clusters allowed");
189
190
191static int
192sysctl_nmbjumbo9(SYSCTL_HANDLER_ARGS)
193{
194 int error, newnmbjumbo9;
195
196 newnmbjumbo9 = nmbjumbo9;
197 error = sysctl_handle_int(oidp, &newnmbjumbo9, 0, req);
198 if (error == 0 && req->newptr) {
199 if (newnmbjumbo9 > nmbjumbo9&&
200 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
201 nmbjumbo9 = newnmbjumbo9;
202 uma_zone_set_max(zone_jumbo9, nmbjumbo9);
203 nmbjumbo9 = uma_zone_get_max(zone_jumbo9);
204 } else
205 error = EINVAL;
206 }
207 return (error);
208}
209SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbo9, CTLTYPE_INT|CTLFLAG_RW,
210&nmbjumbo9, 0, sysctl_nmbjumbo9, "IU",
211 "Maximum number of mbuf 9k jumbo clusters allowed");
212
213static int
214sysctl_nmbjumbo16(SYSCTL_HANDLER_ARGS)
215{
216 int error, newnmbjumbo16;
217
218 newnmbjumbo16 = nmbjumbo16;
219 error = sysctl_handle_int(oidp, &newnmbjumbo16, 0, req);
220 if (error == 0 && req->newptr) {
221 if (newnmbjumbo16 > nmbjumbo16 &&
222 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
223 nmbjumbo16 = newnmbjumbo16;
224 uma_zone_set_max(zone_jumbo16, nmbjumbo16);
225 nmbjumbo16 = uma_zone_get_max(zone_jumbo16);
226 } else
227 error = EINVAL;
--- 5 unchanged lines hidden (view full) ---
233 "Maximum number of mbuf 16k jumbo clusters allowed");
234
235static int
236sysctl_nmbufs(SYSCTL_HANDLER_ARGS)
237{
238 int error, newnmbufs;
239
240 newnmbufs = nmbufs;
241 error = sysctl_handle_int(oidp, &newnmbufs, 0, req);
242 if (error == 0 && req->newptr) {
243 if (newnmbufs > nmbufs) {
244 nmbufs = newnmbufs;
245 uma_zone_set_max(zone_mbuf, nmbufs);
246 nmbufs = uma_zone_get_max(zone_mbuf);
247 EVENTHANDLER_INVOKE(nmbufs_change);
248 } else
249 error = EINVAL;
250 }
251 return (error);
252}
253SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbuf, CTLTYPE_INT|CTLFLAG_RW,
254&nmbufs, 0, sysctl_nmbufs, "IU",
255 "Maximum number of mbufs allowed");
256
257
258SYSCTL_STRUCT(_kern_ipc, OID_AUTO, mbstat, CTLFLAG_RD, &mbstat, mbstat,
259 "Mbuf general information and statistics");
260
261/*
262 * Zones from which we allocate.
263 */
264uma_zone_t zone_mbuf;
265uma_zone_t zone_clust;
--- 217 unchanged lines hidden (view full) ---
483
484/*
485 * The Mbuf master zone destructor.
486 */
487static void
488mb_dtor_mbuf(void *mem, int size, void *arg)
489{
490 struct mbuf *m;
491 unsigned long flags;
492
493 m = (struct mbuf *)mem;
494 flags = (unsigned long)arg;
495
496 if ((flags & MB_NOTAGS) == 0 && (m->m_flags & M_PKTHDR) != 0)
497 m_tag_delete_chain(m, NULL);
498 KASSERT((m->m_flags & M_EXT) == 0, ("%s: M_EXT set", __func__));
499 KASSERT((m->m_flags & M_NOFREE) == 0, ("%s: M_NOFREE set", __func__));
--- 257 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
9 * notice unmodified, this list of conditions and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
--- 9 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 243639 2012-11-27 23:16:56Z andre $");
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>
--- 33 unchanged lines hidden (view full) ---
71 * m_clget() m_getcl()
72 * | |
73 * | .------------>[(Packet Cache)] m_get(), m_gethdr()
74 * | | [ Packet ] |
75 * [(Cluster Cache)] [ Secondary ] [ (Mbuf Cache) ]
76 * [ Cluster Zone ] [ Zone ] [ Mbuf Master Zone ]
77 * | \________ |
78 * [ Cluster Keg ] \ /
79 * | [ Mbuf Keg ]
80 * [ Cluster Slabs ] |
81 * | [ Mbuf Slabs ]
82 * \____________(VM)_________________/
83 *
84 *
85 * Whenever an object is allocated with uma_zalloc() out of
86 * one of the Zones its _ctor_ function is executed. The same
87 * for any deallocation through uma_zfree() the _dtor_ function
--- 55 unchanged lines hidden (view full) ---
143SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
144
145static int
146sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
147{
148 int error, newnmbclusters;
149
150 newnmbclusters = nmbclusters;
151 error = sysctl_handle_int(oidp, &newnmbclusters, 0, req);
152 if (error == 0 && req->newptr) {
153 if (newnmbclusters > nmbclusters &&
154 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
155 nmbclusters = newnmbclusters;
156 uma_zone_set_max(zone_clust, nmbclusters);
157 nmbclusters = uma_zone_get_max(zone_clust);
158 EVENTHANDLER_INVOKE(nmbclusters_change);
159 } else
--- 6 unchanged lines hidden (view full) ---
166 "Maximum number of mbuf clusters allowed");
167
168static int
169sysctl_nmbjumbop(SYSCTL_HANDLER_ARGS)
170{
171 int error, newnmbjumbop;
172
173 newnmbjumbop = nmbjumbop;
174 error = sysctl_handle_int(oidp, &newnmbjumbop, 0, req);
175 if (error == 0 && req->newptr) {
176 if (newnmbjumbop > nmbjumbop &&
177 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
178 nmbjumbop = newnmbjumbop;
179 uma_zone_set_max(zone_jumbop, nmbjumbop);
180 nmbjumbop = uma_zone_get_max(zone_jumbop);
181 } else
182 error = EINVAL;
183 }
184 return (error);
185}
186SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbop, CTLTYPE_INT|CTLFLAG_RW,
187&nmbjumbop, 0, sysctl_nmbjumbop, "IU",
188 "Maximum number of mbuf page size jumbo clusters allowed");
189
190
191static int
192sysctl_nmbjumbo9(SYSCTL_HANDLER_ARGS)
193{
194 int error, newnmbjumbo9;
195
196 newnmbjumbo9 = nmbjumbo9;
197 error = sysctl_handle_int(oidp, &newnmbjumbo9, 0, req);
198 if (error == 0 && req->newptr) {
199 if (newnmbjumbo9 > nmbjumbo9&&
200 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
201 nmbjumbo9 = newnmbjumbo9;
202 uma_zone_set_max(zone_jumbo9, nmbjumbo9);
203 nmbjumbo9 = uma_zone_get_max(zone_jumbo9);
204 } else
205 error = EINVAL;
206 }
207 return (error);
208}
209SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbo9, CTLTYPE_INT|CTLFLAG_RW,
210&nmbjumbo9, 0, sysctl_nmbjumbo9, "IU",
211 "Maximum number of mbuf 9k jumbo clusters allowed");
212
213static int
214sysctl_nmbjumbo16(SYSCTL_HANDLER_ARGS)
215{
216 int error, newnmbjumbo16;
217
218 newnmbjumbo16 = nmbjumbo16;
219 error = sysctl_handle_int(oidp, &newnmbjumbo16, 0, req);
220 if (error == 0 && req->newptr) {
221 if (newnmbjumbo16 > nmbjumbo16 &&
222 nmbufs >= nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16) {
223 nmbjumbo16 = newnmbjumbo16;
224 uma_zone_set_max(zone_jumbo16, nmbjumbo16);
225 nmbjumbo16 = uma_zone_get_max(zone_jumbo16);
226 } else
227 error = EINVAL;
--- 5 unchanged lines hidden (view full) ---
233 "Maximum number of mbuf 16k jumbo clusters allowed");
234
235static int
236sysctl_nmbufs(SYSCTL_HANDLER_ARGS)
237{
238 int error, newnmbufs;
239
240 newnmbufs = nmbufs;
241 error = sysctl_handle_int(oidp, &newnmbufs, 0, req);
242 if (error == 0 && req->newptr) {
243 if (newnmbufs > nmbufs) {
244 nmbufs = newnmbufs;
245 uma_zone_set_max(zone_mbuf, nmbufs);
246 nmbufs = uma_zone_get_max(zone_mbuf);
247 EVENTHANDLER_INVOKE(nmbufs_change);
248 } else
249 error = EINVAL;
250 }
251 return (error);
252}
253SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbuf, CTLTYPE_INT|CTLFLAG_RW,
254&nmbufs, 0, sysctl_nmbufs, "IU",
255 "Maximum number of mbufs allowed");
256
257
258SYSCTL_STRUCT(_kern_ipc, OID_AUTO, mbstat, CTLFLAG_RD, &mbstat, mbstat,
259 "Mbuf general information and statistics");
260
261/*
262 * Zones from which we allocate.
263 */
264uma_zone_t zone_mbuf;
265uma_zone_t zone_clust;
--- 217 unchanged lines hidden (view full) ---
483
484/*
485 * The Mbuf master zone destructor.
486 */
487static void
488mb_dtor_mbuf(void *mem, int size, void *arg)
489{
490 struct mbuf *m;
491 unsigned long flags;
492
493 m = (struct mbuf *)mem;
494 flags = (unsigned long)arg;
495
496 if ((flags & MB_NOTAGS) == 0 && (m->m_flags & M_PKTHDR) != 0)
497 m_tag_delete_chain(m, NULL);
498 KASSERT((m->m_flags & M_EXT) == 0, ("%s: M_EXT set", __func__));
499 KASSERT((m->m_flags & M_NOFREE) == 0, ("%s: M_NOFREE set", __func__));
--- 257 unchanged lines hidden ---