diff -ruN /usr/src/sys.old/conf/files /usr/src/sys/conf/files --- /usr/src/sys.old/conf/files Sun Apr 29 15:28:20 2001 +++ /usr/src/sys/conf/files Sun Apr 29 15:35:23 2001 @@ -677,6 +677,7 @@ kern/kern_lock.c standard kern/kern_lockf.c standard kern/kern_malloc.c standard +kern/kern_mbuf.c standard kern/kern_mib.c standard kern/kern_module.c standard kern/kern_mutex.c standard diff -ruN /usr/src/sys.old/conf/param.c /usr/src/sys/conf/param.c --- /usr/src/sys.old/conf/param.c Sun Apr 29 15:28:21 2001 +++ /usr/src/sys/conf/param.c Sun Apr 29 15:36:00 2001 @@ -68,7 +68,10 @@ int maxfiles = MAXFILES; /* system wide open files limit */ int maxfilesperproc = MAXFILES; /* per-process open files limit */ int ncallout = 16 + NPROC + MAXFILES; /* maximum # of timer events */ -int mbuf_wait = 32; /* mbuf sleep time in ticks */ +int mbuf_wait = 64; /* mbuf sleep time in ticks */ +u_int mbuf_limit = 512; +u_int clust_limit = 128; +u_int cnt_limit = 256; /* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */ #ifndef NSFBUFS diff -ruN /usr/src/sys.old/dev/vx/if_vx.c /usr/src/sys/dev/vx/if_vx.c --- /usr/src/sys.old/dev/vx/if_vx.c Sun Apr 29 15:28:49 2001 +++ /usr/src/sys/dev/vx/if_vx.c Sun Apr 29 16:05:33 2001 @@ -31,6 +31,8 @@ * */ +#error "This driver is broken. Until it's fixed, you can't use it." + /* * Created from if_ep.c driver by Fred Gray (fgray@rice.edu) to support * the 3c590 family. diff -ruN /usr/src/sys.old/kern/kern_malloc.c /usr/src/sys/kern/kern_malloc.c --- /usr/src/sys.old/kern/kern_malloc.c Sun Apr 29 15:29:13 2001 +++ /usr/src/sys/kern/kern_malloc.c Sun Apr 29 15:39:35 2001 @@ -41,9 +41,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -476,7 +476,7 @@ vm_kmem_size = 2 * cnt.v_page_count * PAGE_SIZE; npg = (nmbufs * MSIZE + nmbclusters * MCLBYTES + nmbcnt * - sizeof(union mext_refcnt) + vm_kmem_size) / PAGE_SIZE; + sizeof(struct mext_refcnt) + vm_kmem_size) / PAGE_SIZE; kmemusage = (struct kmemusage *) kmem_alloc(kernel_map, (vm_size_t)(npg * sizeof(struct kmemusage))); diff -ruN /dev/null /usr/src/sys/kern/kern_mbuf.c --- /dev/null Wed Dec 31 19:00:00 1969 +++ /usr/src/sys/kern/kern_mbuf.c Sun Apr 29 15:34:08 2001 @@ -0,0 +1,824 @@ +/* + * Copyright (c) 2001 + * Bosko Milekic . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by members and contributors + * of The FreeBSD Project (http://www.FreeBSD.org/) + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include "opt_param.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* XXX: Ack, where do we get this from for real? */ +#define NCPU 2 + +/* + * The mbuf allocator is heavily based on Alfred Perlstein's + * (alfred@FreeBSD.org) "memcache" allocator which is itself based + * on concepts from several per-CPU memory allocators. The difference + * between this allocator and memcache is that, among other things: + * + * (i) We don't need to do as many things as memcache so we shouldn't waste + * resources worrying about it (e.g. we don't want to ever free back to + * mb_map). + * + * (ii) We want to leave room for future optimizations which may allow us + * to inline a portion of "the easy allocation," provided that the + * generated code is small enough. + * + * (iii) We block on a condition variable in the worst-case scenario, and + * attempt to "steal" objects from other lists. Before we do either, + * we also drain protocols, a task very mbuf-system-specific. + * + * The mbuf allocator keeps all objects that it allocates in mb_buckets. + * The buckets keep a page worth of objects (an object can be an mbuf, an + * mbuf cluster, or an external object reference counter) and facilitate + * moving larger sets of contiguous objects (objects from the same page) + * from the per-CPU lists to the main list for the given object. The buckets + * also have an added advantage in that after several moves from a per-CPU + * list to the main list and back to the per-CPU list, contiguous objects + * are kept together, thus trying to put the TLB cache to good use. + * + * The buckets are kept on singly-linked lists called "containers." A container + * is protected by a mutex lock in order to ensure consistency. The mutex lock + * itself is allocated seperately and attached to the container at boot time, + * thus allowing for certain containers to share the same mutex lock. Per-CPU + * containers for mbufs, clusters, and counters all share the same per-CPU + * lock whereas the "general system" containers (i.e. the "main lists") for + * these objects share one global lock. + * + * When, during allocation, the per-CPU container, the main container for + * the given object, and the space reserved in mb_map for that object are + * all depleted then, depending on whether the allocation was done with + * M_TRYWAIT, we may be allowed to block for a maximum of mbuf_wait ticks. + * The blocking is implemented with a condition variable found only in the + * main (general) container for the given object. During exhaustion, all + * freeing is done to the general list so that any blockers can pick up + * whatever comes in first. + * + */ +struct mb_bucket { + SLIST_ENTRY(mb_bucket) buck_list; + int bckt_owner; + int num_free; + void *free[1]; +}; + +struct mb_container { + SLIST_HEAD(, mb_bucket) buck_head; + struct mtx *mtx_lock; + int num_owner; + u_int starved; +}; + +struct mb_gen_list { + struct mb_container mb_cont; + struct cv m_starved; +}; + +struct mb_pcpu_list { + struct mb_container mb_cont; + u_int obj_count; +}; + +/* + * Parameters used to scale the size of mb_map and its submaps. + * These are tunable at boottime. + */ +int nmbufs; +int nmbclusters; +int nmbcnt; +#ifndef NMBCLUSTERS +#define NMBCLUSTERS (512 + MAXUSERS * 16) +#endif +#ifndef NMBUFS +#define NMBUFS (NMBCLUSTERS * 4) +#endif +#ifndef NMBCNTS +#define NMBCNTS (NMBCLUSTERS + nsfbufs) +#endif +TUNABLE_INT_DECL("kern.ipc.nmbufs", NMBUFS, nmbufs); +TUNABLE_INT_DECL("kern.ipc.nmbclusters", NMBCLUSTERS, nmbclusters); +TUNABLE_INT_DECL("kern.ipc.nmbcnt", NMBCNTS, nmbcnt); + +/* + * The freelist structures and mutex locks. The number statically declared + * here depends on the number of CPUs. + * + * We setup in such a way that all the objects (mbufs, clusters, ref counters) + * share the same mutex lock. It has been established that we do not benefit + * from different locks for different objects, so we use the same lock, + * regardless of object type. + */ +struct mb_lstmngr { + struct mb_gen_list *gen_list; + struct mb_pcpu_list *cnt_lst[NCPU]; + vm_map_t map; + vm_offset_t map_base; + vm_offset_t map_top; + struct mb_bucket **b_table; + int map_full; + u_int obj_size; + u_int *wm_high; +}; +struct mb_lstmngr mb_list_mbuf, mb_list_clust, mb_list_cnt; +struct mtx mbuf_gen, mbuf_pcpu[NCPU]; + +#define MB_GET_PCPU_LIST(mb_lst) (mb_lst)->cnt_lst[PCPU_GET(cpuid)] +#define MB_GET_PCPU_LIST_NUM(mb_lst, num) (mb_lst)->cnt_lst[(num)] +#define MB_GET_GEN_LIST(mb_lst) (mb_lst)->gen_list + +#define MB_LOCK_CONT(mb_cnt) mtx_lock((mb_cnt)->mb_cont.mtx_lock) +#define MB_UNLOCK_CONT(mb_cnt) mtx_unlock((mb_cnt)->mb_cont.mtx_lock) + +#define MB_BUCKET_INDX(mb_obj, mb_lst) \ + (int)(((char *)(mb_obj) - (char *)(mb_lst)->map_base) / PAGE_SIZE) + +/* + * Ownership of buckets/containers is managed through integers. The PCPU + * lists range from 0 to NCPU-1. We need a free numerical id for the general + * list (usually NCPU). We also need a non-conflicting free bit to indicate + * that the bucket is free and removed from a container, while not losing + * the bucket's originating container id. We usually use the highest bit + * for the free marker. + */ +#define MB_GENLIST_OWNER (NCPU) +#define MB_BUCKET_FREE (1 << (sizeof(int) * 8 - 1)) + +/* + * sysctl(8) exported objects + */ +SYSCTL_DECL(_kern_ipc); +SYSCTL_INT(_kern_ipc, OID_AUTO, nmbclusters, CTLFLAG_RD, &nmbclusters, 0, + "Maximum number of mbuf clusters available"); +SYSCTL_INT(_kern_ipc, OID_AUTO, nmbufs, CTLFLAG_RD, &nmbufs, 0, + "Maximum number of mbufs available"); +SYSCTL_INT(_kern_ipc, OID_AUTO, nmbcnt, CTLFLAG_RD, &nmbcnt, 0, + "Maximum number of ext_buf counters available"); +SYSCTL_INT(_kern_ipc, OID_AUTO, mbuf_wait, CTLFLAG_RW, &mbuf_wait, 0, + "Sleep time of mbuf subsystem wait allocations during exhaustion"); +SYSCTL_UINT(_kern_ipc, OID_AUTO, mbuf_limit, CTLFLAG_RW, &mbuf_limit, 0, + "Upper limit of number of mbufs allowed on each PCPU list"); +SYSCTL_UINT(_kern_ipc, OID_AUTO, clust_limit, CTLFLAG_RW, &clust_limit, 0, + "Upper limit of number of mbuf clusters allowed on each PCPU list"); +SYSCTL_UINT(_kern_ipc, OID_AUTO, cnt_limit, CTLFLAG_RW, &cnt_limit, 0, + "Upper limit of number of m_ext counters allowed on each PCPU list"); + +/* + * Prototypes of local (internal) routines. + */ +void *mb_alloc_wait(struct mb_lstmngr *); +static void mb_init(void *); +struct mb_bucket *mb_pop_cont(struct mb_lstmngr *, int, + struct mb_pcpu_list *); +void mb_reclaim(void); + +/* + * Initial allocation numbers. Each parameter represents the number of buckets + * of each object that will be placed initially in each PCPU container for + * said object. + */ +#define NMB_MBUF_INIT 2 +#define NMB_CLUST_INIT 2 +#define NMB_CNT_INIT (NMBCLUSTERS * sizeof(struct mext_refcnt) / PAGE_SIZE) + +/* + * Initialize the mbuf subsystem. + * + * We sub-divide the mb_map into several submaps; this way, we don't have + * to worry about artificially limiting the number of mbuf or mbuf cluster + * allocations, due to fear of one type of allocation "stealing" address + * space initially reserved for another. + * + * Setup both the general containers and all the PCPU containers. Populate + * the PCPU containers with initial numbers. + */ +MALLOC_DEFINE(M_MBUF, "mbufmgr", "mbuf subsystem management structures"); +SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mb_init, NULL) +static void +mb_init(void *dummy) +{ + struct mb_pcpu_list *pcpu_cnt; + vm_offset_t maxaddr, mb_map_base; + vm_size_t mb_map_size; + int i, j; + + /* + * Setup the mb_map, allocate requested VM space. + */ + mb_map_size = (vm_size_t)(nmbufs * MSIZE + nmbclusters * MCLBYTES + + nmbcnt * sizeof(struct mext_refcnt)); + mb_map_size = rounddown(mb_map_size, PAGE_SIZE); + mb_map = kmem_suballoc(kmem_map, &mb_map_base, &maxaddr, mb_map_size); + /* XXX XXX XXX: mb_map->system_map = 1; */ + + /* + * Setup all the submaps, for each type of object that we deal + * with in this allocator. + */ + mb_map_size = (vm_size_t)(nmbufs * MSIZE); + mb_map_size = rounddown(mb_map_size, PAGE_SIZE); + mb_list_mbuf.b_table = malloc((unsigned long)mb_map_size / PAGE_SIZE, + M_MBUF, M_NOWAIT); + if (mb_list_mbuf.b_table == NULL) + goto bad; + mb_list_mbuf.map = kmem_suballoc(mb_map, &(mb_list_mbuf.map_base), + &(mb_list_mbuf.map_top), mb_map_size); + mb_list_mbuf.map_full = 0; + mb_list_mbuf.obj_size = MSIZE; + mb_list_mbuf.wm_high = &mbuf_limit; + + mb_map_size = (vm_size_t)(nmbclusters * MCLBYTES); + mb_map_size = rounddown(mb_map_size, PAGE_SIZE); + mb_list_clust.b_table = malloc((unsigned long)mb_map_size / PAGE_SIZE, + M_MBUF, M_NOWAIT); + if (mb_list_clust.b_table == NULL) + goto bad; + mb_list_clust.map = kmem_suballoc(mb_map, &(mb_list_clust.map_base), + &(mb_list_clust.map_top), mb_map_size); + mb_list_clust.map_full = 0; + mb_list_clust.obj_size = MCLBYTES; + mb_list_clust.wm_high = &clust_limit; + + mb_map_size = (vm_size_t)(nmbcnt * sizeof(struct mext_refcnt)); + mb_map_size = rounddown(mb_map_size, PAGE_SIZE); + mb_list_cnt.b_table = malloc((unsigned long)mb_map_size / PAGE_SIZE, + M_MBUF, M_NOWAIT); + if (mb_list_cnt.b_table == NULL) + goto bad; + mb_list_cnt.map = kmem_suballoc(mb_map, &(mb_list_cnt.map_base), + &(mb_list_cnt.map_top), mb_map_size); + mb_list_cnt.map_full = 0; + mb_list_cnt.obj_size = sizeof(struct mext_refcnt); + mb_list_cnt.wm_high = &cnt_limit; + /* XXX XXX XXX: mbuf_map->system_map = clust_map->system_map = + refcnt_map->system_map = 1; */ + + /* + * Allocate required general (global) containers for each object type. + */ + mb_list_mbuf.gen_list = malloc(sizeof(struct mb_gen_list), M_MBUF, + M_NOWAIT); + mb_list_clust.gen_list = malloc(sizeof(struct mb_gen_list), M_MBUF, + M_NOWAIT); + mb_list_cnt.gen_list = malloc(sizeof(struct mb_gen_list), M_MBUF, + M_NOWAIT); + if ((mb_list_mbuf.gen_list == NULL) || (mb_list_clust.gen_list == NULL) + || (mb_list_cnt.gen_list == NULL)) + goto bad; + + /* + * Initialize condition variables and general container mutex locks. + */ + mtx_init(&mbuf_gen, "mbuf subsystem general lists lock", 0); + cv_init(&(mb_list_mbuf.gen_list->m_starved), "mbuf pool starved"); + cv_init(&(mb_list_clust.gen_list->m_starved), "mcluster pool starved"); + cv_init(&(mb_list_cnt.gen_list->m_starved), "mext cntr pool starved"); + mb_list_mbuf.gen_list->mb_cont.mtx_lock = + mb_list_clust.gen_list->mb_cont.mtx_lock = + mb_list_cnt.gen_list->mb_cont.mtx_lock = &mbuf_gen; + + /* + * Setup the general containers for each object. + */ + mb_list_mbuf.gen_list->mb_cont.num_owner = + mb_list_clust.gen_list->mb_cont.num_owner = + mb_list_cnt.gen_list->mb_cont.num_owner = MB_GENLIST_OWNER; + mb_list_mbuf.gen_list->mb_cont.starved = + mb_list_clust.gen_list->mb_cont.starved = + mb_list_cnt.gen_list->mb_cont.starved = 0; + SLIST_INIT(&(mb_list_mbuf.gen_list->mb_cont.buck_head)); + SLIST_INIT(&(mb_list_clust.gen_list->mb_cont.buck_head)); + SLIST_INIT(&(mb_list_cnt.gen_list->mb_cont.buck_head)); + + /* + * Allocate and initialize PCPU containers. + */ + for (i = 0; i < NCPU; i++) { + mb_list_mbuf.cnt_lst[i] = malloc(sizeof(struct mb_pcpu_list), + M_MBUF, M_NOWAIT); + mb_list_clust.cnt_lst[i] = malloc(sizeof(struct mb_pcpu_list), + M_MBUF, M_NOWAIT); + mb_list_cnt.cnt_lst[i] = malloc(sizeof(struct mb_pcpu_list), + M_MBUF, M_NOWAIT); + if ((mb_list_mbuf.cnt_lst[i] == NULL) || + (mb_list_clust.cnt_lst[i] == NULL) || + (mb_list_cnt.cnt_lst[i] == NULL)) + goto bad; + + mtx_init(&mbuf_pcpu[i], "mbuf PCPU list lock", 0); + mb_list_mbuf.cnt_lst[i]->mb_cont.mtx_lock = + mb_list_clust.cnt_lst[i]->mb_cont.mtx_lock = + mb_list_cnt.cnt_lst[i]->mb_cont.mtx_lock = &mbuf_pcpu[i]; + + mb_list_mbuf.cnt_lst[i]->mb_cont.num_owner = + mb_list_clust.cnt_lst[i]->mb_cont.num_owner = + mb_list_cnt.cnt_lst[i]->mb_cont.num_owner = i; + mb_list_mbuf.cnt_lst[i]->mb_cont.starved = + mb_list_clust.cnt_lst[i]->mb_cont.starved = + mb_list_cnt.cnt_lst[i]->mb_cont.starved = 0; + mb_list_mbuf.cnt_lst[i]->obj_count = + mb_list_clust.cnt_lst[i]->obj_count = + mb_list_cnt.cnt_lst[i]->obj_count = 0; + + SLIST_INIT(&(mb_list_mbuf.cnt_lst[i]->mb_cont.buck_head)); + SLIST_INIT(&(mb_list_clust.cnt_lst[i]->mb_cont.buck_head)); + SLIST_INIT(&(mb_list_cnt.cnt_lst[i]->mb_cont.buck_head)); + + /* + * Perform initial allocations. + */ + pcpu_cnt = MB_GET_PCPU_LIST_NUM(&mb_list_mbuf, i); + MB_LOCK_CONT(pcpu_cnt); + for (j = 0; j < NMB_MBUF_INIT; j++) { + if (mb_pop_cont(&mb_list_mbuf, M_DONTWAIT, pcpu_cnt) + == NULL) + goto bad; + } + MB_UNLOCK_CONT(pcpu_cnt); + + pcpu_cnt = MB_GET_PCPU_LIST_NUM(&mb_list_clust, i); + MB_LOCK_CONT(pcpu_cnt); + for (j = 0; j < NMB_CLUST_INIT; j++) { + if (mb_pop_cont(&mb_list_clust, M_DONTWAIT, pcpu_cnt) + == NULL) + goto bad; + } + MB_UNLOCK_CONT(pcpu_cnt); + + pcpu_cnt = MB_GET_PCPU_LIST_NUM(&mb_list_cnt, i); + MB_LOCK_CONT(pcpu_cnt); + for (j = 0; j < NMB_CNT_INIT; j++) { + if (mb_pop_cont(&mb_list_cnt, M_DONTWAIT, pcpu_cnt) + == NULL) + goto bad; + } + MB_UNLOCK_CONT(pcpu_cnt); + } + + return; +bad: + panic("mb_init(): failed to initialize mbuf subsystem!"); +} + +/* + * Populate a given mbuf PCPU container with a bucket full of fresh new + * buffers. Return a pointer to the new bucket (already in the container if + * successful), or return NULL on failure. + * + * LOCKING NOTES: + * PCPU container lock must be held when this is called. + * The lock is dropped here so that we can cleanly call the underlying VM + * code. If we fail, we return with no locks held. If we succeed (i.e. return + * non-NULL), we return with the PCPU lock held, ready for allocation from + * the returned bucket. + */ +struct mb_bucket * +mb_pop_cont(struct mb_lstmngr *mb_list, int how, struct mb_pcpu_list *cnt_lst) +{ + struct mb_bucket *bucket; + caddr_t p; + int i; + + MB_UNLOCK_CONT(cnt_lst); + + /* + * If our object's (finite) map is starved now (i.e. no more address + * space), bail out now. + */ + if (mb_list->map_full) + return (NULL); + + bucket = malloc(sizeof(struct mb_bucket) + + PAGE_SIZE / mb_list->obj_size * sizeof(void *), M_MBUF, + how == M_TRYWAIT ? M_WAITOK : M_NOWAIT); + if (bucket == NULL) + return (NULL); + + p = (caddr_t)kmem_malloc(mb_list->map, PAGE_SIZE, + how == M_TRYWAIT ? M_WAITOK : M_NOWAIT); + if (p == NULL) { + free(bucket, M_MBUF); + return (NULL); + } + + bucket->num_free = 0; + mb_list->b_table[MB_BUCKET_INDX(p, mb_list)] = bucket; + for (i = 0; i < (PAGE_SIZE / mb_list->obj_size); i++) { + bucket->free[i] = p; + bucket->num_free++; + p += mb_list->obj_size; + } + + MB_LOCK_CONT(cnt_lst); + bucket->bckt_owner = cnt_lst->mb_cont.num_owner; + SLIST_INSERT_HEAD(&(cnt_lst->mb_cont.buck_head), bucket, buck_list); + cnt_lst->obj_count += bucket->num_free; + + return (bucket); +} + +/* + * Allocate an object residing in a submap of mb_map. + * The general case is very easy. Complications only arise if our PCPU + * container is empty. Things get worse if the PCPU container is empty, + * the general container is empty, and we've run out of address space + * in our map; then we try to block if we're willing to (M_TRYWAIT). + */ +void * +mb_alloc(struct mb_lstmngr *mb_list, int how) +{ + struct mb_pcpu_list *cnt_lst; + struct mb_bucket *bucket; + void *m; + + m = NULL; + cnt_lst = MB_GET_PCPU_LIST(mb_list); + MB_LOCK_CONT(cnt_lst); + + if ((bucket = SLIST_FIRST(&(cnt_lst->mb_cont.buck_head))) != NULL) { + /* + * This is the easy allocation case. We just grab an object + * from a bucket in the PCPU container. At worst, we + * have just emptied the bucket and so we remove it + * from the container. + */ + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + cnt_lst->obj_count--; + if (bucket->num_free == 0) { + /* + * The bucket is now empty, so mark it so after it has + * been removed from the PCPU list on which it sits. + */ + SLIST_REMOVE_HEAD(&(cnt_lst->mb_cont.buck_head), + buck_list); + SLIST_NEXT(bucket, buck_list) = NULL; + bucket->bckt_owner |= MB_BUCKET_FREE; + } + MB_UNLOCK_CONT(cnt_lst); + } else { + struct mb_gen_list *gen_list; + + /* + * This is the less-common more difficult case. We must + * first verify if the general list has anything for us + * and if that also fails, we must allocate a page from + * the map and create a new bucket to place in our PCPU + * container (already locked). If the map is starved then + * we're really in for trouble, as we have to wait on + * the general container's condition variable. + */ + gen_list = MB_GET_GEN_LIST(mb_list); + MB_LOCK_CONT(gen_list); + + if ((bucket = SLIST_FIRST(&(gen_list->mb_cont.buck_head))) + != NULL) { + /* + * Give ownership of the bucket to our CPU's + * container, but only actually put the bucket + * in the container if it doesn't become free + * upon removing an mbuf from it. + */ + SLIST_REMOVE_HEAD(&(gen_list->mb_cont.buck_head), + buck_list); + bucket->bckt_owner = cnt_lst->mb_cont.num_owner; + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + if (bucket->num_free == 0) { + SLIST_NEXT(bucket, buck_list) = NULL; + bucket->bckt_owner |= MB_BUCKET_FREE; + } else { + SLIST_INSERT_HEAD(&(cnt_lst->mb_cont.buck_head), + bucket, buck_list); + cnt_lst->obj_count += bucket->num_free; + } + MB_UNLOCK_CONT(gen_list); + MB_UNLOCK_CONT(cnt_lst); + } else { + /* + * We'll have to allocate a new page. + */ + MB_UNLOCK_CONT(gen_list); + bucket = mb_pop_cont(mb_list, how, cnt_lst); + if (bucket != NULL) { + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + cnt_lst->obj_count--; + MB_UNLOCK_CONT(cnt_lst); + } else if (how == M_TRYWAIT) + /* + * Absolute worst-case scenario. We block if we're + * willing to, but only after trying to steal from + * other lists. + */ + m = mb_alloc_wait(mb_list); + } + } + + return (m); +} + +/* + * This is the worst-case scenario called only if we're allocating with + * M_TRYWAIT. We first drain all the protocols, then try to find an mbuf + * by looking in every PCPU container. If we're still unsuccesful, we + * try the general container one last time and possibly block on our + * starved cv. + */ +void * +mb_alloc_wait(struct mb_lstmngr *mb_list) +{ + struct mb_pcpu_list *cnt_lst; + struct mb_gen_list *gen_list; + struct mb_bucket *bucket; + void *m; + int i, cv_ret; + + /* + * Try to reclaim mbuf-related objects (mbufs, clusters). + */ + mb_reclaim(); + + /* + * Cycle all the PCPU containers. Increment starved counts if found + * empty. + */ + for (i = 0; i < NCPU; i++) { + cnt_lst = MB_GET_PCPU_LIST_NUM(mb_list, i); + MB_LOCK_CONT(cnt_lst); + + /* + * If container is non-empty, steal a single object from it. + * If empty, increment starved count. + */ + if ((bucket = SLIST_FIRST(&(cnt_lst->mb_cont.buck_head))) != + NULL) { + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + cnt_lst->obj_count--; + if (bucket->num_free == 0) { + SLIST_REMOVE_HEAD(&(cnt_lst->mb_cont.buck_head), + buck_list); + SLIST_NEXT(bucket, buck_list) = NULL; + bucket->bckt_owner |= MB_BUCKET_FREE; + } + MB_UNLOCK_CONT(cnt_lst); + return (m); + } else + cnt_lst->mb_cont.starved++; + + MB_UNLOCK_CONT(cnt_lst); + } + + /* + * We're still here, so that means it's time to get the general + * container lock, check it one more time (now that mb_reclaim() + * has been called) and if we still get nothing, block on the cv. + */ + gen_list = MB_GET_GEN_LIST(mb_list); + MB_LOCK_CONT(gen_list); + if ((bucket = SLIST_FIRST(&(gen_list->mb_cont.buck_head))) != NULL) { + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + if (bucket->num_free == 0) { + SLIST_REMOVE_HEAD(&(gen_list->mb_cont.buck_head), + buck_list); + SLIST_NEXT(bucket, buck_list) = NULL; + bucket->bckt_owner |= MB_BUCKET_FREE; + } + MB_UNLOCK_CONT(gen_list); + return (m); + } + + gen_list->mb_cont.starved++; + cv_ret = cv_timedwait(&(gen_list->m_starved), + gen_list->mb_cont.mtx_lock, mbuf_wait); + gen_list->mb_cont.starved--; + + if ((cv_ret == 0) && + ((bucket = SLIST_FIRST(&(gen_list->mb_cont.buck_head))) != NULL)) { + bucket->num_free--; + m = bucket->free[(bucket->num_free)]; + if (bucket->num_free == 0) { + SLIST_REMOVE_HEAD( + &(gen_list->mb_cont.buck_head), buck_list); + SLIST_NEXT(bucket, buck_list) = NULL; + bucket->bckt_owner |= MB_BUCKET_FREE; + } + } else + m = NULL; + + MB_UNLOCK_CONT(gen_list); + return (m); +} + +/* + * Free an object to its rightful container. + * In the very general case, this operation is really very easy. + * Complications arise primarily if: + * (a) We've hit the high limit on number of free objects allowed in + * our PCPU container. + * (b) We're in a critical situation where our container has been + * marked 'starved' and we need to issue wakeups on the starved + * condition variable. + * (c) Minor (odd) cases: our bucket has migrated while we were + * waiting for the lock; our bucket is in the general container; + * our bucket is empty. + */ +void +mb_free(struct mb_lstmngr *mb_list, void *m) +{ + struct mb_pcpu_list *cnt_lst; + struct mb_gen_list *gen_list; + struct mb_bucket *bucket; + u_int owner; + + bucket = mb_list->b_table[MB_BUCKET_INDX(m, mb_list)]; + + /* + * Make sure that if after we lock the bucket's present container the + * bucket has migrated, that we drop the lock and get the new one. + */ +retry_lock: + owner = bucket->bckt_owner & ~MB_BUCKET_FREE; + switch (owner) { + case MB_GENLIST_OWNER: + gen_list = MB_GET_GEN_LIST(mb_list); + MB_LOCK_CONT(gen_list); + if (owner != (bucket->bckt_owner & ~MB_BUCKET_FREE)) { + MB_UNLOCK_CONT(gen_list); + goto retry_lock; + } + + /* + * If we're intended for the general container, this is + * real easy: no migrating required. The only `bogon' + * is that we're now contending with all the threads + * dealing with the general list, but this is expected. + */ + bucket->free[(bucket->num_free)] = m; + bucket->num_free++; + if (gen_list->mb_cont.starved > 0) + cv_signal(&(gen_list->m_starved)); + MB_UNLOCK_CONT(gen_list); + break; + + default: + cnt_lst = MB_GET_PCPU_LIST_NUM(mb_list, owner); + MB_LOCK_CONT(cnt_lst); + if (owner != (bucket->bckt_owner & ~MB_BUCKET_FREE)) { + MB_UNLOCK_CONT(cnt_lst); + goto retry_lock; + } + + bucket->free[(bucket->num_free)] = m; + bucket->num_free++; + cnt_lst->obj_count++; + + if (cnt_lst->mb_cont.starved > 0) { + /* + * This is a tough case. It means that we've + * been flagged at least once to indicate that + * we're empty, and that the system is in a critical + * situation, so we ought to migrate at least one + * bucket over to the general container. + * There may or may not be a thread blocking on + * the starved condition variable, but chances + * are that one will eventually come up soon so + * it's better to migrate now than never. + */ + gen_list = MB_GET_GEN_LIST(mb_list); + MB_LOCK_CONT(gen_list); + SLIST_INSERT_HEAD(&(gen_list->mb_cont.buck_head), + bucket, buck_list); + bucket->bckt_owner = MB_GENLIST_OWNER; + cnt_lst->obj_count--; + + /* + * Determine whether or not to keep transferring + * buckets to the general list or whether we've + * transferred enough already. + * We realize that although we may flag another + * bucket to be migrated to the general container + * that in the meantime, the thread that was + * blocked on the cv is already woken up and + * long gone. But in that case, the worst + * consequence is that we will end up migrating + * one bucket too many, which is really not a big + * deal, especially if we're close to a critical + * situation. + */ + if (gen_list->mb_cont.starved > 0) { + cnt_lst->mb_cont.starved--; + cv_signal(&(gen_list->m_starved)); + } else + cnt_lst->mb_cont.starved = 0; + + MB_UNLOCK_CONT(gen_list); + MB_UNLOCK_CONT(cnt_lst); + break; + } + + if (cnt_lst->obj_count > *(mb_list->wm_high)) { + /* + * We've hit the high limit of allowed numbers of mbufs + * on this PCPU list. We must now migrate a bucket + * over to the general container. + */ + gen_list = MB_GET_GEN_LIST(mb_list); + MB_LOCK_CONT(gen_list); + if ((bucket->bckt_owner & MB_BUCKET_FREE) == 0) { + bucket = + SLIST_FIRST(&(cnt_lst->mb_cont.buck_head)); + SLIST_REMOVE_HEAD(&(cnt_lst->mb_cont.buck_head), + buck_list); + } + SLIST_INSERT_HEAD(&(gen_list->mb_cont.buck_head), + bucket, buck_list); + bucket->bckt_owner = MB_GENLIST_OWNER; + cnt_lst->obj_count -= bucket->num_free; + + MB_UNLOCK_CONT(gen_list); + MB_UNLOCK_CONT(cnt_lst); + break; + } + + if (bucket->bckt_owner & MB_BUCKET_FREE) { + SLIST_INSERT_HEAD(&(cnt_lst->mb_cont.buck_head), + bucket, buck_list); + bucket->bckt_owner = cnt_lst->mb_cont.num_owner; + } + + MB_UNLOCK_CONT(cnt_lst); + break; + } + + return; +} + +/* + * Drain protocols in hopes to free up some resources. + * + * LOCKING NOTES: + * No locks should be held when this is called. The drain routines have to + * presently acquire some locks which raises the possibility of lock order + * violation if we're holding any mutex if that mutex is acquired in reverse + * order relative to one of the locks in the drain routines. + */ +void +mb_reclaim(void) +{ + struct domain *dp; + struct protosw *pr; + +#ifdef WITNESS + KASSERT(witness_list(curproc) == 0, + ("mb_reclaim() called with locks held")); +#endif + + for (dp = domains; dp; dp = dp->dom_next) + for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) + if (pr->pr_drain) + (*pr->pr_drain)(); + +} diff -ruN /usr/src/sys.old/kern/uipc_mbuf.c /usr/src/sys/kern/uipc_mbuf.c --- /usr/src/sys.old/kern/uipc_mbuf.c Sun Apr 29 15:29:14 2001 +++ /usr/src/sys/kern/uipc_mbuf.c Sun Apr 29 15:34:18 2001 @@ -31,48 +31,22 @@ * SUCH DAMAGE. * * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94 - * $FreeBSD: src/sys/kern/uipc_mbuf.c,v 1.74 2001/04/18 23:54:10 bmilekic Exp $ + * $FreeBSD: src/sys/kern/uipc_mbuf.c,v 1.73 2001/04/03 04:50:08 bmilekic Exp $ */ #include "opt_param.h" #include #include -#include #include -#include -#include #include #include #include #include -#include -#include -#include - -static void mbinit(void *); -SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbinit, NULL) - -struct mbuf *mbutl; -struct mbstat mbstat; -u_long mbtypes[MT_NTYPES]; + int max_linkhdr; int max_protohdr; int max_hdr; int max_datalen; -int nmbclusters; -int nmbufs; -int nmbcnt; -u_long m_mballoc_wid = 0; -u_long m_clalloc_wid = 0; - -/* - * freelist header structures... - * mbffree_lst, mclfree_lst, mcntfree_lst - */ -struct mbffree_lst mmbfree; -struct mclfree_lst mclfree; -struct mcntfree_lst mcntfree; -struct mtx mbuf_mtx; /* * sysctl(8) exported objects @@ -85,365 +59,6 @@ SYSCTL_INT(_kern_ipc, KIPC_MAX_HDR, max_hdr, CTLFLAG_RW, &max_hdr, 0, ""); SYSCTL_INT(_kern_ipc, KIPC_MAX_DATALEN, max_datalen, CTLFLAG_RW, &max_datalen, 0, ""); -SYSCTL_INT(_kern_ipc, OID_AUTO, mbuf_wait, CTLFLAG_RW, - &mbuf_wait, 0, ""); -SYSCTL_STRUCT(_kern_ipc, KIPC_MBSTAT, mbstat, CTLFLAG_RD, &mbstat, mbstat, ""); -SYSCTL_OPAQUE(_kern_ipc, OID_AUTO, mbtypes, CTLFLAG_RD, mbtypes, - sizeof(mbtypes), "LU", ""); -SYSCTL_INT(_kern_ipc, KIPC_NMBCLUSTERS, nmbclusters, CTLFLAG_RD, - &nmbclusters, 0, "Maximum number of mbuf clusters available"); -SYSCTL_INT(_kern_ipc, OID_AUTO, nmbufs, CTLFLAG_RD, &nmbufs, 0, - "Maximum number of mbufs available"); -SYSCTL_INT(_kern_ipc, OID_AUTO, nmbcnt, CTLFLAG_RD, &nmbcnt, 0, - "Maximum number of ext_buf counters available"); - -#ifndef NMBCLUSTERS -#define NMBCLUSTERS (512 + MAXUSERS * 16) -#endif - -TUNABLE_INT_DECL("kern.ipc.nmbclusters", NMBCLUSTERS, nmbclusters); -TUNABLE_INT_DECL("kern.ipc.nmbufs", NMBCLUSTERS * 4, nmbufs); -TUNABLE_INT_DECL("kern.ipc.nmbcnt", EXT_COUNTERS, nmbcnt); - -static void m_reclaim(void); - -/* Initial allocation numbers */ -#define NCL_INIT 2 -#define NMB_INIT 16 -#define REF_INIT NMBCLUSTERS - -/* - * Full mbuf subsystem initialization done here. - * - * XXX: If ever we have system specific map setups to do, then move them to - * machdep.c - for now, there is no reason for this stuff to go there. - */ -static void -mbinit(void *dummy) -{ - vm_offset_t maxaddr; - vm_size_t mb_map_size; - - /* - * Setup the mb_map, allocate requested VM space. - */ - mb_map_size = (vm_size_t)(nmbufs * MSIZE + nmbclusters * MCLBYTES + - nmbcnt * sizeof(union mext_refcnt)); - mb_map_size = rounddown(mb_map_size, PAGE_SIZE); - mb_map = kmem_suballoc(kmem_map, (vm_offset_t *)&mbutl, &maxaddr, - mb_map_size); - /* XXX XXX XXX: mb_map->system_map = 1; */ - - /* - * Initialize the free list headers, and setup locks for lists. - */ - mmbfree.m_head = NULL; - mclfree.m_head = NULL; - mcntfree.m_head = NULL; - mtx_init(&mbuf_mtx, "mbuf free list lock", MTX_DEF); - cv_init(&mmbfree.m_starved, "mbuf free list starved cv"); - cv_init(&mclfree.m_starved, "mbuf cluster free list starved cv"); - - /* - * Initialize mbuf subsystem (sysctl exported) statistics structure. - */ - mbstat.m_msize = MSIZE; - mbstat.m_mclbytes = MCLBYTES; - mbstat.m_minclsize = MINCLSIZE; - mbstat.m_mlen = MLEN; - mbstat.m_mhlen = MHLEN; - - /* - * Perform some initial allocations. - */ - mtx_lock(&mbuf_mtx); - if (m_alloc_ref(REF_INIT, M_DONTWAIT) == 0) - goto bad; - if (m_mballoc(NMB_INIT, M_DONTWAIT) == 0) - goto bad; - if (m_clalloc(NCL_INIT, M_DONTWAIT) == 0) - goto bad; - mtx_unlock(&mbuf_mtx); - - return; -bad: - panic("mbinit: failed to initialize mbuf subsystem!"); -} - -/* - * Allocate at least nmb reference count structs and place them - * on the ref cnt free list. - * - * Must be called with the mcntfree lock held. - */ -int -m_alloc_ref(u_int nmb, int how) -{ - caddr_t p; - u_int nbytes; - int i; - - /* - * We don't cap the amount of memory that can be used - * by the reference counters, like we do for mbufs and - * mbuf clusters. In fact, we're absolutely sure that we - * won't ever be going over our allocated space. We keep enough - * space in mb_map to accomodate maximum values of allocatable - * external buffers including, but not limited to, clusters. - * (That's also why we won't have to have wait routines for - * counters). - * - * If we're in here, we're absolutely certain to be returning - * succesfully, as long as there is physical memory to accomodate - * us. And if there isn't, but we're willing to wait, then - * kmem_malloc() will do the only waiting needed. - */ - - nbytes = round_page(nmb * sizeof(union mext_refcnt)); - if (1 /* XXX: how == M_TRYWAIT */) - mtx_unlock(&mbuf_mtx); - if ((p = (caddr_t)kmem_malloc(mb_map, nbytes, how == M_TRYWAIT ? - M_WAITOK : M_NOWAIT)) == NULL) { - if (1 /* XXX: how == M_TRYWAIT */) - mtx_lock(&mbuf_mtx); - return (0); - } - nmb = nbytes / sizeof(union mext_refcnt); - - /* - * We don't let go of the mutex in order to avoid a race. - * It is up to the caller to let go of the mutex. - */ - if (1 /* XXX: how == M_TRYWAIT */) - mtx_lock(&mbuf_mtx); - for (i = 0; i < nmb; i++) { - ((union mext_refcnt *)p)->next_ref = mcntfree.m_head; - mcntfree.m_head = (union mext_refcnt *)p; - p += sizeof(union mext_refcnt); - mbstat.m_refree++; - } - mbstat.m_refcnt += nmb; - - return (1); -} - -/* - * Allocate at least nmb mbufs and place on mbuf free list. - * - * Must be called with the mmbfree lock held. - */ -int -m_mballoc(int nmb, int how) -{ - caddr_t p; - int i; - int nbytes; - - nbytes = round_page(nmb * MSIZE); - nmb = nbytes / MSIZE; - - /* - * If we've hit the mbuf limit, stop allocating from mb_map. - * Also, once we run out of map space, it will be impossible to - * get any more (nothing is ever freed back to the map). - */ - if (mb_map_full || ((nmb + mbstat.m_mbufs) > nmbufs)) - return (0); - - if (1 /* XXX: how == M_TRYWAIT */) - mtx_unlock(&mbuf_mtx); - p = (caddr_t)kmem_malloc(mb_map, nbytes, how == M_TRYWAIT ? - M_WAITOK : M_NOWAIT); - if (1 /* XXX: how == M_TRYWAIT */) { - mtx_lock(&mbuf_mtx); - if (p == NULL) - mbstat.m_wait++; - } - - /* - * Either the map is now full, or `how' is M_DONTWAIT and there - * are no pages left. - */ - if (p == NULL) - return (0); - - /* - * We don't let go of the mutex in order to avoid a race. - * It is up to the caller to let go of the mutex when done - * with grabbing the mbuf from the free list. - */ - for (i = 0; i < nmb; i++) { - ((struct mbuf *)p)->m_next = mmbfree.m_head; - mmbfree.m_head = (struct mbuf *)p; - p += MSIZE; - } - mbstat.m_mbufs += nmb; - mbtypes[MT_FREE] += nmb; - return (1); -} - -/* - * Once the mb_map has been exhausted and if the call to the allocation macros - * (or, in some cases, functions) is with M_TRYWAIT, then it is necessary to - * rely solely on reclaimed mbufs. - * - * Here we request for the protocols to free up some resources and, if we - * still cannot get anything, then we wait for an mbuf to be freed for a - * designated (mbuf_wait) time, at most. - * - * Must be called with the mmbfree mutex held. - */ -struct mbuf * -m_mballoc_wait(void) -{ - struct mbuf *p = NULL; - - /* - * See if we can drain some resources out of the protocols. - * We drop the mmbfree mutex to avoid recursing into it in some of - * the drain routines. Clearly, we're faced with a race here because - * once something is freed during the drain, it may be grabbed right - * from under us by some other thread. But we accept this possibility - * in order to avoid a potentially large lock recursion and, more - * importantly, to avoid a potential lock order reversal which may - * result in deadlock (See comment above m_reclaim()). - */ - mtx_unlock(&mbuf_mtx); - m_reclaim(); - - mtx_lock(&mbuf_mtx); - _MGET(p, M_DONTWAIT); - - if (p == NULL) { - int retval; - - m_mballoc_wid++; - retval = cv_timedwait(&mmbfree.m_starved, &mbuf_mtx, - mbuf_wait); - m_mballoc_wid--; - - /* - * If we got signaled (i.e. didn't time out), allocate. - */ - if (retval == 0) - _MGET(p, M_DONTWAIT); - } - - if (p != NULL) { - mbstat.m_wait++; - if (mmbfree.m_head != NULL) - MBWAKEUP(m_mballoc_wid, &mmbfree.m_starved); - } - - return (p); -} - -/* - * Allocate some number of mbuf clusters - * and place on cluster free list. - * - * Must be called with the mclfree lock held. - */ -int -m_clalloc(int ncl, int how) -{ - caddr_t p; - int i; - int npg_sz; - - npg_sz = round_page(ncl * MCLBYTES); - ncl = npg_sz / MCLBYTES; - - /* - * If the map is now full (nothing will ever be freed to it). - * If we've hit the mcluster number limit, stop allocating from - * mb_map. - */ - if (mb_map_full || ((ncl + mbstat.m_clusters) > nmbclusters)) - return (0); - - if (1 /* XXX: how == M_TRYWAIT */) - mtx_unlock(&mbuf_mtx); - p = (caddr_t)kmem_malloc(mb_map, npg_sz, - how == M_TRYWAIT ? M_WAITOK : M_NOWAIT); - if (1 /* XXX: how == M_TRYWAIT */) - mtx_lock(&mbuf_mtx); - - /* - * Either the map is now full, or `how' is M_DONTWAIT and there - * are no pages left. - */ - if (p == NULL) - return (0); - - for (i = 0; i < ncl; i++) { - ((union mcluster *)p)->mcl_next = mclfree.m_head; - mclfree.m_head = (union mcluster *)p; - p += MCLBYTES; - mbstat.m_clfree++; - } - mbstat.m_clusters += ncl; - return (1); -} - -/* - * Once the mb_map submap has been exhausted and the allocation is called with - * M_TRYWAIT, we rely on the mclfree list. If nothing is free, we will - * block on a cv for a designated amount of time (mbuf_wait) or until we're - * signaled due to sudden mcluster availability. - * - * Must be called with the mclfree lock held. - */ -caddr_t -m_clalloc_wait(void) -{ - caddr_t p = NULL; - int retval; - - m_clalloc_wid++; - retval = cv_timedwait(&mclfree.m_starved, &mbuf_mtx, mbuf_wait); - m_clalloc_wid--; - - /* - * Now that we (think) that we've got something, try again. - */ - if (retval == 0) - _MCLALLOC(p, M_DONTWAIT); - - if (p != NULL) { - mbstat.m_wait++; - if (mclfree.m_head != NULL) - MBWAKEUP(m_clalloc_wid, &mclfree.m_starved); - } - - return (p); -} - -/* - * m_reclaim: drain protocols in hopes to free up some resources... - * - * XXX: No locks should be held going in here. The drain routines have - * to presently acquire some locks which raises the possibility of lock - * order violation if we're holding any mutex if that mutex is acquired in - * reverse order relative to one of the locks in the drain routines. - */ -static void -m_reclaim(void) -{ - struct domain *dp; - struct protosw *pr; - -#ifdef WITNESS - KASSERT(witness_list(curproc) == 0, - ("m_reclaim called with locks held")); -#endif - - for (dp = domains; dp; dp = dp->dom_next) - for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) - if (pr->pr_drain) - (*pr->pr_drain)(); - mbstat.m_drain++; -} /* * Space allocation routines. @@ -665,16 +280,16 @@ np = &n->m_next; } if (top == NULL) { - mtx_lock(&mbuf_mtx); + /* mbstat.m_mcfail++; - mtx_unlock(&mbuf_mtx); + */ } return (top); nospace: m_freem(top); - mtx_lock(&mbuf_mtx); + /* mbstat.m_mcfail++; - mtx_unlock(&mbuf_mtx); + */ return (NULL); } @@ -733,9 +348,7 @@ return top; nospace: m_freem(top); - mtx_lock(&mbuf_mtx); - mbstat.m_mcfail++; - mtx_unlock(&mbuf_mtx); + /* mbstat.m_mcfail++; */ return (NULL); } @@ -836,9 +449,7 @@ nospace: m_freem(top); - mtx_lock(&mbuf_mtx); - mbstat.m_mcfail++; - mtx_unlock(&mbuf_mtx); + /* mbstat.m_mcfail++; */ return (NULL); } @@ -1000,9 +611,7 @@ return (m); bad: m_freem(n); - mtx_lock(&mbuf_mtx); - mbstat.m_mcfail++; - mtx_unlock(&mbuf_mtx); + /* mbstat.m_mcfail++; */ return (NULL); } diff -ruN /usr/src/sys.old/sys/mbuf.h /usr/src/sys/sys/mbuf.h --- /usr/src/sys.old/sys/mbuf.h Sun Apr 29 15:29:37 2001 +++ /usr/src/sys/sys/mbuf.h Sun Apr 29 15:34:34 2001 @@ -31,48 +31,28 @@ * SUCH DAMAGE. * * @(#)mbuf.h 8.5 (Berkeley) 2/19/95 - * $FreeBSD: src/sys/sys/mbuf.h,v 1.77 2001/04/18 23:54:13 bmilekic Exp $ + * $FreeBSD: src/sys/sys/mbuf.h,v 1.76 2001/04/05 03:55:27 bmilekic Exp $ */ #ifndef _SYS_MBUF_H_ #define _SYS_MBUF_H_ -#ifdef _KERNEL -#include /* XXX */ -#include /* XXX */ -#include /* XXX */ -#endif /* _KERNEL */ +#define NCPU 2 /* XXX: Not good! */ /* * Mbufs are of a single size, MSIZE (machine/param.h), which * includes overhead. An mbuf may add a single "mbuf cluster" of size * MCLBYTES (also in machine/param.h), which has no additional overhead * and is used instead of the internal data area; this is done when - * at least MINCLSIZE of data must be stored. + * at least MINCLSIZE of data must be stored. Additionally, it is possible + * to allocate a separate buffer externally and attach it to the mbuf in + * a way similar to that of mbuf clusters. */ - #define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ #define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ - #define MINCLSIZE (MHLEN + 1) /* smallest amount to put in cluster */ #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */ -/* - * Maximum number of allocatable counters for external buffers. This - * ensures enough VM address space for the allocation of counters - * in the extreme case where all possible external buffers are allocated. - * - * Note: When new types of external storage are allocated, EXT_COUNTERS - * must be tuned accordingly. Practically, this isn't a big deal - * as each counter is only a word long, so we can fit - * (PAGE_SIZE / length of word) counters in a single page. - * - * XXX: Must increase this if using any of if_ti, if_wb, if_sk drivers, - * or any other drivers which may manage their own buffers and - * eventually attach them to mbufs. - */ -#define EXT_COUNTERS (nmbclusters + nsfbufs) - #ifdef _KERNEL /* * Macros for type conversion @@ -83,7 +63,9 @@ #define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1))) #endif /* _KERNEL */ -/* header at beginning of each mbuf: */ +/* + * Header present at the beginning of every mbuf. + */ struct m_hdr { struct mbuf *mh_next; /* next buffer in chain */ struct mbuf *mh_nextpkt; /* next chain in queue/record */ @@ -93,7 +75,9 @@ short mh_flags; /* flags; see below */ }; -/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */ +/* + * Record/packet header in first mbuf of chain; valid only if M_PKTHDR is set. + */ struct pkthdr { struct ifnet *rcvif; /* rcv interface */ int len; /* total packet length */ @@ -105,17 +89,23 @@ struct mbuf *aux; /* extra data buffer; ipsec/others */ }; -/* description of external storage mapped into mbuf, valid if M_EXT set */ +/* + * Description of external storage mapped into mbuf; valid only if M_EXT is set. + */ struct m_ext { caddr_t ext_buf; /* start of buffer */ void (*ext_free) /* free routine if not the usual */ (caddr_t, void *); void *ext_args; /* optional argument pointer */ u_int ext_size; /* size of buffer, for ext_free */ - union mext_refcnt *ref_cnt; /* pointer to ref count info */ + struct mext_refcnt *ref_cnt; /* pointer to ref count info */ int ext_type; /* type of external storage */ }; +/* + * The core of the mbuf object along with some shortcut defines for + * practical purposes. + */ struct mbuf { struct m_hdr m_hdr; union { @@ -141,7 +131,9 @@ #define m_pktdat M_dat.MH.MH_dat.MH_databuf #define m_dat M_dat.M_databuf -/* mbuf flags */ +/* + * mbuf flags + */ #define M_EXT 0x0001 /* has associated external storage */ #define M_PKTHDR 0x0002 /* start of record */ #define M_EOR 0x0004 /* end of record */ @@ -152,24 +144,32 @@ #define M_PROTO4 0x0080 /* protocol-specific */ #define M_PROTO5 0x0100 /* protocol-specific */ -/* mbuf pkthdr flags, also in m_flags */ +/* + * mbuf pkthdr flags (also stored in m_flags) + */ #define M_BCAST 0x0200 /* send/received as link-level broadcast */ #define M_MCAST 0x0400 /* send/received as link-level multicast */ #define M_FRAG 0x0800 /* packet is a fragment of a larger packet */ #define M_FIRSTFRAG 0x1000 /* packet is first fragment */ #define M_LASTFRAG 0x2000 /* packet is last fragment */ -/* external buffer types: identify ext_buf type */ +/* + * External buffer types: identify ext_buf type + */ #define EXT_CLUSTER 1 /* mbuf cluster */ #define EXT_SFBUF 2 /* sendfile(2)'s sf_bufs */ #define EXT_NET_DRV 100 /* custom ext_buf provided by net driver(s) */ #define EXT_MOD_TYPE 200 /* custom module's ext_buf type */ -/* flags copied when copying m_pkthdr */ +/* + * Flags copied when copying m_pkthdr + */ #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_PROTO1|M_PROTO2|M_PROTO3 | \ M_PROTO4|M_PROTO5|M_BCAST|M_MCAST|M_FRAG|M_RDONLY) -/* flags indicating hw checksum support and sw checksum requirements */ +/* + * Flags indicating hw checksum support and sw checksum requirements + */ #define CSUM_IP 0x0001 /* will csum IP */ #define CSUM_TCP 0x0002 /* will csum TCP */ #define CSUM_UDP 0x0004 /* will csum UDP */ @@ -184,7 +184,9 @@ #define CSUM_DELAY_DATA (CSUM_TCP | CSUM_UDP) #define CSUM_DELAY_IP (CSUM_IP) /* XXX add ipv6 here too? */ -/* mbuf types */ +/* + * mbuf types + */ #define MT_FREE 0 /* should be on free list */ #define MT_DATA 1 /* dynamic (data) allocation */ #define MT_HEADER 2 /* packet header */ @@ -208,16 +210,16 @@ #define MT_OOBDATA 15 /* expedited data */ #define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */ +#if 0 /* * mbuf statistics */ struct mbstat { - u_long m_mbufs; /* # mbufs obtained from page pool */ - u_long m_clusters; /* # clusters obtained from page pool */ - u_long m_clfree; /* # clusters on freelist (cache) */ - u_long m_refcnt; /* # ref counters obtained from page pool */ - u_long m_refree; /* # ref counters on freelist (cache) */ - u_long m_spare; /* spare field */ + u_long m_mbufs; /* num. mbufs obtained from mb_map */ + u_long m_clusters; /* num. clusters obtained from mb_map */ + u_long m_clfree; /* num. clusters on freelist (cache) */ + u_long m_refcnt; /* num. ref counters obtained from mb_map */ + u_long m_refree; /* num. ref counters on freelist (cache) */ u_long m_drops; /* times failed to find space */ u_long m_wait; /* times waited for space */ u_long m_drain; /* times drained protocols for space */ @@ -228,66 +230,30 @@ u_long m_minclsize; /* min length of data to allocate a cluster */ u_long m_mlen; /* length of data in an mbuf */ u_long m_mhlen; /* length of data in a header mbuf */ + u_long m_spare; /* spare field */ }; +#endif -/* flags to m_get/MGET */ +/* + * Flags specifying how an allocation should be made. + * M_DONTWAIT means "don't block if nothing is available" whereas + * M_TRYWAIT means "block for mbuf_wait ticks at most if nothing is + * available." + */ #define M_DONTWAIT 1 #define M_TRYWAIT 0 #define M_WAIT M_TRYWAIT /* XXX: Deprecated. */ /* - * Normal mbuf clusters are normally treated as character arrays - * after allocation, but use the first word of the buffer as a free list - * pointer while on the free list. - */ -union mcluster { - union mcluster *mcl_next; - char mcl_buf[MCLBYTES]; -}; - -/* * The m_ext object reference counter structure. + * XXX: Useless. Do something with this. */ -union mext_refcnt { - union mext_refcnt *next_ref; +struct mext_refcnt { u_int refcnt; }; #ifdef _KERNEL /* - * The freelists for mbufs and mbuf clusters include condition variables - * that are used in cases of depletion/starvation. - * The counter freelist does not require a condition variable as we never - * expect to consume more than the reserved address space for counters. - * All are presently protected by the mbuf_mtx lock. - */ -struct mbffree_lst { - struct mbuf *m_head; - struct cv m_starved; -}; - -struct mclfree_lst { - union mcluster *m_head; - struct cv m_starved; -}; - -struct mcntfree_lst { - union mext_refcnt *m_head; -}; - -/* - * Signal a single instance (if any) blocked on a m_starved cv (i.e. an - * instance waiting for an {mbuf, cluster} to be freed to the global - * cache lists). - * - * Must be called with mbuf_mtx held. - */ -#define MBWAKEUP(m_wid, m_cv) do { \ - if ((m_wid) > 0) \ - cv_signal((m_cv)); \ -} while (0) - -/* * mbuf external reference count management macros: * * MEXT_IS_REF(m): true if (m) is not the only mbuf referencing @@ -307,38 +273,17 @@ #define MEXT_ADD_REF(m) atomic_add_int(&((m)->m_ext.ref_cnt->refcnt), 1) -#define _MEXT_ALLOC_CNT(m_cnt, how) do { \ - union mext_refcnt *__mcnt; \ - \ - mtx_lock(&mbuf_mtx); \ - if (mcntfree.m_head == NULL) \ - m_alloc_ref(1, (how)); \ - __mcnt = mcntfree.m_head; \ - if (__mcnt != NULL) { \ - mcntfree.m_head = __mcnt->next_ref; \ - mbstat.m_refree--; \ - __mcnt->refcnt = 0; \ - } \ - mtx_unlock(&mbuf_mtx); \ - (m_cnt) = __mcnt; \ -} while (0) +#define MEXT_DEALLOC_CNT(m_cnt) mb_free(&mb_list_cnt, (m_cnt)) -#define _MEXT_DEALLOC_CNT(m_cnt) do { \ - union mext_refcnt *__mcnt = (m_cnt); \ +#define MEXT_INIT_REF(m) do { \ + struct mbuf *__mmm = (m); \ \ - mtx_lock(&mbuf_mtx); \ - __mcnt->next_ref = mcntfree.m_head; \ - mcntfree.m_head = __mcnt; \ - mbstat.m_refree++; \ - mtx_unlock(&mbuf_mtx); \ -} while (0) - -#define MEXT_INIT_REF(m, how) do { \ - struct mbuf *__mmm = (m); \ - \ - _MEXT_ALLOC_CNT(__mmm->m_ext.ref_cnt, (how)); \ - if (__mmm->m_ext.ref_cnt != NULL) \ + __mmm->m_ext.ref_cnt = (struct mext_refcnt *)mb_alloc( \ + &mb_list_cnt, M_DONTWAIT); \ + if (__mmm->m_ext.ref_cnt != NULL) { \ + __mmm->m_ext.ref_cnt->refcnt = 0; \ MEXT_ADD_REF(__mmm); \ + } \ } while (0) /* @@ -351,76 +296,35 @@ * allocates an mbuf and initializes it to contain a packet header * and internal data. */ -/* - * Lower-level macros for MGET(HDR)... Not to be used outside the - * subsystem ("non-exportable" macro names are prepended with "_"). - */ -#define _MGET_SETUP(m_set, m_set_type) do { \ - (m_set)->m_type = (m_set_type); \ - (m_set)->m_next = NULL; \ - (m_set)->m_nextpkt = NULL; \ - (m_set)->m_data = (m_set)->m_dat; \ - (m_set)->m_flags = 0; \ -} while (0) - -#define _MGET(m_mget, m_get_how) do { \ - if (mmbfree.m_head == NULL) \ - m_mballoc(1, (m_get_how)); \ - (m_mget) = mmbfree.m_head; \ - if ((m_mget) != NULL) { \ - mmbfree.m_head = (m_mget)->m_next; \ - mbtypes[MT_FREE]--; \ - } else { \ - if ((m_get_how) == M_TRYWAIT) \ - (m_mget) = m_mballoc_wait(); \ - } \ -} while (0) - -#define MGET(m, how, type) do { \ - struct mbuf *_mm; \ - int _mhow = (how); \ - int _mtype = (type); \ +#define MGET(m, how, type) do { \ + struct mbuf *_mb; \ \ - mtx_lock(&mbuf_mtx); \ - _MGET(_mm, _mhow); \ - if (_mm != NULL) { \ - mbtypes[_mtype]++; \ - mtx_unlock(&mbuf_mtx); \ - _MGET_SETUP(_mm, _mtype); \ - } else { \ - mbstat.m_drops++; \ - mtx_unlock(&mbuf_mtx); \ + _mb = (struct mbuf *)mb_alloc(&mb_list_mbuf, (how)); \ + if (_mb != NULL) { \ + _mb->m_type = (type); \ + _mb->m_next = NULL; \ + _mb->m_nextpkt = NULL; \ + _mb->m_data = _mb->m_dat; \ + _mb->m_flags = 0; \ } \ - (m) = _mm; \ + (m) = _mb; \ } while (0) -#define _MGETHDR_SETUP(m_set, m_set_type) do { \ - (m_set)->m_type = (m_set_type); \ - (m_set)->m_next = NULL; \ - (m_set)->m_nextpkt = NULL; \ - (m_set)->m_data = (m_set)->m_pktdat; \ - (m_set)->m_flags = M_PKTHDR; \ - (m_set)->m_pkthdr.rcvif = NULL; \ - (m_set)->m_pkthdr.csum_flags = 0; \ - (m_set)->m_pkthdr.aux = NULL; \ -} while (0) - -#define MGETHDR(m, how, type) do { \ - struct mbuf *_mm; \ - int _mhow = (how); \ - int _mtype = (type); \ +#define MGETHDR(m, how, type) do { \ + struct mbuf *_mb; \ \ - mtx_lock(&mbuf_mtx); \ - _MGET(_mm, _mhow); \ - if (_mm != NULL) { \ - mbtypes[_mtype]++; \ - mtx_unlock(&mbuf_mtx); \ - _MGETHDR_SETUP(_mm, _mtype); \ - } else { \ - mbstat.m_drops++; \ - mtx_unlock(&mbuf_mtx); \ + _mb = (struct mbuf *)mb_alloc(&mb_list_mbuf, (how)); \ + if (_mb != NULL) { \ + _mb->m_type = (type); \ + _mb->m_next = NULL; \ + _mb->m_nextpkt = NULL; \ + _mb->m_data = _mb->m_pktdat; \ + _mb->m_flags = M_PKTHDR; \ + _mb->m_pkthdr.rcvif = NULL; \ + _mb->m_pkthdr.csum_flags = 0; \ + _mb->m_pkthdr.aux = NULL; \ } \ - (m) = _mm; \ + (m) = _mb; \ } while (0) /* @@ -431,33 +335,14 @@ * MEXTFREE removes reference to external object and frees it if * necessary */ -#define _MCLALLOC(p, how) do { \ - caddr_t _mp; \ - int _mhow = (how); \ - \ - if (mclfree.m_head == NULL) \ - m_clalloc(1, _mhow); \ - _mp = (caddr_t)mclfree.m_head; \ - if (_mp != NULL) { \ - mbstat.m_clfree--; \ - mclfree.m_head = ((union mcluster *)_mp)->mcl_next; \ - } else { \ - if (_mhow == M_TRYWAIT) \ - _mp = m_clalloc_wait(); \ - } \ - (p) = _mp; \ -} while (0) - #define MCLGET(m, how) do { \ - struct mbuf *_mm = (m); \ + struct mbuf *_mm = (m); \ \ - mtx_lock(&mbuf_mtx); \ - _MCLALLOC(_mm->m_ext.ext_buf, (how)); \ + _mm->m_ext.ext_buf = (caddr_t)mb_alloc(&mb_list_clust, (how)); \ if (_mm->m_ext.ext_buf != NULL) { \ - mtx_unlock(&mbuf_mtx); \ - MEXT_INIT_REF(_mm, (how)); \ + MEXT_INIT_REF(_mm); \ if (_mm->m_ext.ref_cnt == NULL) { \ - _MCLFREE(_mm->m_ext.ext_buf); \ + MCLFREE(_mm->m_ext.ext_buf); \ _mm->m_ext.ext_buf = NULL; \ } else { \ _mm->m_data = _mm->m_ext.ext_buf; \ @@ -467,16 +352,13 @@ _mm->m_ext.ext_size = MCLBYTES; \ _mm->m_ext.ext_type = EXT_CLUSTER; \ } \ - } else { \ - mbstat.m_drops++; \ - mtx_unlock(&mbuf_mtx); \ } \ } while (0) #define MEXTADD(m, buf, size, free, args, flags, type) do { \ - struct mbuf *_mm = (m); \ + struct mbuf *_mm = (m); \ \ - MEXT_INIT_REF(_mm, M_TRYWAIT); \ + MEXT_INIT_REF(_mm); \ if (_mm->m_ext.ref_cnt != NULL) { \ _mm->m_flags |= (M_EXT | (flags)); \ _mm->m_ext.ext_buf = (caddr_t)(buf); \ @@ -488,18 +370,10 @@ } \ } while (0) -#define _MCLFREE(p) do { \ - union mcluster *_mp = (union mcluster *)(p); \ - \ - mtx_lock(&mbuf_mtx); \ - _mp->mcl_next = mclfree.m_head; \ - mclfree.m_head = _mp; \ - mbstat.m_clfree++; \ - MBWAKEUP(m_clalloc_wid, &mclfree.m_starved); \ - mtx_unlock(&mbuf_mtx); \ -} while (0) +#define MCLFREE(p) mb_free(&mb_list_clust, (caddr_t)(p)) -/* MEXTFREE: +/* + * MEXTFREE: * If the atomic_cmpset_int() returns 0, then we effectively do nothing * in terms of "cleaning up" (freeing the ext buf and ref. counter) as * this means that either there are still references, or another thread @@ -514,8 +388,8 @@ (*(_mmm->m_ext.ext_free))(_mmm->m_ext.ext_buf, \ _mmm->m_ext.ext_args); \ } else \ - _MCLFREE(_mmm->m_ext.ext_buf); \ - _MEXT_DEALLOC_CNT(_mmm->m_ext.ref_cnt); \ + MCLFREE(_mmm->m_ext.ext_buf); \ + MEXT_DEALLOC_CNT(_mmm->m_ext.ref_cnt); \ } \ _mmm->m_flags &= ~M_EXT; \ } while (0) @@ -528,18 +402,11 @@ #define MFREE(m, n) do { \ struct mbuf *_mm = (m); \ \ - KASSERT(_mm->m_type != MT_FREE, ("freeing free mbuf")); \ + (n) = _mm->m_next; \ if (_mm->m_flags & M_EXT) \ MEXTFREE(_mm); \ - mtx_lock(&mbuf_mtx); \ - mbtypes[_mm->m_type]--; \ - _mm->m_type = MT_FREE; \ - mbtypes[MT_FREE]++; \ - (n) = _mm->m_next; \ - _mm->m_next = mmbfree.m_head; \ - mmbfree.m_head = _mm; \ - MBWAKEUP(m_mballoc_wid, &mmbfree.m_starved); \ - mtx_unlock(&mbuf_mtx); \ + mb_free(&mb_list_mbuf, _mm); \ + (m) = NULL; \ } while (0) /* @@ -626,16 +493,7 @@ /* * change mbuf to new type */ -#define MCHTYPE(m, t) do { \ - struct mbuf *_mm = (m); \ - int _mt = (t); \ - \ - mtx_lock(&mbuf_mtx); \ - mbtypes[_mm->m_type]--; \ - mbtypes[_mt]++; \ - mtx_unlock(&mbuf_mtx); \ - _mm->m_type = (_mt); \ -} while (0) +#define MCHTYPE(m, t) (m)->m_type = (t) /* length to m_copy to copy all */ #define M_COPYALL 1000000000 @@ -651,53 +509,46 @@ int type; }; -extern u_long m_clalloc_wid; /* mbuf cluster wait count */ -extern u_long m_mballoc_wid; /* mbuf wait count */ -extern int max_datalen; /* MHLEN - max_hdr */ -extern int max_hdr; /* largest link+protocol header */ -extern int max_linkhdr; /* largest link-level header */ -extern int max_protohdr; /* largest protocol header */ -extern struct mbstat mbstat; -extern u_long mbtypes[MT_NTYPES]; /* per-type mbuf allocations */ -extern int mbuf_wait; /* mbuf sleep time */ -extern struct mtx mbuf_mtx; -extern struct mbuf *mbutl; /* virtual address of mclusters */ -extern struct mclfree_lst mclfree; -extern struct mcntfree_lst mcntfree; -extern struct mbffree_lst mmbfree; -extern int nmbclusters; -extern int nmbcnt; -extern int nmbufs; -extern int nsfbufs; - -void m_adj(struct mbuf *, int); -int m_alloc_ref(u_int, int); -struct mbuf *m_aux_add(struct mbuf *, int, int); -void m_aux_delete(struct mbuf *, struct mbuf *); -struct mbuf *m_aux_find(struct mbuf *, int, int); -void m_cat(struct mbuf *, struct mbuf *); -int m_clalloc(int, int); -caddr_t m_clalloc_wait(void); -void m_copyback(struct mbuf *, int, int, caddr_t); -void m_copydata(struct mbuf *, int, int, caddr_t); -struct mbuf *m_copym(struct mbuf *, int, int, int); -struct mbuf *m_copypacket(struct mbuf *, int); -struct mbuf *m_devget(char *, int, int, struct ifnet *, - void (*copy)(char *, caddr_t, u_int)); -struct mbuf *m_dup(struct mbuf *, int); -struct mbuf *m_free(struct mbuf *); -void m_freem(struct mbuf *); -struct mbuf *m_get(int, int); -struct mbuf *m_getclr(int, int); -struct mbuf *m_gethdr(int, int); -struct mbuf *m_getm(struct mbuf *, int, int, int); -int m_mballoc(int, int); -struct mbuf *m_mballoc_wait(void); -struct mbuf *m_prepend(struct mbuf *, int, int); -void m_print(const struct mbuf *m); -struct mbuf *m_pulldown(struct mbuf *, int, int, int *); -struct mbuf *m_pullup(struct mbuf *, int); -struct mbuf *m_split(struct mbuf *, int, int); +extern int max_datalen; /* MHLEN - max_hdr */ +extern int max_hdr; /* largest link+protocol header */ +extern int max_linkhdr; /* largest link-level header */ +extern int max_protohdr; /* largest protocol header */ +/* extern struct mbstat mbstat; */ +extern int mbuf_wait; /* mbuf sleep time */ +extern int nmbclusters; +extern int nmbufs; +extern int nmbcnt; +extern int nsfbufs; +extern u_int mbuf_limit; +extern u_int clust_limit; +extern u_int cnt_limit; +extern struct mb_lstmngr mb_list_mbuf, mb_list_clust, mb_list_cnt; + +void *mb_alloc(struct mb_lstmngr *, int); +void mb_free(struct mb_lstmngr *, void *); +void m_adj(struct mbuf *, int); +struct mbuf *m_aux_add(struct mbuf *, int, int); +void m_aux_delete(struct mbuf *, struct mbuf *); +struct mbuf *m_aux_find(struct mbuf *, int, int); +void m_cat(struct mbuf *, struct mbuf *); +void m_copyback(struct mbuf *, int, int, caddr_t); +void m_copydata(struct mbuf *, int, int, caddr_t); +struct mbuf *m_copym(struct mbuf *, int, int, int); +struct mbuf *m_copypacket(struct mbuf *, int); +struct mbuf *m_devget(char *, int, int, struct ifnet *, + void (*copy)(char *, caddr_t, u_int)); +struct mbuf *m_dup(struct mbuf *, int); +struct mbuf *m_free(struct mbuf *); +void m_freem(struct mbuf *); +struct mbuf *m_get(int, int); +struct mbuf *m_getclr(int, int); +struct mbuf *m_gethdr(int, int); +struct mbuf *m_getm(struct mbuf *, int, int, int); +struct mbuf *m_prepend(struct mbuf *, int, int); +void m_print(const struct mbuf *m); +struct mbuf *m_pulldown(struct mbuf *, int, int, int *); +struct mbuf *m_pullup(struct mbuf *, int); +struct mbuf *m_split(struct mbuf *, int, int); #endif /* _KERNEL */ #endif /* !_SYS_MBUF_H_ */