Index: src/sys/kern/subr_mbuf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_mbuf.c,v retrieving revision 1.22 diff -u -r1.22 subr_mbuf.c --- src/sys/kern/subr_mbuf.c 23 Jul 2002 14:55:33 -0000 1.22 +++ src/sys/kern/subr_mbuf.c 24 Jul 2002 15:07:44 -0000 @@ -1352,6 +1352,54 @@ } /* + * Free an entire chain of mbufs and associated external buffers, if + * applicable. Right now, we only optimize a little so that the cache + * lock may be held across a single mbuf+cluster free. Hopefully, + * we'll eventually be holding the lock across more than merely two + * consecutive frees but right now this is hard to implement because of + * things like _mext_dealloc_ref (may do a free()) and atomic ops in the + * loop, as well as the fact that we may recurse on m_freem() in + * m_pkthdr.aux != NULL cases. + * + * - mb: the mbuf chain to free. + */ +void +m_freem(struct mbuf *mb) +{ + struct mbuf *m; + int cchnum; + short persist; + + while (mb != NULL) { + /* XXX: This check is bogus... please fix (see KAME). */ + if ((mb->m_flags & M_PKTHDR) != 0 && mb->m_pkthdr.aux) { + m_freem(mb->m_pkthdr.aux); + mb->m_pkthdr.aux = NULL; + } + persist = 0; + m = mb; + mb = mb->m_next; + if ((m->m_flags & M_EXT) != 0) { + MEXT_REM_REF(m); + if (atomic_cmpset_int(m->m_ext.ref_cnt, 0, 1)) { + _mext_dealloc_ref(m); + if (m->m_ext.ext_type == EXT_CLUSTER) { + mb_free(&mb_list_clust, + (caddr_t)m->m_ext.ext_buf, + MT_NOTMBUF, MBP_PERSIST, &cchnum); + persist = MBP_PERSISTENT; + } else { + (*(m->m_ext.ext_free))(m->m_ext.ext_buf, + m->m_ext.ext_args); + persist = 0; + } + } + } + mb_free(&mb_list_mbuf, m, m->m_type, persist, &cchnum); + } +} + +/* * Fetch an mbuf with a cluster attached to it. If one of the * allocations fails, the entire allocation fails. This routine is * the preferred way of fetching both the mbuf and cluster together, Index: src/sys/kern/uipc_mbuf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.93 diff -u -r1.93 uipc_mbuf.c --- src/sys/kern/uipc_mbuf.c 15 Jul 2002 15:32:46 -0000 1.93 +++ src/sys/kern/uipc_mbuf.c 24 Jul 2002 15:07:44 -0000 @@ -62,14 +62,6 @@ SYSCTL_INT(_kern_ipc, KIPC_MAX_DATALEN, max_datalen, CTLFLAG_RW, &max_datalen, 0, ""); -void -m_freem(struct mbuf *m) -{ - while (m) { - m = m_free(m); - } -} - /* * Lesser-used path for M_PREPEND: * allocate new mbuf to prepend to chain,