1/*- 2 * Copyright (c) 2004 3 * Bosko Milekic <bmilekic@FreeBSD.org>. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice unmodified, this list of conditions and the following 11 * disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the author nor the names of contributors may be 16 * used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2004 3 * Bosko Milekic <bmilekic@FreeBSD.org>. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice unmodified, this list of conditions and the following 11 * disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the author nor the names of contributors may be 16 * used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h>
|
33__FBSDID("$FreeBSD: head/sys/kern/kern_mbuf.c 129906 2004-05-31 21:46:06Z bmilekic $");
| 33__FBSDID("$FreeBSD: head/sys/kern/kern_mbuf.c 129947 2004-06-01 16:17:10Z bmilekic $");
|
34 35#include "opt_mac.h" 36#include "opt_param.h" 37 38#include <sys/param.h> 39#include <sys/mac.h> 40#include <sys/malloc.h> 41#include <sys/systm.h> 42#include <sys/mbuf.h> 43#include <sys/domain.h> 44#include <sys/eventhandler.h> 45#include <sys/kernel.h> 46#include <sys/protosw.h> 47#include <sys/smp.h> 48#include <sys/sysctl.h> 49 50#include <vm/vm.h> 51#include <vm/vm_page.h> 52#include <vm/uma.h> 53 54/* 55 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA 56 * Zones. 57 * 58 * Mbuf Clusters (2K, contiguous) are allocated from the Cluster 59 * Zone. The Zone can be capped at kern.ipc.nmbclusters, if the 60 * administrator so desires. 61 * 62 * Mbufs are allocated from a UMA Master Zone called the Mbuf 63 * Zone. 64 * 65 * Additionally, FreeBSD provides a Packet Zone, which it 66 * configures as a Secondary Zone to the Mbuf Master Zone, 67 * thus sharing backend Slab kegs with the Mbuf Master Zone. 68 * 69 * Thus common-case allocations and locking are simplified: 70 * 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 85int nmbclusters; 86struct mbstat mbstat; 87 88static void 89tunable_mbinit(void *dummy) 90{ 91 92 /* This has to be done before VM init. */ 93 nmbclusters = 1024 + maxusers * 64; 94 TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters); 95} 96SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_ANY, tunable_mbinit, NULL); 97 98SYSCTL_DECL(_kern_ipc); 99SYSCTL_INT(_kern_ipc, OID_AUTO, nmbclusters, CTLFLAG_RW, &nmbclusters, 0, 100 "Maximum number of mbuf clusters allowed"); 101SYSCTL_STRUCT(_kern_ipc, OID_AUTO, mbstat, CTLFLAG_RD, &mbstat, mbstat, 102 "Mbuf general information and statistics"); 103 104/* 105 * Zones from which we allocate. 106 */ 107uma_zone_t zone_mbuf; 108uma_zone_t zone_clust; 109uma_zone_t zone_pack; 110 111/* 112 * Local prototypes. 113 */ 114static void mb_ctor_mbuf(void *, int, void *); 115static void mb_ctor_clust(void *, int, void *); 116static void mb_ctor_pack(void *, int, void *); 117static void mb_dtor_mbuf(void *, int, void *); 118static void mb_dtor_clust(void *, int, void *); /* XXX */ 119static void mb_dtor_pack(void *, int, void *); /* XXX */ 120static void mb_init_pack(void *, int); 121static void mb_fini_pack(void *, int); 122 123static void mb_reclaim(void *); 124static void mbuf_init(void *); 125 126/* 127 * Initialize FreeBSD Network buffer allocation. 128 */ 129SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL) 130static void 131mbuf_init(void *dummy) 132{ 133 134 /* 135 * Configure UMA zones for Mbufs, Clusters, and Packets. 136 */ 137 zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, 138 NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_MAXBUCKET); 139 zone_clust = uma_zcreate("MbufClust", MCLBYTES, mb_ctor_clust, 140 mb_dtor_clust, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 141 if (nmbclusters > 0) 142 uma_zone_set_max(zone_clust, nmbclusters); 143 zone_pack = uma_zsecond_create("Packet", mb_ctor_pack, mb_dtor_pack, 144 mb_init_pack, mb_fini_pack, zone_mbuf); 145 146 /* uma_prealloc() goes here */ 147 148 /* 149 * Hook event handler for low-memory situation, used to 150 * drain protocols and push data back to the caches (UMA 151 * later pushes it back to VM). 152 */ 153 EVENTHANDLER_REGISTER(vm_lowmem, mb_reclaim, NULL, 154 EVENTHANDLER_PRI_FIRST); 155 156 /* 157 * [Re]set counters and local statistics knobs. 158 * XXX Some of these should go and be replaced, but UMA stat 159 * gathering needs to be revised. 160 */ 161 mbstat.m_mbufs = 0; 162 mbstat.m_mclusts = 0; 163 mbstat.m_drain = 0; 164 mbstat.m_msize = MSIZE; 165 mbstat.m_mclbytes = MCLBYTES; 166 mbstat.m_minclsize = MINCLSIZE; 167 mbstat.m_mlen = MLEN; 168 mbstat.m_mhlen = MHLEN; 169 mbstat.m_numtypes = MT_NTYPES; 170 171 mbstat.m_mcfail = mbstat.m_mpfail = 0; 172 mbstat.sf_iocnt = 0; 173 mbstat.sf_allocwait = mbstat.sf_allocfail = 0; 174} 175 176/* 177 * Constructor for Mbuf master zone. 178 * 179 * The 'arg' pointer points to a mb_args structure which 180 * contains call-specific information required to support the 181 * mbuf allocation API. 182 */ 183static void 184mb_ctor_mbuf(void *mem, int size, void *arg) 185{ 186 struct mbuf *m; 187 struct mb_args *args; 188 int flags; 189 int how; 190 short type; 191 192 m = (struct mbuf *)mem; 193 args = (struct mb_args *)arg; 194 flags = args->flags; 195 how = args->how; 196 type = args->type; 197 198 m->m_type = type; 199 m->m_next = NULL; 200 m->m_nextpkt = NULL;
| 34 35#include "opt_mac.h" 36#include "opt_param.h" 37 38#include <sys/param.h> 39#include <sys/mac.h> 40#include <sys/malloc.h> 41#include <sys/systm.h> 42#include <sys/mbuf.h> 43#include <sys/domain.h> 44#include <sys/eventhandler.h> 45#include <sys/kernel.h> 46#include <sys/protosw.h> 47#include <sys/smp.h> 48#include <sys/sysctl.h> 49 50#include <vm/vm.h> 51#include <vm/vm_page.h> 52#include <vm/uma.h> 53 54/* 55 * In FreeBSD, Mbufs and Mbuf Clusters are allocated from UMA 56 * Zones. 57 * 58 * Mbuf Clusters (2K, contiguous) are allocated from the Cluster 59 * Zone. The Zone can be capped at kern.ipc.nmbclusters, if the 60 * administrator so desires. 61 * 62 * Mbufs are allocated from a UMA Master Zone called the Mbuf 63 * Zone. 64 * 65 * Additionally, FreeBSD provides a Packet Zone, which it 66 * configures as a Secondary Zone to the Mbuf Master Zone, 67 * thus sharing backend Slab kegs with the Mbuf Master Zone. 68 * 69 * Thus common-case allocations and locking are simplified: 70 * 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 85int nmbclusters; 86struct mbstat mbstat; 87 88static void 89tunable_mbinit(void *dummy) 90{ 91 92 /* This has to be done before VM init. */ 93 nmbclusters = 1024 + maxusers * 64; 94 TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters); 95} 96SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_ANY, tunable_mbinit, NULL); 97 98SYSCTL_DECL(_kern_ipc); 99SYSCTL_INT(_kern_ipc, OID_AUTO, nmbclusters, CTLFLAG_RW, &nmbclusters, 0, 100 "Maximum number of mbuf clusters allowed"); 101SYSCTL_STRUCT(_kern_ipc, OID_AUTO, mbstat, CTLFLAG_RD, &mbstat, mbstat, 102 "Mbuf general information and statistics"); 103 104/* 105 * Zones from which we allocate. 106 */ 107uma_zone_t zone_mbuf; 108uma_zone_t zone_clust; 109uma_zone_t zone_pack; 110 111/* 112 * Local prototypes. 113 */ 114static void mb_ctor_mbuf(void *, int, void *); 115static void mb_ctor_clust(void *, int, void *); 116static void mb_ctor_pack(void *, int, void *); 117static void mb_dtor_mbuf(void *, int, void *); 118static void mb_dtor_clust(void *, int, void *); /* XXX */ 119static void mb_dtor_pack(void *, int, void *); /* XXX */ 120static void mb_init_pack(void *, int); 121static void mb_fini_pack(void *, int); 122 123static void mb_reclaim(void *); 124static void mbuf_init(void *); 125 126/* 127 * Initialize FreeBSD Network buffer allocation. 128 */ 129SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL) 130static void 131mbuf_init(void *dummy) 132{ 133 134 /* 135 * Configure UMA zones for Mbufs, Clusters, and Packets. 136 */ 137 zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, 138 NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_MAXBUCKET); 139 zone_clust = uma_zcreate("MbufClust", MCLBYTES, mb_ctor_clust, 140 mb_dtor_clust, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_REFCNT); 141 if (nmbclusters > 0) 142 uma_zone_set_max(zone_clust, nmbclusters); 143 zone_pack = uma_zsecond_create("Packet", mb_ctor_pack, mb_dtor_pack, 144 mb_init_pack, mb_fini_pack, zone_mbuf); 145 146 /* uma_prealloc() goes here */ 147 148 /* 149 * Hook event handler for low-memory situation, used to 150 * drain protocols and push data back to the caches (UMA 151 * later pushes it back to VM). 152 */ 153 EVENTHANDLER_REGISTER(vm_lowmem, mb_reclaim, NULL, 154 EVENTHANDLER_PRI_FIRST); 155 156 /* 157 * [Re]set counters and local statistics knobs. 158 * XXX Some of these should go and be replaced, but UMA stat 159 * gathering needs to be revised. 160 */ 161 mbstat.m_mbufs = 0; 162 mbstat.m_mclusts = 0; 163 mbstat.m_drain = 0; 164 mbstat.m_msize = MSIZE; 165 mbstat.m_mclbytes = MCLBYTES; 166 mbstat.m_minclsize = MINCLSIZE; 167 mbstat.m_mlen = MLEN; 168 mbstat.m_mhlen = MHLEN; 169 mbstat.m_numtypes = MT_NTYPES; 170 171 mbstat.m_mcfail = mbstat.m_mpfail = 0; 172 mbstat.sf_iocnt = 0; 173 mbstat.sf_allocwait = mbstat.sf_allocfail = 0; 174} 175 176/* 177 * Constructor for Mbuf master zone. 178 * 179 * The 'arg' pointer points to a mb_args structure which 180 * contains call-specific information required to support the 181 * mbuf allocation API. 182 */ 183static void 184mb_ctor_mbuf(void *mem, int size, void *arg) 185{ 186 struct mbuf *m; 187 struct mb_args *args; 188 int flags; 189 int how; 190 short type; 191 192 m = (struct mbuf *)mem; 193 args = (struct mb_args *)arg; 194 flags = args->flags; 195 how = args->how; 196 type = args->type; 197 198 m->m_type = type; 199 m->m_next = NULL; 200 m->m_nextpkt = NULL;
|
| 201 m->m_flags = flags;
|
201 if (flags & M_PKTHDR) { 202 m->m_data = m->m_pktdat;
| 202 if (flags & M_PKTHDR) { 203 m->m_data = m->m_pktdat;
|
203 m->m_flags = M_PKTHDR;
| |
204 m->m_pkthdr.rcvif = NULL; 205 m->m_pkthdr.csum_flags = 0; 206 SLIST_INIT(&m->m_pkthdr.tags); 207#ifdef MAC 208 /* If the label init fails, fail the alloc */ 209 if (mac_init_mbuf(m, how) != 0) { 210 m_free(m); 211/* XXX*/ panic("mb_ctor_mbuf(): can't deal with failure!"); 212/* return 0; */ 213 } 214#endif
| 204 m->m_pkthdr.rcvif = NULL; 205 m->m_pkthdr.csum_flags = 0; 206 SLIST_INIT(&m->m_pkthdr.tags); 207#ifdef MAC 208 /* If the label init fails, fail the alloc */ 209 if (mac_init_mbuf(m, how) != 0) { 210 m_free(m); 211/* XXX*/ panic("mb_ctor_mbuf(): can't deal with failure!"); 212/* return 0; */ 213 } 214#endif
|
215 } else {
| 215 } else
|
216 m->m_data = m->m_dat;
| 216 m->m_data = m->m_dat;
|
217 m->m_flags = 0; 218 }
| |
219 mbstat.m_mbufs += 1; /* XXX */ 220/* return 1; 221*/ 222} 223 224/* 225 * The Mbuf master zone and Packet secondary zone destructor. 226 */ 227static void 228mb_dtor_mbuf(void *mem, int size, void *arg) 229{ 230 struct mbuf *m; 231 232 m = (struct mbuf *)mem; 233 if ((m->m_flags & M_PKTHDR) != 0) 234 m_tag_delete_chain(m, NULL); 235 mbstat.m_mbufs -= 1; /* XXX */ 236} 237 238/* XXX Only because of stats */ 239static void 240mb_dtor_pack(void *mem, int size, void *arg) 241{ 242 struct mbuf *m; 243 244 m = (struct mbuf *)mem; 245 if ((m->m_flags & M_PKTHDR) != 0) 246 m_tag_delete_chain(m, NULL); 247 mbstat.m_mbufs -= 1; /* XXX */ 248 mbstat.m_mclusts -= 1; /* XXX */ 249} 250 251/* 252 * The Cluster zone constructor. 253 * 254 * Here the 'arg' pointer points to the Mbuf which we 255 * are configuring cluster storage for. 256 */ 257static void 258mb_ctor_clust(void *mem, int size, void *arg) 259{ 260 struct mbuf *m; 261 262 m = (struct mbuf *)arg; 263 m->m_ext.ext_buf = (caddr_t)mem; 264 m->m_data = m->m_ext.ext_buf; 265 m->m_flags |= M_EXT; 266 m->m_ext.ext_free = NULL; 267 m->m_ext.ext_args = NULL; 268 m->m_ext.ext_size = MCLBYTES; 269 m->m_ext.ext_type = EXT_CLUSTER; 270 m->m_ext.ref_cnt = (u_int *)uma_find_refcnt(zone_clust, 271 m->m_ext.ext_buf); 272 *(m->m_ext.ref_cnt) = 1; 273 mbstat.m_mclusts += 1; /* XXX */ 274/* return 1; 275*/ 276} 277 278/* XXX */ 279static void 280mb_dtor_clust(void *mem, int size, void *arg) 281{ 282 mbstat.m_mclusts -= 1; /* XXX */ 283} 284 285/* 286 * The Packet secondary zone's init routine, executed on the 287 * object's transition from keg slab to zone cache. 288 */ 289static void 290mb_init_pack(void *mem, int size) 291{ 292 struct mbuf *m; 293 294 m = (struct mbuf *)mem; 295 m->m_ext.ext_buf = NULL; 296 uma_zalloc_arg(zone_clust, m, M_NOWAIT); 297 if (m->m_ext.ext_buf == NULL) /* XXX */ 298 panic("mb_init_pack(): Can't deal with failure yet."); 299 mbstat.m_mclusts -= 1; /* XXX */ 300} 301 302/* 303 * The Packet secondary zone's fini routine, executed on the 304 * object's transition from zone cache to keg slab. 305 */ 306static void 307mb_fini_pack(void *mem, int size) 308{ 309 struct mbuf *m; 310 311 m = (struct mbuf *)mem; 312 uma_zfree_arg(zone_clust, m->m_ext.ext_buf, NULL); 313 m->m_ext.ext_buf = NULL; 314 mbstat.m_mclusts += 1; /* XXX */ 315} 316 317/* 318 * The "packet" keg constructor. 319 */ 320static void 321mb_ctor_pack(void *mem, int size, void *arg) 322{ 323 struct mbuf *m; 324 struct mb_args *args; 325 int flags, how; 326 short type; 327 328 m = (struct mbuf *)mem; 329 args = (struct mb_args *)arg; 330 flags = args->flags; 331 type = args->type; 332 how = args->how; 333 334 m->m_type = type; 335 m->m_next = NULL;
| 217 mbstat.m_mbufs += 1; /* XXX */ 218/* return 1; 219*/ 220} 221 222/* 223 * The Mbuf master zone and Packet secondary zone destructor. 224 */ 225static void 226mb_dtor_mbuf(void *mem, int size, void *arg) 227{ 228 struct mbuf *m; 229 230 m = (struct mbuf *)mem; 231 if ((m->m_flags & M_PKTHDR) != 0) 232 m_tag_delete_chain(m, NULL); 233 mbstat.m_mbufs -= 1; /* XXX */ 234} 235 236/* XXX Only because of stats */ 237static void 238mb_dtor_pack(void *mem, int size, void *arg) 239{ 240 struct mbuf *m; 241 242 m = (struct mbuf *)mem; 243 if ((m->m_flags & M_PKTHDR) != 0) 244 m_tag_delete_chain(m, NULL); 245 mbstat.m_mbufs -= 1; /* XXX */ 246 mbstat.m_mclusts -= 1; /* XXX */ 247} 248 249/* 250 * The Cluster zone constructor. 251 * 252 * Here the 'arg' pointer points to the Mbuf which we 253 * are configuring cluster storage for. 254 */ 255static void 256mb_ctor_clust(void *mem, int size, void *arg) 257{ 258 struct mbuf *m; 259 260 m = (struct mbuf *)arg; 261 m->m_ext.ext_buf = (caddr_t)mem; 262 m->m_data = m->m_ext.ext_buf; 263 m->m_flags |= M_EXT; 264 m->m_ext.ext_free = NULL; 265 m->m_ext.ext_args = NULL; 266 m->m_ext.ext_size = MCLBYTES; 267 m->m_ext.ext_type = EXT_CLUSTER; 268 m->m_ext.ref_cnt = (u_int *)uma_find_refcnt(zone_clust, 269 m->m_ext.ext_buf); 270 *(m->m_ext.ref_cnt) = 1; 271 mbstat.m_mclusts += 1; /* XXX */ 272/* return 1; 273*/ 274} 275 276/* XXX */ 277static void 278mb_dtor_clust(void *mem, int size, void *arg) 279{ 280 mbstat.m_mclusts -= 1; /* XXX */ 281} 282 283/* 284 * The Packet secondary zone's init routine, executed on the 285 * object's transition from keg slab to zone cache. 286 */ 287static void 288mb_init_pack(void *mem, int size) 289{ 290 struct mbuf *m; 291 292 m = (struct mbuf *)mem; 293 m->m_ext.ext_buf = NULL; 294 uma_zalloc_arg(zone_clust, m, M_NOWAIT); 295 if (m->m_ext.ext_buf == NULL) /* XXX */ 296 panic("mb_init_pack(): Can't deal with failure yet."); 297 mbstat.m_mclusts -= 1; /* XXX */ 298} 299 300/* 301 * The Packet secondary zone's fini routine, executed on the 302 * object's transition from zone cache to keg slab. 303 */ 304static void 305mb_fini_pack(void *mem, int size) 306{ 307 struct mbuf *m; 308 309 m = (struct mbuf *)mem; 310 uma_zfree_arg(zone_clust, m->m_ext.ext_buf, NULL); 311 m->m_ext.ext_buf = NULL; 312 mbstat.m_mclusts += 1; /* XXX */ 313} 314 315/* 316 * The "packet" keg constructor. 317 */ 318static void 319mb_ctor_pack(void *mem, int size, void *arg) 320{ 321 struct mbuf *m; 322 struct mb_args *args; 323 int flags, how; 324 short type; 325 326 m = (struct mbuf *)mem; 327 args = (struct mb_args *)arg; 328 flags = args->flags; 329 type = args->type; 330 how = args->how; 331 332 m->m_type = type; 333 m->m_next = NULL;
|
| 334 m->m_nextpkt = NULL;
|
336 m->m_data = m->m_ext.ext_buf; 337 m->m_flags = flags|M_EXT; 338 m->m_ext.ext_free = NULL; 339 m->m_ext.ext_args = NULL; 340 m->m_ext.ext_size = MCLBYTES; 341 m->m_ext.ext_type = EXT_PACKET; 342 *(m->m_ext.ref_cnt) = 1; 343 344 if (flags & M_PKTHDR) {
| 335 m->m_data = m->m_ext.ext_buf; 336 m->m_flags = flags|M_EXT; 337 m->m_ext.ext_free = NULL; 338 m->m_ext.ext_args = NULL; 339 m->m_ext.ext_size = MCLBYTES; 340 m->m_ext.ext_type = EXT_PACKET; 341 *(m->m_ext.ref_cnt) = 1; 342 343 if (flags & M_PKTHDR) {
|
345 m->m_nextpkt = NULL;
| |
346 m->m_pkthdr.rcvif = NULL; 347 m->m_pkthdr.csum_flags = 0; 348 SLIST_INIT(&m->m_pkthdr.tags); 349#ifdef MAC 350 /* If the label init fails, fail the alloc */ 351 if (mac_init_mbuf(m, how) != 0) { 352 m_free(m); 353/* XXX*/ panic("mb_ctor_pack(): can't deal with failure!"); 354/* return 0; */ 355 } 356#endif 357 } 358 mbstat.m_mbufs += 1; /* XXX */ 359 mbstat.m_mclusts += 1; /* XXX */ 360/* return 1; 361*/ 362} 363 364/* 365 * This is the protocol drain routine. 366 * 367 * No locks should be held when this is called. The drain routines have to 368 * presently acquire some locks which raises the possibility of lock order 369 * reversal. 370 */ 371static void 372mb_reclaim(void *junk) 373{ 374 struct domain *dp; 375 struct protosw *pr; 376 377 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK | WARN_PANIC, NULL, 378 "mb_reclaim()"); 379 380 mbstat.m_drain++; 381 for (dp = domains; dp != NULL; dp = dp->dom_next) 382 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 383 if (pr->pr_drain != NULL) 384 (*pr->pr_drain)(); 385}
| 344 m->m_pkthdr.rcvif = NULL; 345 m->m_pkthdr.csum_flags = 0; 346 SLIST_INIT(&m->m_pkthdr.tags); 347#ifdef MAC 348 /* If the label init fails, fail the alloc */ 349 if (mac_init_mbuf(m, how) != 0) { 350 m_free(m); 351/* XXX*/ panic("mb_ctor_pack(): can't deal with failure!"); 352/* return 0; */ 353 } 354#endif 355 } 356 mbstat.m_mbufs += 1; /* XXX */ 357 mbstat.m_mclusts += 1; /* XXX */ 358/* return 1; 359*/ 360} 361 362/* 363 * This is the protocol drain routine. 364 * 365 * No locks should be held when this is called. The drain routines have to 366 * presently acquire some locks which raises the possibility of lock order 367 * reversal. 368 */ 369static void 370mb_reclaim(void *junk) 371{ 372 struct domain *dp; 373 struct protosw *pr; 374 375 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK | WARN_PANIC, NULL, 376 "mb_reclaim()"); 377 378 mbstat.m_drain++; 379 for (dp = domains; dp != NULL; dp = dp->dom_next) 380 for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) 381 if (pr->pr_drain != NULL) 382 (*pr->pr_drain)(); 383}
|