Enhanced mbuf/pool diagnostics patch - puts the caller of m_free into the pool history, rather than just the generic locations. Index: sys/mbuf.h =================================================================== RCS file: /cvs/src/sys/sys/mbuf.h,v retrieving revision 1.77 diff -u -r1.77 mbuf.h @@ -344,6 +346,25 @@ MCLINITREFERENCE(m); \ } while (/* CONSTCOND */ 0) +#ifdef POOL_DIAGNOSTIC +#define _MEXTREMOVE(m, f, l) do { \ + if (MCLISREFERENCED(m)) { \ + _MCLDEREFERENCE(m); \ + } else if ((m)->m_flags & M_CLUSTER) { \ + _pool_put(&mclpool, (m)->m_ext.ext_buf, f, l); \ + } else if ((m)->m_ext.ext_free) { \ + (*((m)->m_ext.ext_free))((m)->m_ext.ext_buf, \ + (m)->m_ext.ext_size, (m)->m_ext.ext_arg); \ + } else { \ + free((m)->m_ext.ext_buf,(m)->m_ext.ext_type); \ + } \ + (m)->m_flags &= ~(M_CLUSTER|M_EXT); \ + (m)->m_ext.ext_size = 0; /* why ??? */ \ +} while (/* CONSTCOND */ 0) + +#define MEXTREMOVE(m) \ + MBUFLOCK(_MEXTREMOVE((m), __FILE__, __LINE__);) +#else #define _MEXTREMOVE(m) do { \ if (MCLISREFERENCED(m)) { \ _MCLDEREFERENCE(m); \ @@ -361,6 +382,7 @@ #define MEXTREMOVE(m) \ MBUFLOCK(_MEXTREMOVE((m));) +#endif /* * Reset the data pointer on an mbuf. @@ -387,6 +409,23 @@ * Free a single mbuf and associated external storage. * Place the successor, if any, in n. */ +#ifdef POOL_DIAGNOSTIC +#define MMFREE(m, n, f, l) \ + MBUFLOCK( \ + mbstat.m_mtypes[(m)->m_type]--; \ + if ((m)->m_flags & M_PKTHDR) \ + m_tag_delete_chain((m), NULL); \ + if ((m)->m_flags & M_EXT) { \ + _MEXTREMOVE((m), f, l); \ + } \ + (n) = (m)->m_next; \ + _pool_put(&mbpool, (m), f, l); \ + ) + +#define MFREE(m, n) MMFREE(m, n, __FILE__, __LINE__) +#define m_free(m) mm_free(m, __FILE__, __LINE__) +#define m_freem(m) mm_freem(m, __FILE__, __LINE__) +#else #define MFREE(m, n) \ MBUFLOCK( \ mbstat.m_mtypes[(m)->m_type]--; \ @@ -398,6 +437,7 @@ (n) = (m)->m_next; \ pool_put(&mbpool, (m)); \ ) +#endif /* * Move just m_pkthdr from from to to, @@ -544,7 +584,11 @@ void mbinit(void); struct mbuf *m_copym2(struct mbuf *, int, int, int); struct mbuf *m_copym(struct mbuf *, int, int, int); +#ifdef POOL_DIAGNOSTIC +struct mbuf *mm_free(struct mbuf *, char *, int); +#else struct mbuf *m_free(struct mbuf *); +#endif struct mbuf *m_get(int, int); struct mbuf *m_getclr(int, int); struct mbuf *m_gethdr(int, int); @@ -558,7 +602,11 @@ void m_adj(struct mbuf *, int); int m_clalloc(int, int); void m_copyback(struct mbuf *, int, int, const void *); +#ifdef POOL_DIAGNOSTIC +void mm_freem(struct mbuf *, char *, int); +#else void m_freem(struct mbuf *); +#endif void m_reclaim(void *, int); void m_copydata(struct mbuf *, int, int, caddr_t); void m_cat(struct mbuf *, struct mbuf *); Index: kern/uipc_mbuf.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.70 diff -u -r1.70 uipc_mbuf.c --- kern/uipc_mbuf.c 27 May 2004 04:55:28 -0000 1.70 +++ kern/uipc_mbuf.c 7 Dec 2004 07:34:57 -0000 @@ -194,6 +194,34 @@ return (m); } +#ifdef POOL_DIAGNOSTIC +struct mbuf * +mm_free(m, f, l) + struct mbuf *m; + char *f; + int l; +{ + register struct mbuf *n; + + MMFREE(m, n, f, l); + return (n); +} + +void +mm_freem(m, f, l) + register struct mbuf *m; + char *f; + int l; +{ + register struct mbuf *n; + + if (m == NULL) + return; + do { + MMFREE(m, n, f, l); + } while ((m = n) != NULL); +} +#else struct mbuf * m_free(m) struct mbuf *m; @@ -216,6 +244,7 @@ MFREE(m, n); } while ((m = n) != NULL); } +#endif /* * Mbuffer utility routines.